-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: pass appropriate workspace args and improve tests (#90)
- Loading branch information
Showing
38 changed files
with
3,350 additions
and
397 deletions.
There are no files selected for viewing
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
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
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,74 @@ | ||
import { fileURLToPath } from "node:url"; | ||
import { isWindows } from "std-env"; | ||
import type { PackageManagerName } from "../src"; | ||
|
||
export type Fixture = { | ||
name: string; | ||
dir: string; | ||
packageManager: PackageManagerName; | ||
majorVersion?: string; | ||
workspace: boolean; | ||
}; | ||
|
||
export const fixtures = ( | ||
[ | ||
{ | ||
name: "bun", | ||
packageManager: "bun", | ||
}, | ||
{ | ||
name: "bun-workspace", | ||
packageManager: "bun", | ||
}, | ||
{ | ||
name: "npm", | ||
packageManager: "npm", | ||
}, | ||
{ | ||
name: "npm-workspace", | ||
packageManager: "npm", | ||
}, | ||
{ | ||
name: "pnpm", | ||
packageManager: "pnpm", | ||
}, | ||
{ | ||
name: "pnpm-workspace", | ||
packageManager: "pnpm", | ||
}, | ||
{ | ||
name: "yarn-classic", | ||
packageManager: "yarn", | ||
}, | ||
{ | ||
name: "yarn-classic-workspace", | ||
packageManager: "yarn", | ||
}, | ||
{ | ||
name: "yarn-berry", | ||
packageManager: "yarn", | ||
majorVersion: "3", | ||
}, | ||
{ | ||
name: "yarn-berry-workspace", | ||
packageManager: "yarn", | ||
majorVersion: "3", | ||
}, | ||
] satisfies Partial<Fixture>[] | ||
) | ||
.map((fixture) => ({ | ||
...fixture, | ||
dir: resolveFixtureDirectory(fixture.name), | ||
workspace: fixture.name.includes("workspace"), | ||
})) | ||
.filter((fixture) => { | ||
// Bun is not yet supported on Windows | ||
if (isWindows && fixture.packageManager === "bun") { | ||
return false; | ||
} | ||
return true; | ||
}); | ||
|
||
export function resolveFixtureDirectory(name: string) { | ||
return fileURLToPath(new URL(`fixtures/${name}`, import.meta.url)); | ||
} |
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,62 @@ | ||
import { expect, it, describe, vi } from "vitest"; | ||
import { addDependency, removeDependency } from "../src"; | ||
import { fixtures } from "./_shared"; | ||
|
||
describe("api", () => { | ||
for (const fixture of fixtures.filter((f) => f.workspace)) { | ||
describe(fixture.name, () => { | ||
it("adds dependency to the workspace root", async () => { | ||
const addDependencySpy = vi.fn(addDependency); | ||
const executeAddDependencySpy = () => | ||
addDependencySpy("pathe", { | ||
cwd: fixture.dir, | ||
silent: !process.env.DEBUG, | ||
workspace: true, | ||
}); | ||
await executeAddDependencySpy(); | ||
expect(addDependencySpy).toHaveReturned(); | ||
}, 30_000); | ||
|
||
it("removes dependency from workspace root", async () => { | ||
const removeDependencySpy = vi.fn(removeDependency); | ||
const executeRemoveDependencySpy = () => | ||
removeDependencySpy("pathe", { | ||
cwd: fixture.dir, | ||
silent: !process.env.DEBUG, | ||
workspace: true, | ||
}); | ||
await executeRemoveDependencySpy(); | ||
expect(removeDependencySpy).toHaveReturned(); | ||
}, 30_000); | ||
|
||
const workspaceRef = | ||
fixture.name === "yarn-classic-workspace" | ||
? "./packages/workspace-a" | ||
: "workspace-a"; | ||
|
||
it("adds dependency to workspace package", async () => { | ||
const addDependencySpy = vi.fn(addDependency); | ||
const executeAddDependencySpy = () => | ||
addDependencySpy("ufo", { | ||
cwd: fixture.dir, | ||
silent: !process.env.DEBUG, | ||
workspace: workspaceRef, | ||
}); | ||
await executeAddDependencySpy(); | ||
expect(addDependencySpy).toHaveReturned(); | ||
}, 30_000); | ||
|
||
it("removes dependency from workspace package", async () => { | ||
const removeDependencySpy = vi.fn(removeDependency); | ||
const executeRemoveDependencySpy = () => | ||
removeDependencySpy("ufo", { | ||
cwd: fixture.dir, | ||
silent: !process.env.DEBUG, | ||
workspace: workspaceRef, | ||
}); | ||
await executeRemoveDependencySpy(); | ||
expect(removeDependencySpy).toHaveReturned(); | ||
}, 30_000); | ||
}); | ||
} | ||
}); |
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,62 @@ | ||
import { expect, it, describe, vi } from "vitest"; | ||
import { | ||
installDependencies, | ||
addDependency, | ||
removeDependency, | ||
ensureDependencyInstalled, | ||
} from "../src"; | ||
import { fixtures } from "./_shared"; | ||
|
||
describe("api (workspace)", () => { | ||
for (const fixture of fixtures.filter((f) => !f.workspace)) { | ||
describe(fixture.name, () => { | ||
it("installs dependencies", async () => { | ||
const installDependenciesSpy = vi.fn(installDependencies); | ||
const executeInstallDependenciesSpy = () => | ||
installDependenciesSpy({ | ||
cwd: fixture.dir, | ||
silent: !process.env.DEBUG, | ||
}); | ||
await executeInstallDependenciesSpy(); | ||
expect(installDependenciesSpy).toHaveReturned(); | ||
}, 30_000); | ||
|
||
it("adds dependency", async () => { | ||
const addDependencySpy = vi.fn(addDependency); | ||
const executeAddDependencySpy = () => | ||
addDependencySpy("pathe", { | ||
cwd: fixture.dir, | ||
silent: !process.env.DEBUG, | ||
}); | ||
|
||
await executeAddDependencySpy(); | ||
expect(addDependencySpy).toHaveReturned(); | ||
}, 30_000); | ||
|
||
it("ensures dependency is installed", async () => { | ||
const ensureDependencyInstalledSpy = vi.fn(ensureDependencyInstalled); | ||
|
||
const executeEnsureDependencyInstalledSpy = () => | ||
ensureDependencyInstalledSpy("pathe", { | ||
cwd: fixture.dir, | ||
}); | ||
|
||
await executeEnsureDependencyInstalledSpy(); | ||
expect(ensureDependencyInstalledSpy).toHaveReturned(); | ||
}); | ||
|
||
it("removes dependency", async () => { | ||
const removeDependencySpy = vi.fn(removeDependency); | ||
|
||
const executeRemoveDependencySpy = () => | ||
removeDependencySpy("pathe", { | ||
cwd: fixture.dir, | ||
silent: !process.env.DEBUG, | ||
}); | ||
|
||
await executeRemoveDependencySpy(); | ||
expect(removeDependencySpy).toHaveReturned(); | ||
}, 30_000); | ||
}); | ||
} | ||
}); |
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,32 @@ | ||
import { expect, it, describe } from "vitest"; | ||
import { detectPackageManager } from "../src"; | ||
import { fixtures } from "./_shared"; | ||
|
||
describe("detectPackageManager", () => { | ||
for (const fixture of fixtures) { | ||
describe(fixture.name, () => { | ||
it("should detect with package.json", async () => { | ||
const detected = await detectPackageManager(fixture.dir, { | ||
ignoreLockFile: true, | ||
}); | ||
expect(detected?.name).toBe(fixture.packageManager); | ||
if (fixture.majorVersion) { | ||
expect(detected?.majorVersion).toBe(fixture.majorVersion); | ||
} | ||
}); | ||
|
||
it.skipIf(fixture.name.includes("berry") /* TODO */)( | ||
"should detect with lock file", | ||
async () => { | ||
const detected = await detectPackageManager(fixture.dir, { | ||
ignorePackageJSON: true, | ||
}); | ||
expect(detected?.name).toBe(fixture.packageManager); | ||
if (fixture.majorVersion) { | ||
expect(detected?.majorVersion).toBe(fixture.majorVersion); | ||
} | ||
}, | ||
); | ||
}); | ||
} | ||
}); |
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,11 @@ | ||
{ | ||
"name": "fixture-bun-workspace", | ||
"private": true, | ||
"workspaces": [ | ||
"packages/*" | ||
], | ||
"dependencies": { | ||
"consola": "3.2.2" | ||
}, | ||
"packageManager": "bun@0.8.0" | ||
} |
6 changes: 1 addition & 5 deletions
6
...classic/packages/workspace-a/package.json → ...rkspace/packages/workspace-a/package.json
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 |
---|---|---|
@@ -1,10 +1,6 @@ | ||
{ | ||
"name": "workspace-a", | ||
"private": true, | ||
"version": "0.0.0", | ||
"packageManager": "yarn@1.22.19", | ||
"devDependencies": { | ||
"ufo": "1.1.2" | ||
}, | ||
"private": true, | ||
"dependencies": {} | ||
} |
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 |
---|---|---|
@@ -1,9 +1,8 @@ | ||
{ | ||
"name": "fixture-bun", | ||
"version": "0.0.0", | ||
"packageManager": "bun@0.8.0", | ||
"private": true, | ||
"workspaces": [ | ||
"packages/*" | ||
] | ||
"dependencies": { | ||
"consola": "3.2.2" | ||
}, | ||
"packageManager": "bun@0.8.0" | ||
} |
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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,11 @@ | ||
{ | ||
"name": "fixture-npm-workspace", | ||
"private": true, | ||
"workspaces": [ | ||
"packages/*" | ||
], | ||
"packageManager": "npm@9.7.2", | ||
"dependencies": { | ||
"consola": "3.2.2" | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
test/fixtures/npm-workspace/packages/workspace-a/package.json
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,5 @@ | ||
{ | ||
"name": "workspace-a", | ||
"version": "0.0.0", | ||
"private": true | ||
} |
Oops, something went wrong.