Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New option to skip all variants #36

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading