-
Notifications
You must be signed in to change notification settings - Fork 14
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
1 parent
4864c29
commit 30c8186
Showing
6 changed files
with
304 additions
and
28 deletions.
There are no files selected for viewing
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
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,188 @@ | ||
import { describe, it } from "node:test"; | ||
import * as fs from "fs"; | ||
import * as path from "path"; | ||
import { isDirectory, isFile, runJsr, withTempEnv } from "./test_utils"; | ||
import * as assert from "node:assert/strict"; | ||
|
||
describe("install", () => { | ||
it("jsr i @std/encoding - resolve latest version", async () => { | ||
await withTempEnv(["i", "@std/encoding"], async (getPkgJson, dir) => { | ||
const pkgJson = await getPkgJson(); | ||
assert( | ||
pkgJson.dependencies && "@std/encoding" in pkgJson.dependencies, | ||
"Missing dependency entry" | ||
); | ||
|
||
assert.match( | ||
pkgJson.dependencies["@std/encoding"], | ||
/^npm:@jsr\/std__encoding@\^\d+\.\d+\.\d+.*$/ | ||
); | ||
|
||
const depPath = path.join(dir, "node_modules", "@std", "encoding"); | ||
assert(await isDirectory(depPath), "Not installed in node_modules"); | ||
}); | ||
}); | ||
|
||
it("jsr i @std/[email protected] - with version", async () => { | ||
await withTempEnv(["i", "@std/[email protected]"], async (getPkgJson) => { | ||
const pkgJson = await getPkgJson(); | ||
assert.deepEqual(pkgJson.dependencies, { | ||
"@std/encoding": "npm:@jsr/std__encoding@^0.216.0", | ||
}); | ||
}); | ||
}); | ||
|
||
it("jsr install @std/[email protected] - command", async () => { | ||
await withTempEnv(["i", "@std/[email protected]"], async (getPkgJson) => { | ||
const pkgJson = await getPkgJson(); | ||
assert.deepEqual(pkgJson.dependencies, { | ||
"@std/encoding": "npm:@jsr/std__encoding@^0.216.0", | ||
}); | ||
}); | ||
}); | ||
|
||
it("jsr add @std/[email protected] - command", async () => { | ||
await withTempEnv(["i", "@std/[email protected]"], async (getPkgJson) => { | ||
const pkgJson = await getPkgJson(); | ||
assert.deepEqual(pkgJson.dependencies, { | ||
"@std/encoding": "npm:@jsr/std__encoding@^0.216.0", | ||
}); | ||
}); | ||
}); | ||
|
||
it("jsr add -D @std/[email protected] - dev dependency", async () => { | ||
await withTempEnv( | ||
["i", "-D", "@std/[email protected]"], | ||
async (getPkgJson) => { | ||
const pkgJson = await getPkgJson(); | ||
assert.deepEqual(pkgJson.devDependencies, { | ||
"@std/encoding": "npm:@jsr/std__encoding@^0.216.0", | ||
}); | ||
} | ||
); | ||
|
||
await withTempEnv( | ||
["i", "--save-dev", "@std/[email protected]"], | ||
async (getPkgJson) => { | ||
const pkgJson = await getPkgJson(); | ||
assert.deepEqual(pkgJson.devDependencies, { | ||
"@std/encoding": "npm:@jsr/std__encoding@^0.216.0", | ||
}); | ||
} | ||
); | ||
}); | ||
|
||
it("jsr add -O @std/[email protected] - dev dependency", async () => { | ||
await withTempEnv( | ||
["i", "-O", "@std/[email protected]"], | ||
async (getPkgJson) => { | ||
const pkgJson = await getPkgJson(); | ||
assert.deepEqual(pkgJson.optionalDependencies, { | ||
"@std/encoding": "npm:@jsr/std__encoding@^0.216.0", | ||
}); | ||
} | ||
); | ||
|
||
await withTempEnv( | ||
["i", "--save-optional", "@std/[email protected]"], | ||
async (getPkgJson) => { | ||
const pkgJson = await getPkgJson(); | ||
assert.deepEqual(pkgJson.optionalDependencies, { | ||
"@std/encoding": "npm:@jsr/std__encoding@^0.216.0", | ||
}); | ||
} | ||
); | ||
}); | ||
|
||
it("jsr add --npm @std/[email protected] - forces npm", async () => { | ||
await withTempEnv( | ||
["i", "--npm", "@std/[email protected]"], | ||
async (_, dir) => { | ||
assert( | ||
await isFile(path.join(dir, "package-lock.json")), | ||
"npm lockfile not created" | ||
); | ||
} | ||
); | ||
}); | ||
|
||
it("jsr add --yarn @std/[email protected] - forces yarn", async () => { | ||
await withTempEnv( | ||
["i", "--yarn", "@std/[email protected]"], | ||
async (_, dir) => { | ||
assert( | ||
await isFile(path.join(dir, "yarn.lock")), | ||
"yarn lockfile not created" | ||
); | ||
} | ||
); | ||
}); | ||
|
||
it("jsr add --pnpm @std/[email protected] - forces pnpm", async () => { | ||
await withTempEnv( | ||
["i", "--pnpm", "@std/[email protected]"], | ||
async (_, dir) => { | ||
assert( | ||
await isFile(path.join(dir, "pnpm-lock.yaml")), | ||
"pnpm lockfile not created" | ||
); | ||
} | ||
); | ||
}); | ||
}); | ||
|
||
describe("remove", () => { | ||
it("jsr r @std/[email protected] - removes node_modules", async () => { | ||
await withTempEnv( | ||
["i", "@std/[email protected]"], | ||
async (getPkgJson, dir) => { | ||
await runJsr(["r", "@std/encoding"], dir); | ||
|
||
const pkgJson = await getPkgJson(); | ||
assert.equal(pkgJson.dependencies, undefined); | ||
|
||
const depPath = path.join(dir, "node_modules", "@std", "encoding"); | ||
assert( | ||
!(await isDirectory(depPath)), | ||
"Folder in node_modules not removed" | ||
); | ||
} | ||
); | ||
}); | ||
|
||
it("jsr r @std/[email protected] - command", async () => { | ||
await withTempEnv( | ||
["i", "@std/[email protected]"], | ||
async (getPkgJson, dir) => { | ||
await runJsr(["r", "@std/encoding"], dir); | ||
|
||
const pkgJson = await getPkgJson(); | ||
assert.equal(pkgJson.dependencies, undefined); | ||
} | ||
); | ||
}); | ||
|
||
it("jsr remove @std/[email protected] - command", async () => { | ||
await withTempEnv( | ||
["i", "@std/[email protected]"], | ||
async (getPkgJson, dir) => { | ||
await runJsr(["remove", "@std/encoding"], dir); | ||
|
||
const pkgJson = await getPkgJson(); | ||
assert.equal(pkgJson.dependencies, undefined); | ||
} | ||
); | ||
}); | ||
|
||
it("jsr uninstall @std/[email protected] - command", async () => { | ||
await withTempEnv( | ||
["i", "@std/[email protected]"], | ||
async (getPkgJson, dir) => { | ||
await runJsr(["uninstall", "@std/encoding"], dir); | ||
|
||
const pkgJson = await getPkgJson(); | ||
assert.equal(pkgJson.dependencies, undefined); | ||
} | ||
); | ||
}); | ||
}); |
Oops, something went wrong.