From 698e44f8e7ddcc3891915ca9827f72f6152b7a25 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Sun, 14 Jul 2024 23:37:10 -0400 Subject: [PATCH] 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. PR-URL: https://github.com/nodejs/node/pull/53853 Reviewed-By: Moshe Atlow Reviewed-By: Chemi Atlow Reviewed-By: Benjamin Gruenbaum --- 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 57cb8b57ebb8e4..c1f57c2b991db8 100644 --- a/doc/api/test.md +++ b/doc/api/test.md @@ -3194,6 +3194,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`