diff --git a/lib/internal/test_runner/test.js b/lib/internal/test_runner/test.js index 48271e2e71a80e..c51fdc4a925951 100644 --- a/lib/internal/test_runner/test.js +++ b/lib/internal/test_runner/test.js @@ -288,6 +288,13 @@ class Test extends AsyncResource { }; this.waitingOn = 0; this.finished = false; + + if (!testOnlyFlag && only) { + const warning = + "'only' does not work when node is started" + + ' without the --test-only command-line option'; + this.diagnostic(warning); + } } hasConcurrency() { diff --git a/test/message/test_runner_only_warning.js b/test/message/test_runner_only_warning.js new file mode 100644 index 00000000000000..88aed49ab453d6 --- /dev/null +++ b/test/message/test_runner_only_warning.js @@ -0,0 +1,9 @@ +'use strict'; +require('../common'); +const { test } = require('node:test'); + +test('only = true without --test-only flag', { only: true }, () => {}); + +test('subtest only = true without --test-only flag', (t) => { + t.test('this subtest is run', { only: true }); +}); diff --git a/test/message/test_runner_only_warning.out b/test/message/test_runner_only_warning.out new file mode 100644 index 00000000000000..2906e51298ef1f --- /dev/null +++ b/test/message/test_runner_only_warning.out @@ -0,0 +1,27 @@ +TAP version 13 +# Subtest: only = true without --test-only flag +ok 1 - only = true without --test-only flag + --- + duration_ms: * + ... +# 'only' does not work when node is started without the --test-only command-line option +# Subtest: subtest only = true without --test-only flag + # Subtest: this subtest is run + ok 1 - this subtest is run + --- + duration_ms: * + ... + # 'only' does not work when node is started without the --test-only command-line option + 1..1 +ok 2 - subtest only = true without --test-only flag + --- + duration_ms: * + ... +1..2 +# tests 2 +# pass 2 +# fail 0 +# cancelled 0 +# skipped 0 +# todo 0 +# duration_ms * diff --git a/test/message/test_runner_output.out b/test/message/test_runner_output.out index 15d2009816a961..7c87e360c959cf 100644 --- a/test/message/test_runner_output.out +++ b/test/message/test_runner_output.out @@ -480,6 +480,7 @@ ok 52 - callback async throw after done --- duration_ms: * ... + # 'only' does not work when node is started without the --test-only command-line option # Subtest: running subtest 4 ok 4 - running subtest 4 --- @@ -490,6 +491,7 @@ ok 53 - only is set but not in only mode --- duration_ms: * ... +# 'only' does not work when node is started without the --test-only command-line option # Subtest: custom inspect symbol fail not ok 54 - custom inspect symbol fail --- diff --git a/test/message/test_runner_output_cli.out b/test/message/test_runner_output_cli.out index cc9c07f4c5c409..bb1e4f19434945 100644 --- a/test/message/test_runner_output_cli.out +++ b/test/message/test_runner_output_cli.out @@ -481,6 +481,7 @@ TAP version 13 --- duration_ms: * ... + # 'only' does not work when node is started without the --test-only command-line option # Subtest: running subtest 4 ok 4 - running subtest 4 --- @@ -491,6 +492,7 @@ TAP version 13 --- duration_ms: * ... + # 'only' does not work when node is started without the --test-only command-line option # Subtest: custom inspect symbol fail not ok 54 - custom inspect symbol fail --- diff --git a/test/message/test_runner_output_spec_reporter.out b/test/message/test_runner_output_spec_reporter.out index cf47c7ac7e33ff..9025f318920ee0 100644 --- a/test/message/test_runner_output_spec_reporter.out +++ b/test/message/test_runner_output_spec_reporter.out @@ -200,8 +200,10 @@ running subtest 1 (*ms) running subtest 2 (*ms) running subtest 3 (*ms) + 'only' does not work when node is started without the --test-only command-line option running subtest 4 (*ms) only is set but not in only mode (*ms) + 'only' does not work when node is started without the --test-only command-line option custom inspect symbol fail (*ms) customized