From 7c9f1aefb76d9982330e051d165e230dd21c26cf Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Thu, 11 Jul 2024 04:44:46 +0100 Subject: [PATCH] Test: Add CLI test for `--seed` without value --- src/cli/run.js | 3 +- test/cli/cli-main.js | 35 ++++++++++++++++++- .../filter-modulename-insensitive.tap.txt | 2 +- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/cli/run.js b/src/cli/run.js index ee3fe64df..6b8c6a04c 100644 --- a/src/cli/run.js +++ b/src/cli/run.js @@ -56,7 +56,8 @@ async function run (args, options) { const seed = options.seed; if (seed) { if (seed === true) { - QUnit.config.seed = Math.random().toString(36).slice(2); + // Length may vary from 6-14, pad to 10 + QUnit.config.seed = Math.random().toString(36).slice(2).padEnd(10, '0'); } else { QUnit.config.seed = seed; } diff --git a/test/cli/cli-main.js b/test/cli/cli-main.js index 3d62ce70a..412174d96 100644 --- a/test/cli/cli-main.js +++ b/test/cli/cli-main.js @@ -175,10 +175,43 @@ not ok 1 global failure # exit code: 1`); }); + QUnit.test('--seed generates new random seed', async assert => { + // https://github.com/qunitjs/qunit/issues/1691 + const command = ['qunit', '--seed', '--', 'basic-one.js', 'test/']; + const execution = await execute(command); + + const actualHarness = execution.snapshot + .replace(/^(Running tests with seed: )([a-z0-9]{10,20})/g, (_m, m1) => { + return m1 + '0000000000'; + }) + .split('\n') + .filter(line => !line.startsWith('ok ')) + .join('\n'); + + const actualResults = execution.snapshot + .replace(/^ok \d/gm, 'ok 0') + .split('\n') + .filter(line => line.startsWith('ok ')) + .sort() + .join('\n'); + + assert.equal(actualHarness, `Running tests with seed: 0000000000 +TAP version 13 +1..3 +# pass 3 +# skip 0 +# todo 0 +# fail 0`); + + assert.equal(actualResults, `ok 0 First > 1 +ok 0 Second > 1 +ok 0 Single > has a test`); + }); + QUnit.test('--require loads unknown module', async assert => { const command = ['qunit', 'basic-one.js', '--require', 'does-not-exist-at-all']; const execution = await execute(command); - // TODO: Change to a generic tap-outputs.js + // TODO: Change to a generic .tap.txt fixture // https://github.com/qunitjs/qunit/issues/1688 assert.equal(execution.code, 1); assert.true(execution.stderr.includes("Error: Cannot find module 'does-not-exist-at-all'")); diff --git a/test/cli/fixtures/filter-modulename-insensitive.tap.txt b/test/cli/fixtures/filter-modulename-insensitive.tap.txt index 05b2c94d3..00862705e 100644 --- a/test/cli/fixtures/filter-modulename-insensitive.tap.txt +++ b/test/cli/fixtures/filter-modulename-insensitive.tap.txt @@ -1,5 +1,5 @@ # name: --module selects a module (case-insensitive) -# command: ["qunit","--module","seconD","test/"] +# command: ["qunit", "--module", "seconD", "test/"] TAP version 13 ok 1 Second > 1