Skip to content

Commit 19cb394

Browse files
MoLownodejs-github-bot
authored andcommitted
test_runner: resolve entryFile against the cwd option
The location of a test file run in a child process was resolved against `process.cwd()`, so `run()` reported a wrong `entryFile` for relative paths when called with a different `cwd`. Signed-off-by: Moshe Atlow <moshe@atlow.co.il> PR-URL: #67512 Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent d78268e commit 19cb394

3 files changed

Lines changed: 15 additions & 2 deletions

File tree

‎lib/internal/test_runner/runner.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ class FileTest extends Test {
305305
__proto__: null,
306306
line: 1,
307307
column: 1,
308-
file: resolve(this.name),
308+
file: resolve(this.config.cwd, this.name),
309309
};
310310
this.timeout = null;
311311
}

‎test/parallel/test-runner-entry-file.mjs‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,19 @@ describe('entryFile attribution in reporter events', { concurrency: false }, ()
4848
assert.strictEqual(backupB.data.entryFile, bPath);
4949
});
5050

51+
it('resolves entryFile against the cwd option', async () => {
52+
const events = await collectEvents({
53+
isolation: 'process',
54+
cwd: fixtures.path('test-runner', 'entry-file'),
55+
files: ['a.test.mjs', 'b.test.mjs'],
56+
});
57+
const pass = events.filter(({ type }) => type === 'test:pass');
58+
const backupA = pass.find(({ data }) => data.name === 'backup A');
59+
const backupB = pass.find(({ data }) => data.name === 'backup B');
60+
assert.strictEqual(backupA.data.entryFile, aPath);
61+
assert.strictEqual(backupB.data.entryFile, bPath);
62+
});
63+
5164
it('does not stamp entryFile with isolation none', async () => {
5265
const events = await collectEvents({ isolation: 'none' });
5366
for (const { data } of events) {

‎test/parallel/test-runner-v8-deserializer.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ describe('v8 deserializer', common.mustCall(() => {
9191
reported = [];
9292
fileTest = new runner.FileTest({
9393
name: 'filetest',
94-
harness: { config: {} },
94+
harness: { config: { cwd: process.cwd() } },
9595
});
9696
fileTest.reporter.on('data', (data) => reported.push(data));
9797
assert(fileTest.isClearToSend());

0 commit comments

Comments
 (0)