You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(reporter): warning if stack trace contains generated code invocation
For some projects, a preprocessor like TypeScript may run to downlevel
certain features to a lower ECMAScript target. e.g. a project may
consume Angular for example, which ships ES2020.
If TypeScript, ESBuild, Babel etc. is used to do this, they may inject
generated code which does not map to any original source. If any of
these helpers (the generated code) is then part of a stack trace, Karma
will incorrectly report an error for an unresolved source map position.
Generated code is valid within source maps and can be denoted as
mappings with a 1-variable-length mapping. See the source map spec:
https://sourcemaps.info/spec.html.
The warning for generated code is especially bad when the majority of
file paths, and the actually relevant-portions in the stack are
resolved properly. e.g.
Errors initially look like this without the source mapping processing
of Karma:
(See PR description as commit lint does not allow for long stack
traces..)
A helper function shows up in the stacktrace but has no original mapping as it is
purely generated by TypeScript/ESbuild etc. The following warning is
printed and pollutes the test output while the remaining stack trace
paths (as said before), have been remapped properly:
```
SourceMap position not found for trace: http://localhost:9877/base/angular_material/
src/material/select/testing/unit_tests_bundle_spec.js:26:26
```
The resolved stacktrace looks like this after the transformation:
(see PR description as commit lint does not allow for long stack traces
here..)
More details on the scenario here:
https://gist.github.com/devversion/549d25915c2dc98a8896ba4408a1e27c.
expect(logWarnStub).to.have.been.calledWith('An unexpected error occurred while resolving the original position for: http://localhost:123/base/b.js:2:6')
221
+
expect(logWarnStub).to.have.been.calledWith(sinon.match({message: 'Fake parse error from source map consumer'}))
222
+
done()
223
+
})
224
+
})
225
+
226
+
// Generated code can be added by e.g. TypeScript or Babel when it transforms
227
+
// native async/await to generators. Calls would then be wrapped with a helper
228
+
// that is generated and does not map to anything, so-called generated code that
229
+
// is allowed as case #1 in the source map spec.
230
+
it('should not warn for trace file portion for generated code',(done)=>{
0 commit comments