blueprint icon indicating copy to clipboard operation
blueprint copied to clipboard

Error position is incorrect when tests fail

Open behrang opened this issue 2 years ago • 4 comments

If a test fails, the error line and column is wrong and the displayed source code shows the incorrect snippet from the file.

It looks like that there is a problem with source map or ts-jest, but I can't figure out a solution to fix it.

To recreate the error, create an example project, create a contract based on the counter template, then add an artificial error to one of the tests and run yarn blueprint test. I added throw new Error(); to the first line of should increase counter test case and here is the output that I get:

yarn run v1.22.19
$ /Users/x/Desktop/example/node_modules/.bin/blueprint test

> [email protected] test
> jest

 FAIL  tests/HelloWorld.spec.ts
  HelloWorld
    ✓ should deploy (1326 ms)
    ✕ should increase counter (1 ms)

  ● HelloWorld › should increase counter



      26 |
      27 |         const deployer = await blockchain.treasury('deployer');
    > 28 |
         | ^
      29 |         const deployResult = await helloWorld.sendDeploy(deployer.getSender(), toNano('0.05'));
      30 |
      31 |         expect(deployResult.transactions).toHaveTransaction({

      at Object.<anonymous> (tests/HelloWorld.spec.ts:28:15)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 passed, 2 total
Snapshots:   0 total
Time:        4.514 s, estimated 6 s
Ran all test suites.
Error: Command failed: npm test
    at checkExecSyncError (node:child_process:841:11)
    at execSync (node:child_process:912:15)
    at test (/Users/x/Desktop/example/node_modules/@ton-community/blueprint/dist/cli/test.js:7:34)
    at main (/Users/x/Desktop/example/node_modules/@ton-community/blueprint/dist/cli/cli.js:36:11)
    at Object.<anonymous> (/Users/x/Desktop/example/node_modules/@ton-community/blueprint/dist/cli/cli.js:41:1)
    at Module._compile (node:internal/modules/cjs/loader:1126:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
    at Module.load (node:internal/modules/cjs/loader:1004:32)
    at Function.Module._load (node:internal/modules/cjs/loader:839:12) {
  status: 1,
  signal: null,
  output: [ null, null, null ],
  pid: 57761,
  stdout: null,
  stderr: null
}
✨  Done in 6.46s.

behrang avatar Feb 15 '23 07:02 behrang