-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Not all my tests are detected and executed #3506
Description
What version of Bun is running?
0.6.12
What platform is your computer?
Darwin 22.5.0 arm64 arm
What steps can reproduce the bug?
Explain the bug :
TL;DR => Some tests are not detected and ignored
When running my test with bun test, some of my test are not detected (and not executed)
For example, I have these file at tests/user/services/slugify.test.ts :
import { slugify } from '$src/user-context/services/slugify';
import { describe, expect, test } from 'bun:test';
describe('slugify service', () => {
test('should lower-case the text', () => {
const text = 'Hello World';
const result = slugify(text);
expect(result).toBe('hello-world');
});
test('should trim the text', () => {
const text = ' Hello World ';
const result = slugify(text);
expect(result).toBe('hello-world');
});
test('should raise for empty text', () => {
const text = ' ';
expect(() => slugify(text)).toThrow('Empty slug');
});
});
And when I run bun test, no test are detected :
alexandre-cantin@macbook-pro-de-alexandre bun % bun test
bun test v0.6.12 (039bbc68)
[0.31ms] ".env"
... other tests
tests/user/use-cases/validate-user.test.ts:
tests/user/services/slugify.test.ts:
==> NO TEST EXECUTED 🫤
10 pass
0 fail
33 expect() calls
Ran 10 tests across 6 files. 10 total [211.00ms]
How to be sure it's not a visual bug ?
If I update a test in slugify.test.ts in order to fail => bun test detects no failing test and say that's all good
But if I rename the folder tests/user/services/ to tests/user/slugify/, my 3 tests are executed :
alexandre-cantin@macbook-pro-de-alexandre bun % bun test
bun test v0.6.12 (039bbc68)
[0.27ms] ".env"
... other tests
tests/user/slugify/slugify.test.ts:
✓ slugify service > should lower-case the text [1.36ms]
✓ slugify service > should trim the text [0.05ms]
✓ slugify service > should raise for empty text [0.04ms]
13 pass
0 fail
36 expect() calls
Ran 13 tests across 6 files. 13 total [205.00ms]
On the Github actions CI, it's worse because less test are executed than in local 😅
By the way, it's not the only an example in this repo => tests in tests/user/use-cases/validate-user.test.ts are not detected or executed either… But they are if I rename register-user.test.ts (in the same folder) to register-user.testss.ts to make it undetected by bun:test…
To reproduce :
- Clone the repo
https://github.com/AlexandreCantin/bun-template bun installbun test
What is the expected behavior?
All my test are detected and executed despite the folder structure
What do you see instead?
alexandre-cantin@macbook-pro-de-alexandre bun-template % bun test
bun test v0.6.12 (039bbc68)
tests/health-check.test.ts:
✓ checking if wiptest works > check server ping [6.41ms]
tests/user/value-objects/encrypted-password.test.ts:
✓ encrypted-password value object > valid case [0.14ms]
✓ encrypted-password value object > error case [0.07ms]
tests/user/value-objects/locale.test.ts:
✓ locale value object > valid case [0.68ms]
✓ locale value object > error case [0.07ms]
tests/user/use-cases/register-user.test.ts:
✓ register-user use case > sanitize fields [8.94ms]
✓ register-user use case > missing fields [0.87ms]
✓ register-user use case > malformed email [0.45ms]
✓ register-user use case > too long email [0.56ms]
✓ register-user use case > send register email [27.80ms]
tests/user/use-cases/validate-user.test.ts:
tests/user/services/slugify.test.ts:
10 pass
0 fail
33 expect() calls
Ran 10 tests across 6 files. 10 total [259.00ms]
==> No test in tests/user/services/slugify.test.ts are executed… (and in tests/user/use-cases/validate-user.test.ts) - despite the fact that the files are correctly detected
Additional information
The tests folder structure seems to impact the execution of the tests (despite the file being detected)
