Commit Graph

78 Commits

Author SHA1 Message Date
Moshe Atlow
aac5ad901d
test_runner: add test:complete event to reflect execution order
PR-URL: https://github.com/nodejs/node/pull/51909
Fixes: https://github.com/nodejs/node/issues/51907
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
2024-03-01 10:08:09 +00:00
Tim Stableford
d755f1ae88
lib: allow checking the test result from afterEach
PR-URL: https://github.com/nodejs/node/pull/51485
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
2024-01-19 14:56:06 +00:00
Marco Ippolito
a53fd95d36
test_runner: do not invoke after hook when test is empty
PR-URL: https://github.com/nodejs/node/pull/51389
Fixes: https://github.com/nodejs/node/issues/51371
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
2024-01-08 10:03:45 +00:00
Pulkit Gupta
71e19e8f08
test_runner: fixed to run after hook if before throws an error
PR-URL: https://github.com/nodejs/node/pull/51062
Refs: https://github.com/nodejs/node/issues/50842
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Raz Luvaton <rluvaton@gmail.com>
2023-12-17 21:15:02 +00:00
Colin Ihrig
c935d4c8fa
test_runner: replace spurious if with else
There is an `if` statement that likely should have been
an `else` in the original PR.

Refs: https://github.com/nodejs/node/pull/48915
PR-URL: https://github.com/nodejs/node/pull/49943
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Raz Luvaton <rluvaton@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: LiviaMedeiros <livia@cirno.name>
2023-09-29 11:04:58 +00:00
Moshe Atlow
47c5152545
test_runner: fix typescript coverage
PR-URL: https://github.com/nodejs/node/pull/49406
Fixes: https://github.com/nodejs/node/issues/49398
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2023-09-04 21:45:07 +00:00
Colin Ihrig
b5740756ca
test_runner: reland run global after() hook earlier
This commit reverts the revert in
bb52656fc6. It also includes the
fix for the issue that required the revert
(https://github.com/nodejs/node/pull/49059#issuecomment-1675171959)
and an additional common.mustCall() in the added test.

Refs: https://github.com/nodejs/node/pull/49059
Refs: https://github.com/nodejs/node/pull/49110
PR-URL: https://github.com/nodejs/node/pull/49116
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
2023-08-14 14:29:29 +00:00
Joyee Cheung
bb52656fc6
Revert "test_runner: run global after() hook earlier"
This reverts commit 6346bdc526.

Reason for revert: breaking CI

PR-URL: https://github.com/nodejs/node/pull/49110
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: LiviaMedeiros <livia@cirno.name>
Reviewed-By: Debadree Chatterjee <debadree333@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2023-08-12 04:19:05 +00:00
cjihrig
6346bdc526
test_runner: run global after() hook earlier
This commit moves the global after() hook execution from the
'beforeExit' event to the point where all tests have finished
running. This gives the global after() a chance to clean up
handles that would otherwise prevent the 'beforeExit' event
from being emitted.

PR-URL: https://github.com/nodejs/node/pull/49059
Fixes: https://github.com/nodejs/node/issues/49056
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
2023-08-11 09:16:51 -04:00
cjihrig
4e61c22699
test_runner: expose location of tests
This commit adds each test's line and column number to the reporter
output. This will aid in debugging test suite failures when error
stacks are not helpful, test suites are large, or tests have the
same name. This data is also exposed on the spec reporter.

This commit also replaces the filename that was previously being
reported, with the filename where the test actually exists. These
are normally correct, but could be wrong if tests were run from
a file other than the user's entrypoint.

PR-URL: https://github.com/nodejs/node/pull/48975
Fixes: https://github.com/nodejs/node/issues/48457
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
2023-08-11 09:12:49 -04:00
Raz Luvaton
c58e8fc31f
test_runner: fix global after not failing the tests
PR-URL: https://github.com/nodejs/node/pull/48913
Fixes: https://github.com/nodejs/node/issues/48867
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
2023-08-02 20:06:25 +00:00
Raz Luvaton
88094bba3c
test_runner: fix timeout in *Each hook failing further tests
PR-URL: https://github.com/nodejs/node/pull/48925
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
2023-07-31 22:13:02 +00:00
Raz Luvaton
7a33f2b88d
test_runner: cleanup test timeout abort listener
fix #48475

PR-URL: https://github.com/nodejs/node/pull/48915
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
2023-07-31 08:10:36 +00:00
Moshe Atlow
a955c534a8 test_runner: dont set exit code on todo tests
PR-URL: https://github.com/nodejs/node/pull/48929
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
2023-07-29 20:45:16 +00:00
Raz Luvaton
ee391f3781
test_runner: add __proto__ null
PR-URL: https://github.com/nodejs/node/pull/48663
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
2023-07-29 13:22:16 +00:00
Raz Luvaton
a0f3ed8ac4
test_runner: fix global before not called when no global test exists
PR-URL: https://github.com/nodejs/node/pull/48877
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
2023-07-24 11:38:23 +00:00
Raz Luvaton
44b8a061df
test_runner: fix async callback in describe not awaited
PR-URL: https://github.com/nodejs/node/pull/48856
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
2023-07-23 10:22:35 +00:00
Raz Luvaton
24c3d8a1b3
test_runner: call abort on test finish
PR-URL: https://github.com/nodejs/node/pull/48827
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
2023-07-21 12:53:58 +00:00
Chemi Atlow
78f6952751
fs: use kResistStopPropagation
PR-URL: https://github.com/nodejs/node/pull/48521
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
2023-06-24 15:52:38 +00:00
Erick Wendel
da80964a3d
test_runner: add initial draft for fakeTimers
Signed-off-by: Erick Wendel <erick.workspace@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/47775
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
2023-06-22 04:01:52 +00:00
Moshe Atlow
8bc6e193a0
test_runner: add enqueue and dequeue events
PR-URL: https://github.com/nodejs/node/pull/48428
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
2023-06-13 18:33:43 +00:00
Moshe Atlow
c21fe3ad87
test_runner: make --test-name-pattern recursive
PR-URL: https://github.com/nodejs/node/pull/48382
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2023-06-11 15:02:18 +00:00
Moshe Atlow
5c27cc2afb
test_runner: apply runOnly on suites
PR-URL: https://github.com/nodejs/node/pull/48279
Fixes: https://github.com/nodejs/node/issues/47937
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
2023-06-05 00:05:34 +03:00
Moshe Atlow
5e98a74327
test_runner: fix global after hook
PR-URL: https://github.com/nodejs/node/pull/48231
Fixes: https://github.com/nodejs/node/issues/48230
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2023-05-31 15:33:30 +00:00
Benjamin Gruenbaum
3cf05be50e
test: fix suite signal
PR-URL: https://github.com/nodejs/node/pull/47800
Fixes: https://github.com/nodejs/node/issues/47882
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2023-05-17 08:57:21 +00:00
Phil Nash
24615bd409
test_runner: fix ordering of test hooks
For tests with subtests the before hook was being run after the
beforeEach hook, which is the opposite to test suites and expectations.

Also, a function was being used to close over the after hooks, but at
the point it was being run the after hooks were not yet set up.

Fixes #47915

PR-URL: https://github.com/nodejs/node/pull/47931
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2023-05-11 10:10:56 +00:00
Moshe Atlow
dccd25e5bb test_runner: fix test runner concurrency
PR-URL: https://github.com/nodejs/node/pull/47675
Fixes: https://github.com/nodejs/node/issues/47365
Fixes: https://github.com/nodejs/node/issues/47696
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2023-04-24 22:32:01 +00:00
Moshe Atlow
dac02632a6 test_runner: fix test counting
PR-URL: https://github.com/nodejs/node/pull/47675
Fixes: https://github.com/nodejs/node/issues/47365
Fixes: https://github.com/nodejs/node/issues/47696
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2023-04-24 22:32:00 +00:00
Moshe Atlow
95e40b528d
test_runner: fix nested hooks
PR-URL: https://github.com/nodejs/node/pull/47648
Fixes: https://github.com/nodejs/node/issues/47643
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2023-04-23 17:55:01 +00:00
cjihrig
ecb023be8a
test_runner: move coverage collection to root.postRun()
This commit moves code coverage collection from the test
harness exit handler to the postRun() function of the root
test.

This is necessary preparatory work for supporting
code coverage with --test. The reason is that --test is
implemented on top of run(), and that function calls the root
test's postRun() function, which outputs the test summary. This
happens before the harness exit handler.

PR-URL: https://github.com/nodejs/node/pull/47651
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
2023-04-23 06:57:10 +00:00
Chemi Atlow
2ec4ef7c24
test_runner: execute before hook on test
Execute the before hook for Test as well, and execute it on root before
executing any tests.

Fixes: https://github.com/nodejs/node/issues/47518
PR-URL: https://github.com/nodejs/node/pull/47586
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
2023-04-18 20:59:49 +00:00
Moshe Atlow
d1eaded0d1
test_runner: count nested tests
PR-URL: https://github.com/nodejs/node/pull/47094
Fixes: https://github.com/nodejs/node/issues/46762
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
2023-03-21 08:16:38 +00:00
cjihrig
b191f09e6e
test_runner: give the root test a harness reference
This commit replaces the 'coverage' reference inside of the Test
class with a more generic harness reference which includes
coverage. This will let the root test more easily track process
level state such as code coverage, uncaughtException handlers,
and the state of bootstrapping.

PR-URL: https://github.com/nodejs/node/pull/46962
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
2023-03-07 13:59:28 -05:00
Moshe Atlow
ca033c16fe
test_runner: align behavior of it and test
PR-URL: https://github.com/nodejs/node/pull/46889
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2023-03-05 09:42:29 +02:00
Richie McColl
c90ea9301b
test_runner: emit test-only diagnostic warning
PR-URL: https://github.com/nodejs/node/pull/46540
Fixes: https://github.com/nodejs/node/issues/46448
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2023-02-21 08:39:17 +00:00
Colin Ihrig
5e954c3ce3
test_runner: centralize CLI option handling
The test runner relies on a few CLI options. That code was spread
across a few locations. This commit centralizes that logic.

PR-URL: https://github.com/nodejs/node/pull/46707
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: James M Snell <jasnell@gmail.com>
2023-02-20 01:26:04 +00:00
Moshe Atlow
3354f89dcf
test_runner: flatten TAP output when running using --test
PR-URL: https://github.com/nodejs/node/pull/46440
Fixes: https://github.com/nodejs/node/issues/45833
Refs: https://github.com/nodejs/node/issues/45833
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
2023-02-18 16:19:24 +00:00
Antoine du Hamel
fe514bf960
lib: enforce use of trailing commas for functions
PR-URL: https://github.com/nodejs/node/pull/46629
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
2023-02-14 18:45:16 +01:00
cjihrig
8c95cb012b
test_runner: add initial code coverage support
This commit adds code coverage functionality to the node:test
module. When node:test is used in conjunction with the new
--test-coverage CLI flag, a coverage report is created when
the test runner finishes. The coverage summary is forwarded to
any test runner reporters so that the display can be customized
as desired. This new functionality is compatible with the
existing NODE_V8_COVERAGE environment variable as well.

There are still several limitations, which will be addressed in
subsequent pull requests:

- Coverage is only reported for a single process. It is possible
  to merge coverage reports together. Once this is done, the
  --test flag will be supported as well.
- Source maps are not currently supported.
- Excluding specific files or directories from the coverage
  report is not currently supported. Node core modules and
  node_modules/ are excluded though.

PR-URL: https://github.com/nodejs/node/pull/46017
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
2023-01-08 16:09:41 -05:00
Moshe Atlow
9eb363a3e0
test_runner: report file in test runner events
PR-URL: https://github.com/nodejs/node/pull/46030
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2023-01-02 21:22:54 +00:00
Colin Ihrig
fe5710effc
test_runner: use os.availableParallelism()
This commit addresses an existing TODO in the code by moving
to the new os.availableParallelism() instead of os.cpus().length.

PR-URL: https://github.com/nodejs/node/pull/45969
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2022-12-27 03:30:19 +00:00
Moshe Atlow
a1b27b25bb
test_runner: add reporters
PR-URL: https://github.com/nodejs/node/pull/45712
Fixes: https://github.com/nodejs/node/issues/45648
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
2022-12-19 17:35:57 +00:00
Colin Ihrig
385d595a4f
test_runner: run t.after() if test body throws
This commit fixes a bug where t.after() was not called if the
test body threw an exception.

PR-URL: https://github.com/nodejs/node/pull/45870
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2022-12-17 06:36:15 +00:00
Moshe Atlow
232efb06fe
test_runner: parse yaml
PR-URL: https://github.com/nodejs/node/pull/45815
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2022-12-13 14:51:35 +00:00
cjihrig
215c5317d4 test_runner: add t.after() hook
This commit adds an after() hook to the TestContext class. This
hook can be used to clean up after a test finishes.

PR-URL: https://github.com/nodejs/node/pull/45792
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2022-12-11 19:19:07 +00:00
cjihrig
8302b0add0 test_runner: don't use a symbol for runHook()
This is not exposed to userland, so there is no need to put it
behind a symbol.

PR-URL: https://github.com/nodejs/node/pull/45792
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2022-12-11 19:19:06 +00:00
Debadree Chatterjee
8541b3a4c0
lib: added SuiteContext class
added SuiteContext class to replace object literal

Fixes: https://github.com/nodejs/node/issues/45641
Refs: https://github.com/nodejs/node/issues/45641#issuecomment-1329130581
PR-URL: https://github.com/nodejs/node/pull/45687
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2022-12-02 06:29:48 +00:00
Wassim Chegham
f8ce9117b1
test_runner: add initial TAP parser
Work in progress

PR-URL: https://github.com/nodejs/node/pull/43525
Refs: https://github.com/nodejs/node/issues/43344
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
2022-11-21 22:50:21 +00:00
cjihrig
7c6682957b
test_runner: support function mocking
This commit allows tests in the test runner to mock functions
and methods.

PR-URL: https://github.com/nodejs/node/pull/45326
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2022-11-07 18:25:54 -05:00
Jithil P Ponnan
3759935ee2
test_runner: fix afterEach not running on test failures
test_runner: fix afterEach not running on test failures

PR-URL: https://github.com/nodejs/node/pull/45204
Fixes: https://github.com/nodejs/node/issues/45192
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
2022-11-07 05:58:39 +00:00