Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
110 additions
and
115 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
packages/turbo-repository/__tests__/affected-packages.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import * as path from "node:path"; | ||
import { Workspace, Package, PackageManager } from "../js/dist/index.js"; | ||
|
||
type PackageReduced = Pick<Package, "name" | "relativePath">; | ||
|
||
interface AffectedPackagesTestParams { | ||
files: string[]; | ||
expected: PackageReduced[]; | ||
description: string; | ||
} | ||
|
||
describe("affectedPackages", () => { | ||
const tests: AffectedPackagesTestParams[] = [ | ||
{ | ||
description: "app change", | ||
files: ["apps/app/file.txt"], | ||
expected: [{ name: "app-a", relativePath: "apps/app" }], | ||
}, | ||
{ | ||
description: "lib change", | ||
files: ["packages/ui/a.txt"], | ||
expected: [{ name: "ui", relativePath: "packages/ui" }], | ||
}, | ||
{ | ||
description: "global change", | ||
files: ["package.json"], | ||
expected: [ | ||
{ name: "app-a", relativePath: "apps/app" }, | ||
{ name: "ui", relativePath: "packages/ui" }, | ||
], | ||
}, | ||
{ | ||
description: "global change that can be ignored", | ||
files: ["README.md"], | ||
expected: [], | ||
}, | ||
]; | ||
|
||
test.each(tests)( | ||
"$description", | ||
async (testParams: AffectedPackagesTestParams) => { | ||
const { files, expected } = testParams; | ||
const dir = path.resolve(__dirname, "./fixtures/monorepo"); | ||
const workspace = await Workspace.find(dir); | ||
const reduced: PackageReduced[] = ( | ||
await workspace.affectedPackages(files) | ||
).map((pkg) => { | ||
return { | ||
name: pkg.name, | ||
relativePath: pkg.relativePath, | ||
}; | ||
}); | ||
|
||
expect(reduced).toEqual(expected); | ||
} | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import * as path from "node:path"; | ||
import { Workspace, Package } from "../js/dist/index.js"; | ||
|
||
describe("findPackages", () => { | ||
it("enumerates packages", async () => { | ||
const workspace = await Workspace.find("./fixtures/monorepo"); | ||
const packages: Package[] = await workspace.findPackages(); | ||
expect(packages.length).not.toBe(0); | ||
}); | ||
|
||
it("returns a package graph", async () => { | ||
const dir = path.resolve(__dirname, "./fixtures/monorepo"); | ||
const workspace = await Workspace.find(dir); | ||
const packages = await workspace.findPackagesAndDependents(); // TODO: rename this | ||
|
||
expect(Object.keys(packages).length).toBe(2); | ||
|
||
const pkg1 = packages["apps/app"]; | ||
const pkg2 = packages["packages/ui"]; | ||
|
||
expect(pkg1.dependencies).toEqual(["packages/ui"]); | ||
expect(pkg1.dependents).toEqual([]); | ||
|
||
expect(pkg2.dependencies).toEqual([]); | ||
expect(pkg2.dependents).toEqual(["apps/app"]); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import * as path from "node:path"; | ||
import { Workspace, PackageManager } from "../js/dist/index.js"; | ||
|
||
describe("Workspace", () => { | ||
it("finds a workspace", async () => { | ||
const workspace = await Workspace.find(); | ||
const expectedRoot = path.resolve(__dirname, "../../.."); | ||
expect(workspace.absolutePath).toBe(expectedRoot); | ||
}); | ||
|
||
it("finds a package manager", async () => { | ||
const workspace = await Workspace.find(); | ||
const packageManager: PackageManager = workspace.packageManager; | ||
expect(packageManager.name).toBe("pnpm"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters