11cb0ef41Sopenharmony_ci// Flags: --test-only
21cb0ef41Sopenharmony_ci'use strict';
31cb0ef41Sopenharmony_cirequire('../../../common');
41cb0ef41Sopenharmony_ciconst { test, describe, it } = require('node:test');
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ci// These tests should be skipped based on the 'only' option.
71cb0ef41Sopenharmony_citest('only = undefined');
81cb0ef41Sopenharmony_citest('only = undefined, skip = string', { skip: 'skip message' });
91cb0ef41Sopenharmony_citest('only = undefined, skip = true', { skip: true });
101cb0ef41Sopenharmony_citest('only = undefined, skip = false', { skip: false });
111cb0ef41Sopenharmony_citest('only = false', { only: false });
121cb0ef41Sopenharmony_citest('only = false, skip = string', { only: false, skip: 'skip message' });
131cb0ef41Sopenharmony_citest('only = false, skip = true', { only: false, skip: true });
141cb0ef41Sopenharmony_citest('only = false, skip = false', { only: false, skip: false });
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_ci// These tests should be skipped based on the 'skip' option.
171cb0ef41Sopenharmony_citest('only = true, skip = string', { only: true, skip: 'skip message' });
181cb0ef41Sopenharmony_citest('only = true, skip = true', { only: true, skip: true });
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_ci// An 'only' test with subtests.
211cb0ef41Sopenharmony_citest('only = true, with subtests', { only: true }, async (t) => {
221cb0ef41Sopenharmony_ci  // These subtests should run.
231cb0ef41Sopenharmony_ci  await t.test('running subtest 1');
241cb0ef41Sopenharmony_ci  await t.test('running subtest 2');
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_ci  // Switch the context to only execute 'only' tests.
271cb0ef41Sopenharmony_ci  t.runOnly(true);
281cb0ef41Sopenharmony_ci  await t.test('skipped subtest 1');
291cb0ef41Sopenharmony_ci  await t.test('skipped subtest 2');
301cb0ef41Sopenharmony_ci  await t.test('running subtest 3', { only: true });
311cb0ef41Sopenharmony_ci
321cb0ef41Sopenharmony_ci  // Switch the context back to execute all tests.
331cb0ef41Sopenharmony_ci  t.runOnly(false);
341cb0ef41Sopenharmony_ci  await t.test('running subtest 4', async (t) => {
351cb0ef41Sopenharmony_ci    // These subtests should run.
361cb0ef41Sopenharmony_ci    await t.test('running sub-subtest 1');
371cb0ef41Sopenharmony_ci    await t.test('running sub-subtest 2');
381cb0ef41Sopenharmony_ci
391cb0ef41Sopenharmony_ci    // Switch the context to only execute 'only' tests.
401cb0ef41Sopenharmony_ci    t.runOnly(true);
411cb0ef41Sopenharmony_ci    await t.test('skipped sub-subtest 1');
421cb0ef41Sopenharmony_ci    await t.test('skipped sub-subtest 2');
431cb0ef41Sopenharmony_ci  });
441cb0ef41Sopenharmony_ci
451cb0ef41Sopenharmony_ci  // Explicitly do not run these tests.
461cb0ef41Sopenharmony_ci  await t.test('skipped subtest 3', { only: false });
471cb0ef41Sopenharmony_ci  await t.test('skipped subtest 4', { skip: true });
481cb0ef41Sopenharmony_ci});
491cb0ef41Sopenharmony_ci
501cb0ef41Sopenharmony_cidescribe.only('describe only = true, with subtests', () => {
511cb0ef41Sopenharmony_ci  it.only('`it` subtest 1 should run', () => {});
521cb0ef41Sopenharmony_ci
531cb0ef41Sopenharmony_ci  it('`it` subtest 2 should not run', async () => {});
541cb0ef41Sopenharmony_ci});
551cb0ef41Sopenharmony_ci
561cb0ef41Sopenharmony_cidescribe.only('describe only = true, with a mixture of subtests', () => {
571cb0ef41Sopenharmony_ci  it.only('`it` subtest 1', () => {});
581cb0ef41Sopenharmony_ci
591cb0ef41Sopenharmony_ci  it.only('`it` async subtest 1', async () => {});
601cb0ef41Sopenharmony_ci
611cb0ef41Sopenharmony_ci  it('`it` subtest 2 only=true', { only: true });
621cb0ef41Sopenharmony_ci
631cb0ef41Sopenharmony_ci  it('`it` subtest 2 only=false', { only: false }, () => {
641cb0ef41Sopenharmony_ci    throw new Error('This should not run');
651cb0ef41Sopenharmony_ci  });
661cb0ef41Sopenharmony_ci
671cb0ef41Sopenharmony_ci  it.skip('`it` subtest 3 skip', () => {
681cb0ef41Sopenharmony_ci    throw new Error('This should not run');
691cb0ef41Sopenharmony_ci  });
701cb0ef41Sopenharmony_ci
711cb0ef41Sopenharmony_ci  it.todo('`it` subtest 4 todo', { only: false }, () => {
721cb0ef41Sopenharmony_ci    throw new Error('This should not run');
731cb0ef41Sopenharmony_ci  });
741cb0ef41Sopenharmony_ci
751cb0ef41Sopenharmony_ci  test.only('`test` subtest 1', () => {});
761cb0ef41Sopenharmony_ci
771cb0ef41Sopenharmony_ci  test.only('`test` async subtest 1', async () => {});
781cb0ef41Sopenharmony_ci
791cb0ef41Sopenharmony_ci  test('`test` subtest 2 only=true', { only: true });
801cb0ef41Sopenharmony_ci
811cb0ef41Sopenharmony_ci  test('`test` subtest 2 only=false', { only: false }, () => {
821cb0ef41Sopenharmony_ci    throw new Error('This should not run');
831cb0ef41Sopenharmony_ci  });
841cb0ef41Sopenharmony_ci
851cb0ef41Sopenharmony_ci  test.skip('`test` subtest 3 skip', () => {
861cb0ef41Sopenharmony_ci    throw new Error('This should not run');
871cb0ef41Sopenharmony_ci  });
881cb0ef41Sopenharmony_ci
891cb0ef41Sopenharmony_ci  test.todo('`test` subtest 4 todo', { only: false }, () => {
901cb0ef41Sopenharmony_ci    throw new Error('This should not run');
911cb0ef41Sopenharmony_ci  });
921cb0ef41Sopenharmony_ci});
931cb0ef41Sopenharmony_ci
941cb0ef41Sopenharmony_cidescribe.only('describe only = true, with subtests', () => {
951cb0ef41Sopenharmony_ci  test.only('subtest should run', () => {});
961cb0ef41Sopenharmony_ci
971cb0ef41Sopenharmony_ci  test('async subtest should not run', async () => {});
981cb0ef41Sopenharmony_ci
991cb0ef41Sopenharmony_ci  test('subtest should be skipped', { only: false }, () => {});
1001cb0ef41Sopenharmony_ci});
101