From e5de45a4bfadedb500b3f447e5cc0e95727f58f9 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Sun, 14 Jul 2024 23:37:10 -0400 Subject: [PATCH 1/2] test_runner: add context.filePath 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. --- doc/api/test.md | 20 +++++++++ lib/internal/test_runner/harness.js | 2 +- lib/internal/test_runner/test.js | 12 ++++- test/parallel/test-runner-test-filepath.js | 52 ++++++++++++++++++++++ 4 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 test/parallel/test-runner-test-filepath.js diff --git a/doc/api/test.md b/doc/api/test.md index 716fe8c5f62767..e0d4bee17a7483 100644 --- a/doc/api/test.md +++ b/doc/api/test.md @@ -3204,6 +3204,16 @@ test('top level test', (t) => { }); ``` +### `context.filePath` + + + +The absolute path of the test file that created the current test. If a test file +imports additional modules that generate tests, the imported tests will return +the path of the root test file. + ### `context.fullName` + +The absolute path of the test file that created the current suite. If a test +file imports additional modules that generate suites, the imported suites will +return the path of the root test file. + ### `context.name`