I'm trying to import from a Typescript file into globalSetup.ts
, to be run before some tests. Here is an MWE:
globalSetup.ts
: following https://stackoverflow.com/a/65708470/394957
require('ts-node/register');
require('ts-node').register({
transpileOnly: true,
});
//require('tsconfig-paths').register();
import { thing } from "../../error.ts";
console.log(thing);
and error.ts
:
require('ts-node').register({
transpileOnly: true,
});
require('tsconfig-paths').register();
const thing: int = 1;
returns
> test
> dotenv -e .env.test jest -i
TypeError: Cannot assign to read only property 'message' of object 'SyntaxError: $PATH/error.ts: Missing initializer in const declaration. (8:11)
6 | require('tsconfig-paths').register();
7 |
> 8 | const thing: int = 1;
| ^
9 |'
at runGlobalHook ($PATH/node_modules/@jest/core/build/runGlobalHook.js:130:25)
at async runJest ($PATH/node_modules/@jest/core/build/runJest.js:370:5)
at async _run10000 ($PATH/node_modules/@jest/core/build/cli/index.js:386:7)
at async runCLI ($PATH/node_modules/@jest/core/build/cli/index.js:237:3)
at async Object.run ($PATH/node_modules/jest-cli/build/cli/index.js:155:37)
(I have replaced the current app path with $PATH
for privacy.)
How can I import and run a Typescript file in globalSetup.js
?