swc-project / swc-node

Faster ts-node without typecheck
MIT License
1.72k stars 71 forks source link

jest silently ignores compilation error w/swc #679

Closed fauxbytes closed 1 year ago

fauxbytes commented 1 year ago
$ cat src/my-class.ts
export class MyClass {
    constructor(readonly a: string) {}
}
$ cat src/my-class.test.ts
import { MyClass } from "./my-class";

describe('compile error', () => {
    it('runs even though test has compilation errors', async () => {
        let myClass = new MyClass();
        expect(true);
    })
});
$ cat package.json |jq .jest
{
  "transform": {
    "^.+\\.(t|j)s$": "@swc/jest"
  }
}
$ npm run test -- src/my-class.test.ts

> jest-trials@1.0.0 test
> jest src/my-class.test.ts

 PASS  src/my-class.test.ts
  compile error
    √ runs even though test has compilation errors (2 ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        0.516 s, estimated 1 s
Ran all test suites matching /src\\my-class.test.ts/i.

// reconfigure jest to use ts-jest
$ cat package.json |jq .jest
{
  "transform": {
    "^.+\\.(t|j)s$": "ts-jest"
  }
}
$ npm run test -- src/my-class.test.ts

> jest-trials@1.0.0 test
> jest src/my-class.test.ts

 FAIL  src/my-class.test.ts
  ● Test suite failed to run

    src/my-class.test.ts:5:23 - error TS2554: Expected 1 arguments, but got 0.

    5         let myClass = new MyClass(); //compile error
                            ~~~~~~~~~~~~~

      src/my-class.ts:2:17
        2     constructor(readonly a: string) {}
                          ~~~~~~~~~~~~~~~~~~
        An argument for 'a' was not provided.

Test Suites: 1 failed, 1 total
Brooooooklyn commented 1 year ago

@fauxbytes this project doesn't provide typecheck