-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Make line number selection work with @ava/babel & @ava/typescript #2473
Comments
Current implementation of
By moving source map management to AVA, we will get more flexibility to manage the stack trace. Maybe we could create new file Lines 194 to 197 in 78cfaa1
Example of source map manager usage: const SourceMapManager = require('./source-map-manager');
const sourceMapManager = await new SourceMapManager({
defaultStackTraceInference: 'compiled-stack'
});
sourceMapManager.installSourceMapHandler();
sourceMapManager.addState(state); // register `state` which is generated by provider, where `source-map-manager` could find the source map file
// this can be used to replace `const sourceCallSite = sourceMapSupport.wrapCallSite(callSite);` in `worker/line-numbers.js`
// it will decide which source map to use and return original frame
sourceMapManager.getOriginalFrame(frame);
sourceMapManager.enableOriginalStackTrace(); // enable source map manager to infer original stack
const originalStack = (new Error('foo')).stack
sourceMapManager.disableOriginalStackTrace(); // leave source map manager to infer from compiled source again
// maybe also expose some lower level methods such as methods found in `SourceMapConsumer` We can pass const getParser = providers => {
for (const provider of providers) {
if (provider.canParse(file)) {
return provider.parse;
}
}
// no provider can handle. use default
return parse;
}
parse = getParser(providers);
const locations = parse(file);
// omitted lines
// ......
return () => {
// omitted lines
// .....
const sourceCallSite = sourceMapManager.getOriginalFrame(callSite);
const start = {
line: sourceCallSite.getLineNumber(),
column: sourceCallSite.getColumnNumber() - 1
};
const test = findTest(locations, start);
// omitted lines
// .....
} In the future maybe we could add more providers such as |
@okyantoro yes, see arno #2474. That said I'd prefer using a language specific AST to determine the line numbers.
I don't think it's wrong. AVA itself can focus on Node.js support, and other languages / dialects can be handled through providers. However we have limited resources and should refrain from supporting esoteric platforms. |
I hit this issue/#2474 yesterday with some tests I wrote in Typescript, and worked around it by using Babel to transpile my Typescript into Javascript for AVA to execute. It's... clunky. I see both issues are labelled |
@alastairs I think the issue description is still accurate. Happy to help if you're getting stuck anywhere in particular. |
AVA 4 removes |
Line number selection relies on AVA parsing the test file. This does not work when you use a require hook (such as
ts-node/register
). That's OK. However we do want it to work with our Babel and TypeScript providers.Ultimately, we need start and end lines & columns for each call expression in the test file. First we need to initialize the providers earlier:
ava/lib/worker/subprocess.js
Lines 45 to 52 in 1222ce9
See here:
ava/lib/worker/subprocess.js
Lines 140 to 159 in 1222ce9
Then, depending on the extension of the test file, we need to get the provider to give us the call locations. For normal JS files you can find that logic here:
ava/lib/worker/line-numbers.js
Lines 1 to 28 in 1222ce9
For
@ava/babel
we need to parse the test file using Babel, with all the configured plugins active and whatnot.For
@ava/typescript
, hopefully we can usetypescript
itself as a parser?The text was updated successfully, but these errors were encountered: