material-svelte / vite-web-test-runner-plugin

MIT License
39 stars 13 forks source link

Typescript sourcemap #14

Open reekoheek opened 3 years ago

reekoheek commented 3 years ago

I'm working with typescript with enable sourcemap in my tsconfig.json. When I throw an error from test, it logged different line number from my ts files. But when I use @web/dev-server-esbuild line numbers are correct.

web-test-runner.config.mjs

// import { esbuildPlugin } from '@web/dev-server-esbuild';
import vite from 'vite-web-test-runner-plugin';

export default {
  plugins: [
    // esbuildPlugin({ ts: true, target: 'auto' }),
    vite(),
  ],
};

tsconfig.json

{
  "compilerOptions": {
    "module": "es2020",
    "target": "es2019",
    "sourceMap": true,
    "moduleResolution": "node",
    "strict": true,
    "noEmit": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,
    "resolveJsonModule": true,
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true,
    "importsNotUsedAsValues": "error"
  }
}

I'm running with

wtr ./src/**/*.test.ts --node-resolve --coverage
betaboon commented 3 years ago

would you be able to provide a repro ?

reekoheek commented 3 years ago

I think the problem when we use typescript decorator.

Run this to reproduce:

git clone git@github.com:material-svelte/vite-web-test-runner-plugin.git
cd vite-web-test-runner-plugin/
curl https://gist.githubusercontent.com/reekoheek/332dce6c76c582da9cadbd22544b5bb5/raw/d2a430761a84ac4111332a7b2d5a167ff518ac14/vite_wtr_repro_patch.diff | git apply --check
cd examples/react/
npm i
npm test

You will see error happened at src/foo.test.ts:21:11 but the actual error happened at src/foo.test.ts:8

❯ npm test

> web-test-runner-example@0.0.0 test
> web-test-runner "src/**/*.test.ts" --coverage

  vite v2.4.2 dev server running at:

  > Local: http://localhost:3000/
  > Network: use `--host` to expose

src/foo.test.ts:

 🚧 Browser logs:
      foo arg name: Foo
      foo [Function: Foo]

 ❌ foo > ok
      Error: something err
        at o.<anonymous> (src/foo.test.ts:21:11)

Chrome: |██████████████████████████████| 1/1 test files | 0 passed, 1 failed

Code coverage: 100 %
View full coverage report at coverage/lcov-report/index.html

Finished running tests in 1.5s with 1 failed tests.

5:42:27 PM [vite] page reload coverage/lcov-report/index.html
betaboon commented 3 years ago

i wonder if this is a vite-internal problem. i saw multiple issues in the vite ecosystem relating to wrong line-numbers in sourcemaps. this plugin readly doesnt do alot, just proxy all requests to vite.

maybe you could ask around in their discord ?