From 5bd2bb8d8a738d0fae2f9542209b7f39a6a95899 Mon Sep 17 00:00:00 2001 From: Edward Faulkner Date: Tue, 3 Sep 2024 16:34:25 -0400 Subject: [PATCH] New option to skip all variants --- index.ts | 30 +++++++++++++++++++----------- tests/test.ts | 9 +++++++++ 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/index.ts b/index.ts index 8762ab3..6a9519c 100644 --- a/index.ts +++ b/index.ts @@ -179,19 +179,28 @@ export class Scenarios { * with name name of the base scenario: -. * @returns a new `Scenarios` instance with the given scenario removed. */ - skip(variantName: string): Scenarios { + skip(): Scenarios; + skip(variantName: string): Scenarios; + skip(variantName?: string): Scenarios { if (this.state.type === 'root') { - throw new Error(`no variant named ${variantName} available to skip on root scenario`); - } - if (!this.state.variants[variantName]) { - throw new Error( - `no variant named ${variantName} available to skip. Found variants: ${Object.keys( - this.state.variants - ).join(', ')}` - ); + throw new Error('cannot call skip() on root scenarios'); } + let variants = Object.assign({}, this.state.variants); - variants[variantName].status = 'skipped'; + if (variantName) { + if (!this.state.variants[variantName]) { + throw new Error( + `no variant named ${variantName} available to skip. Found variants: ${Object.keys( + this.state.variants + ).join(', ')}` + ); + } + variants[variantName].status = 'skipped'; + } else { + for (let variant of Object.values(variants)) { + variant.status = 'skipped'; + } + } return new Scenarios({ type: 'derived', parent: this.state.parent, @@ -199,7 +208,6 @@ export class Scenarios { }); } - /** * @param variantName - name of scenario to keep. Note: names of derived scenarios are prepended * with name name of the base scenario: -. diff --git a/tests/test.ts b/tests/test.ts index ec29a9e..e95fbcd 100644 --- a/tests/test.ts +++ b/tests/test.ts @@ -72,6 +72,15 @@ ok 1 project > createHello }); }); +const skipExpandedExample = Scenarios.fromProject(() => new Project()); +skipExpandedExample + .expand({ + 'child-one-of-other-root': () => {}, + 'child-two-of-other-root': () => {}, + }).skip().map('inner', () => {}) // skip with no arguments skips all variants + .forEachScenario(() => {}); + + Qunit.module('cli', () => { Qunit.test('list', async (assert) => { const result = await execa('node', ['./dist/cli.js', 'list', '--require', 'ts-node/register', '--files', './tests/test.ts', '--matrix'])