Skip to content

Commit

Permalink
add per-pipeline e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
arlyon committed Jan 24, 2023
1 parent 78e8b0e commit e72532d
Showing 1 changed file with 71 additions and 32 deletions.
103 changes: 71 additions & 32 deletions cli/scripts/e2e/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,46 +40,77 @@ const basicPipeline = {
globalEnv: ["GLOBAL_ENV_DEPENDENCY"],
};

const prunePipeline = {
...basicPipeline,
pipeline: {
...basicPipeline.pipeline,
// add some package specific pipeline tasks to test pruning
"a#build": {
outputs: ["dist/**", "!dist/cache/**"],
},
"c#build": {
outputs: ["dist/**", "!dist/cache/**"],
},
},
}

const explicitPrunePipeline = {
...basicPipeline,
pipeline: {
...basicPipeline.pipeline,
// add some package specific pipeline tasks to test pruning
"a#build": {
dependsOn: ["c#build"],
outputs: ["dist/**", "!dist/cache/**"],
},
"c#build": {
outputs: ["dist/**", "!dist/cache/**"],
},
},
}

const testCombinations = [
{npmClient: "yarn" as const, pipeline: basicPipeline},
{npmClient: "berry" as const, pipeline: basicPipeline},
{npmClient: "pnpm6" as const, pipeline: basicPipeline},
{npmClient: "pnpm"as const , pipeline: basicPipeline},
{npmClient: "npm" as const, pipeline: basicPipeline},

// there is probably no need to test every
// pipeline against every package manager,
// so specify directly rather than use the
// cartesian product
{npmClient: "yarn" as const, pipeline: prunePipeline, name: "basicPrune", excludePrune: ["c#build"]}, // expect c#build to be removed, since there is no dep between a -> c
{npmClient: "yarn" as const, pipeline: explicitPrunePipeline, name: "explicitDepPrune", includePrune: ["c#build"]}, // expect c#build to be included, since a depends on c

]

// This is injected by github actions
process.env.TURBO_TOKEN = "";

let suites: uvu.uvu.Test<uvu.Context>[] = [];
for (let npmClient of ["yarn", "berry", "pnpm6", "pnpm", "npm"] as const) {
const Suite = uvu.suite(`${npmClient}`);
for (let {npmClient, pipeline, name, includePrune, excludePrune} of testCombinations) {
const Suite = uvu.suite(`${name ?? npmClient}`);

const repo = new Monorepo("basics");
repo.init(npmClient, {
pipeline: {
...basicPipeline.pipeline,
// add some package specific pipeline tasks to test pruning
"a#build": {
dependsOn: ["^build"],
outputs: ["dist/**", "!dist/cache/**"],
},
"c#build": {
dependsOn: ["^build"],
outputs: ["dist/**", "!dist/cache/**"],
},
},
globalDependencies: basicPipeline.globalDependencies
});
repo.init(npmClient, pipeline);
repo.install();
repo.addPackage("a", ["b"]);
repo.addPackage("b");
repo.addPackage("c");
repo.linkPackages();
repo.expectCleanGitStatus();
runSmokeTests(Suite, repo, npmClient);
runSmokeTests(Suite, repo, npmClient, includePrune ?? [], excludePrune ?? []);

const sub = new Monorepo("in-subdirectory");
sub.init(npmClient, basicPipeline, "js");
sub.init(npmClient, pipeline, "js");
sub.install();
sub.addPackage("a", ["b"]);
sub.addPackage("b");
sub.addPackage("c");
sub.linkPackages();

runSmokeTests(Suite, sub, npmClient, {
runSmokeTests(Suite, sub, npmClient, includePrune ?? [], excludePrune ?? [], {
cwd: sub.subdir ? path.join(sub.root, sub.subdir) : sub.root,
});

Expand Down Expand Up @@ -137,6 +168,8 @@ function runSmokeTests<T>(
suite: uvu.Test<T>,
repo: Monorepo,
npmClient: "yarn" | "berry" | "pnpm6" | "pnpm" | "npm",
includePrune: string[],
excludePrune: string[],
options: execa.SyncOptions<string> = {}
) {
suite.after(() => {
Expand Down Expand Up @@ -605,12 +638,15 @@ function runSmokeTests<T>(
}

// grab the first turbo.json in an out folder
let turbos = repo.globbySync("**/out/turbo.json")
let turbo = JSON.parse(repo.readFileSync(turbos[0]))

for (const pipeline of Object.keys(turbo.pipeline)) {
if (pipeline.startsWith("//#") || pipeline.indexOf("#") === -1) continue;
assert.ok(pipeline.startsWith(scope), `Expected package ${pipeline} to not appear in prune with scope ${scope}`)
let turbos = repo.globbySync("**/out/turbo.json").map((t: string) => JSON.parse(repo.readFileSync(t)));
for (const turbo of turbos) {
const pipelines = Object.keys(turbo.pipeline);
const missingInclude = includePrune.filter(i => !pipelines.includes(i));
const presentExclude = excludePrune.filter(i => pipelines.includes(i));

if (missingInclude.length || presentExclude.length) {
assert.unreachable('failed to validate prune in pipeline' + (missingInclude.length ? `, expecting ${missingInclude}` : '') + (presentExclude.length ? `, not expecting ${presentExclude}` : ''))
}
}

const install = repo.run(installCmd, installArgs, {
Expand Down Expand Up @@ -668,12 +704,15 @@ function runSmokeTests<T>(
}

// grab the first turbo.json in an out folder
let turbos = repo.globbySync("**/out/turbo.json")
let turbo = JSON.parse(repo.readFileSync(turbos[0]))

for (const pipeline of Object.keys(turbo.pipeline)) {
if (pipeline.startsWith("//#") || pipeline.indexOf("#") === -1) continue;
assert.ok(pipeline.startsWith(scope), `Expected package ${pipeline} to not appear in prune with scope ${scope}`)
let turbos = repo.globbySync("**/out/turbo.json").map((t: string) => JSON.parse(repo.readFileSync(t)));
for (const turbo of turbos) {
const pipelines = Object.keys(turbo.pipeline);
const missingInclude = includePrune.filter(i => !pipelines.includes(i));
const presentExclude = excludePrune.filter(i => pipelines.includes(i));

if (missingInclude.length || presentExclude.length) {
assert.unreachable('failed to validate prune in pipeline' + (missingInclude.length ? `, expecting ${missingInclude}` : '') + (presentExclude.length ? `, not expecting ${presentExclude}` : ''))
}
}

const install = repo.run(installCmd, installArgs, {
Expand Down

0 comments on commit e72532d

Please sign in to comment.