Skip to content

ts-jest not configured to match tsc options #59

Closed
@kmturley

Description

@kmturley

Some code works fine via npm run build && npm start but not by npm test.
My assumption is that ts-jest is not configured to work in the same way as tsconfig.

How to replicate

git clone https://github.com/jsynowiec/node-typescript-boilerplate.git
cd node-typescript-boilerplate
npm install

1) No top-level 'await' expressions

Add to bottom of main.ts

console.log(await greeter('Bob'));

Then run:

npm run build && npm start
npm test

Notice how start works fine, but test outputs this error:

 FAIL  __tests__/main.test.ts
  ● Test suite failed to run
    src/main.ts:36:13 - error TS1378: Top-level 'await' expressions are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', 'nodenext', or 'preserve', and the 'target' option is set to 'es2017' or higher.
    console.log(await greeter('Bob'));

1) No native node.js modules

Add these lines to the bottom of main.ts

import path from 'path';
async function init() {
  console.log(path.basename('test/path/filename.json'));
  console.log(await greeter('Bob'));
}
init();

Then run:

npm run build && npm start
npm test

Notice how start works fine, but test outputs this error:

 RUNS  __tests__/main.test.ts
/Users/kimturley/Sites/node-typescript-boilerplate/src/main.ts:497
  console.log(path_1.default.basename('test/path/filename.json'));
TypeError: Cannot read properties of undefined (reading 'basename')

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions