Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Line number parser doesn't utilize @ava/typescript's compilation output #3064

Open
novemberborn opened this issue Jul 10, 2022 · 5 comments
Open
Labels

Comments

@novemberborn
Copy link
Member

Line number selection doesn't use the @ava/typescript provider to resolve the compiled JS file. This means it's parsing the actual TypeScript file which is not supported:

ava/lib/worker/base.js

Lines 42 to 51 in ac0d75d

let checkSelectedByLineNumbers;
try {
checkSelectedByLineNumbers = lineNumberSelection({
file: options.file,
lineNumbers: options.lineNumbers,
});
} catch (error) {
channel.send({type: 'line-number-selection-error', err: serializeError('Line number selection error', false, error, options.file)});
checkSelectedByLineNumbers = () => false;
}

We'd need to amend the worker interface to make the file resolver available:

https://github.com/avajs/typescript/blob/34da7bf008bd94e4844562ed86f5446faae6c087/index.js#L152-L168

This requires a new protocol identifier, and the file resolver should only be called if available to retain compatibility with the current @ava/typescript version. I can explain more when we get to this point:

const levelsByProtocol = {
'ava-3.2': levels.levelIntegersAreCurrentlyUnused,
};

We can then install the providers earlier:

ava/lib/worker/base.js

Lines 123 to 132 in ac0d75d

// Install before processing options.require, so if helpers are added to the
// require configuration the *compiled* helper will be loaded.
const {projectDir, providerStates = []} = options;
const providers = [];
await Promise.all(providerStates.map(async ({type, state}) => {
if (type === 'typescript') {
const provider = await providerManager.typescript(projectDir);
providers.push(provider.worker({extensionsToLoadAsModules, state}));
}
}));

@Acroucamp
Copy link

If this issue is still open and not resolved (since it has been created in 2022), I would like to work on it.

@novemberborn
Copy link
Member Author

@Acroucamp Go for it!

@novemberborn
Copy link
Member Author

Another approach may be to strip the TypeScript types from the files and then use the existing logic, but that depends on whether the generated JS has the same line numbers for test() declarations as the TypeScript file.

@Acroucamp
Copy link

Thanks Mark, appreciate it!

@novemberborn
Copy link
Member Author

Yet another approach, have @ava/typescript do the parsing using typescript as a peer dependency and using their API. All AVA really needs is start and end positions of the test functions. When running the tests, call sites with source maps should already map back cleanly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants