Skip to content

Commit

Permalink
Merge pull request #36 from embroider-build/skip-all
Browse files Browse the repository at this point in the history
New option to skip all variants
  • Loading branch information
ef4 authored Sep 3, 2024
2 parents 7de67fd + 5bd2bb8 commit 7e3d24e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
30 changes: 19 additions & 11 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,27 +179,35 @@ export class Scenarios {
* with name name of the base scenario: <base>-<derived>.
* @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,
variants,
});
}


/**
* @param variantName - name of scenario to keep. Note: names of derived scenarios are prepended
* with name name of the base scenario: <base>-<derived>.
Expand Down
9 changes: 9 additions & 0 deletions tests/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand Down

0 comments on commit 7e3d24e

Please sign in to comment.