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

Allow you to call skip twice with the same name #30

Merged
merged 7 commits into from
Jan 7, 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
21 changes: 13 additions & 8 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export type CallbackMutateProject = (project: Project) => void | Promise<void>;
*/
export type CallbackDefineTests = (scenario: Scenario) => void;

type SkippableVariant = { status: 'active' | 'skipped', project: CallbackMutateProject[]};

export { Project };

type State =
Expand All @@ -42,7 +44,7 @@ type State =
| {
type: 'derived';
parent: Scenarios;
variants: Record<string, CallbackMutateProject[]>;
variants: Record<string, SkippableVariant>;
};

/**
Expand Down Expand Up @@ -167,7 +169,7 @@ export class Scenarios {
type: 'derived',
parent: this,
variants: Object.fromEntries(
Object.entries(variants).map(([variantName, mutator]) => [variantName, [mutator]])
Object.entries(variants).map(([variantName, mutator]) => [variantName, { status: 'active', project: [mutator]}])
),
});
}
Expand All @@ -189,7 +191,7 @@ export class Scenarios {
);
}
let variants = Object.assign({}, this.state.variants);
delete variants[variantName];
variants[variantName].status = 'skipped';
return new Scenarios({
type: 'derived',
parent: this.state.parent,
Expand Down Expand Up @@ -255,17 +257,17 @@ export class Scenarios {
type: 'derived',
parent: this,
variants: {
[name]: [callbackMutateProject],
[name]: { status: 'active', project: [callbackMutateProject]},
},
});
} else {
return new Scenarios({
type: 'derived',
parent: this.state.parent,
variants: Object.fromEntries(
Object.entries(this.state.variants).map(([variantName, mutators]) => [
Object.entries(this.state.variants).map(([variantName, variant]) => [
`${variantName}-${name}`,
[...mutators, callbackMutateProject],
{ status: variant.status, project: [...variant.project, callbackMutateProject]},
])
),
});
Expand All @@ -284,12 +286,15 @@ export class Scenarios {
} else {
let state = this.state;
this.state.parent.iterate((parent) => {
for (let [variantName, mutators] of Object.entries(state.variants)) {
for (let [variantName, variant] of Object.entries(state.variants)) {
if(variant.status === 'skipped') {
continue;
}
let combinedName = parent.name ? `${parent.name}-${variantName}` : variantName;
fn({
name: combinedName,
callbackCreateProject: parent.callbackCreateProject,
mutators: [...parent.mutators, ...mutators],
mutators: [...parent.mutators, ...variant.project],
});
}
});
Expand Down
6 changes: 6 additions & 0 deletions list.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
import { Scenario } from './index.js';
import glob from 'glob';
import { resolve } from 'path';
Expand All @@ -15,8 +16,11 @@ export interface ListParams {
export async function list(params: ListParams): Promise<Scenario[]> {
if (params.require) {
for (let r of params.require) {
// @ts-ignore this doesn't actually fail since we're checking before using it
if(import.meta.url) {
// @ts-ignore
const require = createRequire(import.meta.url);
// @ts-ignore this will only happen if we have import.meta.url
await import(require.resolve(r, { paths: [process.cwd()]}));
} else {
require(require.resolve(r, { paths: [process.cwd()]}));
Expand All @@ -25,7 +29,9 @@ export async function list(params: ListParams): Promise<Scenario[]> {
}
for (let pattern of params.files) {
for (let file of globSync(pattern)) {
// @ts-ignore
if(import.meta.url) {
// @ts-ignore
await import(resolve(file));
} else {
require(resolve(file));
Expand Down
11 changes: 5 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@
"dist/"
],
"scripts": {
"build": "yarn tsup cli.ts index.ts list.ts output.ts --tsconfig tsconfig.esm.json --dts --format esm,cjs",
"build": "pnpm tsup cli.ts index.ts list.ts output.ts --tsconfig tsconfig.esm.json --dts --format esm,cjs",
"docs": "typedoc --tsconfig tsconfig.esm.json index.ts --out typedoc/",
"docs:dev": "concurrently \"yarn docs:watch\" \"yarn docs:serve\"",
"docs:dev": "concurrently \"pnpm docs:watch\" \"pnpm docs:serve\"",
"docs:serve": "browser-sync start --server \"typedoc/\" --files \"**/*.html\"",
"docs:watch": "yarn docs -- --watch",
"docs:watch": "pnpm docs -- --watch",
"lint": "eslint '*.ts'",
"prepare": "yarn build",
"prepare": "pnpm build",
"start": "tsc --watch",
"test": "concurrently --no-color \"npm:test:*\" --names \"test:\"",
"test:cjs": "qunit tests/test.cjs",
Expand Down Expand Up @@ -79,8 +79,7 @@
"typescript": "^5.1.6"
},
"volta": {
"node": "18.17.0",
"yarn": "1.22.18"
"node": "18.17.0"
},
"publishConfig": {
"registry": "https://registry.npmjs.org"
Expand Down
89 changes: 0 additions & 89 deletions test-modules.mjs

This file was deleted.

23 changes: 13 additions & 10 deletions tests/test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,27 @@ function hello2(project) {
resolveName: 'hello',
});
}

