Skip to content

Commit

Permalink
Merge pull request #38 from embroider-build/dont-mutate
Browse files Browse the repository at this point in the history
Fix accidental mutation
  • Loading branch information
ef4 authored Sep 3, 2024
2 parents 23cefb4 + 369e044 commit 8538153
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
12 changes: 9 additions & 3 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,18 @@ export class Scenarios {
throw new Error('cannot call skip() on root scenarios');
}

let variants = Object.assign({}, this.state.variants);
let variants = Object.fromEntries(
Object.entries(this.state.variants).map(([variantName, entry]) => [
variantName,
Object.assign({}, entry),
])
);

if (variantName) {
if (!this.state.variants[variantName]) {
if (!variants[variantName]) {
throw new Error(
`no variant named ${variantName} available to skip. Found variants: ${Object.keys(
this.state.variants
variants
).join(', ')}`
);
}
Expand Down
17 changes: 10 additions & 7 deletions tests/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,17 @@ 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
const skipTester = Scenarios.fromProject(() => new Project()).expand({
'variant-one': () => {},
'variant-two': () => {},
})


skipTester.skip().map('skipped', () => {}) // skip with no arguments skips all variants
.forEachScenario(() => {});

skipTester.map('not-skipped', () => {} ).forEachScenario(() => {});


Qunit.module('cli', () => {
Qunit.test('list', async (assert) => {
Expand All @@ -88,7 +91,7 @@ Qunit.module('cli', () => {
const { stdout } = result;
assert.deepEqual(
stdout.split('\n'),
['hello1', 'hello2']
['hello1', 'hello2', 'variant-one-not-skipped', 'variant-two-not-skipped']
);
});
});

0 comments on commit 8538153

Please sign in to comment.