-
Notifications
You must be signed in to change notification settings - Fork 6
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
TypeScript tests appear in Test Explorer, but are not run. #33
Comments
Please enable the |
Hi, I've discovered what's wrong: In my tests I like to include the path of the test file so that I can easily jump to it from the test output. My tests look like this: import { describe, it } from 'node:test';
import assert from 'node:assert';
describe(`${__filename} - When doing a thing`, () => {
it('it returns true', () => {
// ARRANGE
const expected: boolean = true;
// ACT
const actual: boolean = true;
// ASSERT
assert(expected === actual);
});
}); It's the
It looks like it's running the test, but not gathering the result? |
Once I'd got the tests working, I found a separate thing. Any code that referenced a path to a file (even using For example, if I have:
import { describe, it } from 'node:test';
import assert from 'node:assert';
import { existsSync } from 'node:fs';
import { resolve } from 'node:path';
describe(`When doing a thing`, () => {
it('it returns true', () => {
// ARRANGE
console.log(resolve('test/thing.test.ts'));
const expected: boolean = existsSync(resolve('test/thing.test.ts'));
// ACT
const actual: boolean = true;
// ASSERT
assert(expected === actual);
});
}); then the test runs fine from the command line. But the test fails from your extension and shows the path as
I have managed to fix this by using a package called app-root-path instead of import { describe, it } from 'node:test';
import assert from 'node:assert';
import { existsSync } from 'node:fs';
import appRootPath from 'app-root-path';
describe(`When doing a thing`, () => {
it('it returns true', () => {
// ARRANGE
console.log(`${appRootPath}/test/thing.test.ts`);
const expected: boolean = existsSync(`${appRootPath}/test/thing.test.ts`);
// ACT
const actual: boolean = true;
// ASSERT
assert(expected === actual);
});
}); I wonder whether this is because you are setting the current working directory here as the directory each test file is in? |
Thanks for your help @alexc155! I'd love to migrate ArkType to node's test runner but I'm still encountering lots of problems with TS discovery and imports. Will be keeping an eye on this- awesome to see the early support for test coverage metrics ❤️ |
Ah, yes. This is expected. At the moment tests are discovered purely by static code analysis, which does not make any attempt to evaluate template literals with replacements. During runs, any additional tests not found in the test tree are ignored. We could add support for that, however, such that tests emitted during runs are added to the tree if they aren't already there.
This probably duplicates at. At the moment I would use |
Using the config
I can make TypeScript tests appear in the Test Explorer 😀
However, when I run all tests the Test Results pane shows
0/0 tests passed
and the Test Explorer fails to show any green or red ticks.I wonder if this is because node is being used as the test runner and the glob for detecting tests doesn't include the
.ts
extension?This is similar to running
npm --test --import tsx
Changing the test runner to
tsx
probably wouldn't help as it uses the same glob patterns to discover tests.I have tried adding the glob to the parameters in the config:
but then all the tests fail with
Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'foo/test/**/*.test.ts' imported from foo/
I thought perhaps the
filePatterns
property in settings might be used for this, but it appears to only control the discovery of tests rather than their execution.Please could you tell me what I'm doing wrong, or provide a setting I can use to pass a glob pattern of test files to the runner?
Thanks!
The text was updated successfully, but these errors were encountered: