-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit adds a filePath getter to the TestContext and SuiteContext classes. This allows a context to be mapped back to the original test file that created it, even if it was imported from another file. This is useful for mapping features like test snapshots to the correct test file. This is also prep work for supporting running test files in the test runner process. PR-URL: #53853 Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Chemi Atlow <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
- Loading branch information
Showing
4 changed files
with
84 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
'use strict'; | ||
require('../common'); | ||
const tmpdir = require('../common/tmpdir'); | ||
const { strictEqual } = require('node:assert'); | ||
const { writeFileSync } = require('node:fs'); | ||
const { suite, test } = require('node:test'); | ||
|
||
tmpdir.refresh(); | ||
|
||
suite('suite', (t) => { | ||
strictEqual(t.filePath, __filename); | ||
|
||
test('test', (t) => { | ||
strictEqual(t.filePath, __filename); | ||
|
||
t.test('subtest', (t) => { | ||
strictEqual(t.filePath, __filename); | ||
|
||
t.test('subsubtest', (t) => { | ||
strictEqual(t.filePath, __filename); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
test((t) => { | ||
strictEqual(t.filePath, __filename); | ||
}); | ||
|
||
const importedTestFile = tmpdir.resolve('temp.js'); | ||
writeFileSync(importedTestFile, ` | ||
'use strict'; | ||
const { strictEqual } = require('node:assert'); | ||
const { suite, test } = require('node:test'); | ||
suite('imported suite', (t) => { | ||
strictEqual(t.filePath, ${JSON.stringify(__filename)}); | ||
test('imported test', (t) => { | ||
strictEqual(t.filePath, ${JSON.stringify(__filename)}); | ||
t.test('imported subtest', (t) => { | ||
strictEqual(t.filePath, ${JSON.stringify(__filename)}); | ||
t.test('imported subsubtest', (t) => { | ||
strictEqual(t.filePath, ${JSON.stringify(__filename)}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
`); | ||
require(importedTestFile); |