53de295b21
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
46 lines
1.8 KiB
TypeScript
46 lines
1.8 KiB
TypeScript
import { describe, expect, test } from "bun:test"
|
|
import { selectCiTestTargets } from "./run-ci-tests"
|
|
|
|
describe("test script isolation", () => {
|
|
test("#given mock.module tests in the suite #then bun run test uses the isolated CI runner", async () => {
|
|
//#given
|
|
const packageJson = await Bun.file("package.json").json()
|
|
|
|
//#then
|
|
expect(packageJson.scripts.test).toBe("bun run script/run-ci-tests.ts")
|
|
})
|
|
|
|
test("#given isolated test shards #when selecting targets #then shards are deterministic and complete", () => {
|
|
// given
|
|
const ciTestPlan = {
|
|
isolatedModuleMockFiles: [],
|
|
isolatedTestTargets: ["a.test.ts", "b.test.ts", "c.test.ts", "d.test.ts", "e.test.ts"],
|
|
sharedTestFiles: ["shared.test.ts"],
|
|
}
|
|
|
|
// when
|
|
const shardOne = selectCiTestTargets(ciTestPlan, { phase: "isolated", shardCount: 2, shardIndex: 0 })
|
|
const shardTwo = selectCiTestTargets(ciTestPlan, { phase: "isolated", shardCount: 2, shardIndex: 1 })
|
|
|
|
// then
|
|
expect(shardOne).toEqual({ isolatedTestTargets: ["a.test.ts", "c.test.ts", "e.test.ts"], sharedTestFiles: [] })
|
|
expect(shardTwo).toEqual({ isolatedTestTargets: ["b.test.ts", "d.test.ts"], sharedTestFiles: [] })
|
|
expect([...shardOne.isolatedTestTargets, ...shardTwo.isolatedTestTargets].sort()).toEqual(ciTestPlan.isolatedTestTargets)
|
|
})
|
|
|
|
test("#given shared phase #when selecting targets #then only shared tests run", () => {
|
|
// given
|
|
const ciTestPlan = {
|
|
isolatedModuleMockFiles: [],
|
|
isolatedTestTargets: ["isolated.test.ts"],
|
|
sharedTestFiles: ["shared.test.ts"],
|
|
}
|
|
|
|
// when
|
|
const selectedTargets = selectCiTestTargets(ciTestPlan, { phase: "shared", shardCount: 1, shardIndex: 0 })
|
|
|
|
// then
|
|
expect(selectedTargets).toEqual({ isolatedTestTargets: [], sharedTestFiles: ["shared.test.ts"] })
|
|
})
|
|
})
|