function skipMe(project) {
// do nothing
}

const scenarios = Scenarios.fromDir('./tests/fixtures/app').expand({
hello1,
hello2,
skipMe,
});
scenarios.forEachScenario((scenario) => {

scenarios
.skip('skipMe')
.skip('skipMe') // show that skipping twice doesn't crash
.forEachScenario((scenario) => {
qunit.module(scenario.name, (hooks) => {
hooks.before(async function () {
this.app = await scenario.prepare();
});
qunit.test('yarn test', async function (assert) {
const result = await this.app.execute('yarn --silent test');
qunit.test('pnpm test', async function (assert) {
const result = await this.app.execute('pnpm --silent test');
assert.equal(result.stdout, `TAP version 13
ok 1 project > createHello
1..1
Expand All @@ -37,13 +47,6 @@ ok 1 project > createHello
# fail 0
`);
});
qunit.test('yarn bin inside app', async function (assert) {
let result = await this.app.execute('yarn --silent bin');
const yarnBin = result.stdout.trimRight();
assert.ok(yarnBin.startsWith(this.app.dir));
result = await this.app.execute('yarn --silent exec which qunit');
assert.ok(result.stdout.startsWith(yarnBin));
});
qunit.test('check scenario', async function (assert) {
let result = await this.app.execute(`node -p 'require("./index").polyfilled'`);
assert.equal(result.stdout.trim(), ('hello1' === scenario.name).toString());
Expand Down
24 changes: 11 additions & 13 deletions tests/test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,30 @@ function hello2(project) {
});
}

function skipMe(project) {
// do nothing
}

const scenarios = Scenarios.fromDir('./tests/fixtures/app').expand({
hello1,
hello2,
skipMe,
});


scenarios.forEachScenario((scenario) => {
scenarios
.skip('skipMe')
.skip('skipMe') // show that skipping twice doesn't crash
.forEachScenario((scenario) => {
Qunit.module(scenario.name, (hooks) => {
hooks.before(async function () {
this.app = await scenario.prepare();
});

Qunit.test(
'yarn test',
'pnpm test',
async function (assert) {
const result = await this.app.execute('yarn --silent test');
const result = await this.app.execute('pnpm --silent test');
assert.equal(
result.stdout,
`TAP version 13
Expand All @@ -46,16 +54,6 @@ ok 1 project > createHello
}
);

Qunit.test(
'yarn bin inside app',
async function (assert) {
let result = await this.app.execute('yarn --silent bin');
const yarnBin = result.stdout.trimRight();
assert.ok(yarnBin.startsWith(this.app.dir));
result = await this.app.execute('yarn --silent exec which qunit');
assert.ok(result.stdout.startsWith(yarnBin));
}
);

Qunit.test(
'check scenario',
Expand Down
25 changes: 11 additions & 14 deletions tests/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,31 @@ function hello2(project: Project) {
});
}

function skipMe(/* project: Project */) {
// do nothing
}

const scenarios = Scenarios.fromDir('./tests/fixtures/app').expand({
hello1,
hello2,
skipMe,
});

type TestContext = { app: PreparedApp };

scenarios.forEachScenario((scenario) => {
scenarios
.skip('skipMe')
.skip('skipMe') // show that skipping twice doesn't crash
.forEachScenario((scenario) => {
Qunit.module(scenario.name, (hooks) => {
hooks.before(async function (this: TestContext) {
this.app = await scenario.prepare();
});

Qunit.test(
'yarn test',
'pnpm test',
async function (this: TestContext, assert) {
const result = await this.app.execute('yarn --silent test');
const result = await this.app.execute('pnpm --silent test');
assert.equal(
result.stdout,
`TAP version 13
Expand All @@ -49,17 +57,6 @@ ok 1 project > createHello
}
);

Qunit.test(
'yarn bin inside app',
async function (this: TestContext, assert) {
let result = await this.app.execute('yarn --silent bin');
const yarnBin = result.stdout.trimRight();
assert.ok(yarnBin.startsWith(this.app.dir));
result = await this.app.execute('yarn --silent exec which qunit');
assert.ok(result.stdout.startsWith(yarnBin));
}
);

Qunit.test(
'check scenario',
async function (this: TestContext, assert) {
Expand Down