|
| 1 | +import { describe, it } from "node:test"; |
| 2 | +import * as fs from "fs"; |
| 3 | +import * as path from "path"; |
| 4 | +import { isDirectory, isFile, runJsr, withTempEnv } from "./test_utils"; |
| 5 | +import * as assert from "node:assert/strict"; |
| 6 | + |
| 7 | +describe("install", () => { |
| 8 | + it("jsr i @std/encoding - resolve latest version", async () => { |
| 9 | + await withTempEnv(["i", "@std/encoding"], async (getPkgJson, dir) => { |
| 10 | + const pkgJson = await getPkgJson(); |
| 11 | + assert( |
| 12 | + pkgJson.dependencies && "@std/encoding" in pkgJson.dependencies, |
| 13 | + "Missing dependency entry" |
| 14 | + ); |
| 15 | + |
| 16 | + assert.match( |
| 17 | + pkgJson.dependencies["@std/encoding"], |
| 18 | + /^npm:@jsr\/std__encoding@\^\d+\.\d+\.\d+.*$/ |
| 19 | + ); |
| 20 | + |
| 21 | + const depPath = path.join(dir, "node_modules", "@std", "encoding"); |
| 22 | + assert(await isDirectory(depPath), "Not installed in node_modules"); |
| 23 | + }); |
| 24 | + }); |
| 25 | + |
| 26 | + it("jsr i @std/[email protected] - with version", async () => { |
| 27 | + await withTempEnv(["i", "@std/[email protected]"], async (getPkgJson) => { |
| 28 | + const pkgJson = await getPkgJson(); |
| 29 | + assert.deepEqual(pkgJson.dependencies, { |
| 30 | + "@std/encoding": "npm:@jsr/std__encoding@^0.216.0", |
| 31 | + }); |
| 32 | + }); |
| 33 | + }); |
| 34 | + |
| 35 | + it("jsr install @std/[email protected] - command", async () => { |
| 36 | + await withTempEnv(["i", "@std/[email protected]"], async (getPkgJson) => { |
| 37 | + const pkgJson = await getPkgJson(); |
| 38 | + assert.deepEqual(pkgJson.dependencies, { |
| 39 | + "@std/encoding": "npm:@jsr/std__encoding@^0.216.0", |
| 40 | + }); |
| 41 | + }); |
| 42 | + }); |
| 43 | + |
| 44 | + it("jsr add @std/[email protected] - command", async () => { |
| 45 | + await withTempEnv(["i", "@std/[email protected]"], async (getPkgJson) => { |
| 46 | + const pkgJson = await getPkgJson(); |
| 47 | + assert.deepEqual(pkgJson.dependencies, { |
| 48 | + "@std/encoding": "npm:@jsr/std__encoding@^0.216.0", |
| 49 | + }); |
| 50 | + }); |
| 51 | + }); |
| 52 | + |
| 53 | + it("jsr add -D @std/[email protected] - dev dependency", async () => { |
| 54 | + await withTempEnv( |
| 55 | + ["i", "-D", "@std/[email protected]"], |
| 56 | + async (getPkgJson) => { |
| 57 | + const pkgJson = await getPkgJson(); |
| 58 | + assert.deepEqual(pkgJson.devDependencies, { |
| 59 | + "@std/encoding": "npm:@jsr/std__encoding@^0.216.0", |
| 60 | + }); |
| 61 | + } |
| 62 | + ); |
| 63 | + |
| 64 | + await withTempEnv( |
| 65 | + ["i", "--save-dev", "@std/[email protected]"], |
| 66 | + async (getPkgJson) => { |
| 67 | + const pkgJson = await getPkgJson(); |
| 68 | + assert.deepEqual(pkgJson.devDependencies, { |
| 69 | + "@std/encoding": "npm:@jsr/std__encoding@^0.216.0", |
| 70 | + }); |
| 71 | + } |
| 72 | + ); |
| 73 | + }); |
| 74 | + |
| 75 | + it("jsr add -O @std/[email protected] - dev dependency", async () => { |
| 76 | + await withTempEnv( |
| 77 | + ["i", "-O", "@std/[email protected]"], |
| 78 | + async (getPkgJson) => { |
| 79 | + const pkgJson = await getPkgJson(); |
| 80 | + assert.deepEqual(pkgJson.optionalDependencies, { |
| 81 | + "@std/encoding": "npm:@jsr/std__encoding@^0.216.0", |
| 82 | + }); |
| 83 | + } |
| 84 | + ); |
| 85 | + |
| 86 | + await withTempEnv( |
| 87 | + ["i", "--save-optional", "@std/[email protected]"], |
| 88 | + async (getPkgJson) => { |
| 89 | + const pkgJson = await getPkgJson(); |
| 90 | + assert.deepEqual(pkgJson.optionalDependencies, { |
| 91 | + "@std/encoding": "npm:@jsr/std__encoding@^0.216.0", |
| 92 | + }); |
| 93 | + } |
| 94 | + ); |
| 95 | + }); |
| 96 | + |
| 97 | + it("jsr add --npm @std/[email protected] - forces npm", async () => { |
| 98 | + await withTempEnv( |
| 99 | + ["i", "--npm", "@std/[email protected]"], |
| 100 | + async (_, dir) => { |
| 101 | + assert( |
| 102 | + await isFile(path.join(dir, "package-lock.json")), |
| 103 | + "npm lockfile not created" |
| 104 | + ); |
| 105 | + } |
| 106 | + ); |
| 107 | + }); |
| 108 | + |
| 109 | + it("jsr add --yarn @std/[email protected] - forces yarn", async () => { |
| 110 | + await withTempEnv( |
| 111 | + ["i", "--yarn", "@std/[email protected]"], |
| 112 | + async (_, dir) => { |
| 113 | + assert( |
| 114 | + await isFile(path.join(dir, "yarn.lock")), |
| 115 | + "yarn lockfile not created" |
| 116 | + ); |
| 117 | + } |
| 118 | + ); |
| 119 | + }); |
| 120 | + |
| 121 | + it("jsr add --pnpm @std/[email protected] - forces pnpm", async () => { |
| 122 | + await withTempEnv( |
| 123 | + ["i", "--pnpm", "@std/[email protected]"], |
| 124 | + async (_, dir) => { |
| 125 | + assert( |
| 126 | + await isFile(path.join(dir, "pnpm-lock.yaml")), |
| 127 | + "pnpm lockfile not created" |
| 128 | + ); |
| 129 | + } |
| 130 | + ); |
| 131 | + }); |
| 132 | +}); |
| 133 | + |
| 134 | +describe("remove", () => { |
| 135 | + it("jsr r @std/[email protected] - removes node_modules", async () => { |
| 136 | + await withTempEnv( |
| 137 | + |
| 138 | + async (getPkgJson, dir) => { |
| 139 | + await runJsr(["r", "@std/encoding"], dir); |
| 140 | + |
| 141 | + const pkgJson = await getPkgJson(); |
| 142 | + assert.equal(pkgJson.dependencies, undefined); |
| 143 | + |
| 144 | + const depPath = path.join(dir, "node_modules", "@std", "encoding"); |
| 145 | + assert( |
| 146 | + !(await isDirectory(depPath)), |
| 147 | + "Folder in node_modules not removed" |
| 148 | + ); |
| 149 | + } |
| 150 | + ); |
| 151 | + }); |
| 152 | + |
| 153 | + it("jsr r @std/[email protected] - command", async () => { |
| 154 | + await withTempEnv( |
| 155 | + |
| 156 | + async (getPkgJson, dir) => { |
| 157 | + await runJsr(["r", "@std/encoding"], dir); |
| 158 | + |
| 159 | + const pkgJson = await getPkgJson(); |
| 160 | + assert.equal(pkgJson.dependencies, undefined); |
| 161 | + } |
| 162 | + ); |
| 163 | + }); |
| 164 | + |
| 165 | + it("jsr remove @std/[email protected] - command", async () => { |
| 166 | + await withTempEnv( |
| 167 | + |
| 168 | + async (getPkgJson, dir) => { |
| 169 | + await runJsr(["remove", "@std/encoding"], dir); |
| 170 | + |
| 171 | + const pkgJson = await getPkgJson(); |
| 172 | + assert.equal(pkgJson.dependencies, undefined); |
| 173 | + } |
| 174 | + ); |
| 175 | + }); |
| 176 | + |
| 177 | + it("jsr uninstall @std/[email protected] - command", async () => { |
| 178 | + await withTempEnv( |
| 179 | + |
| 180 | + async (getPkgJson, dir) => { |
| 181 | + await runJsr(["uninstall", "@std/encoding"], dir); |
| 182 | + |
| 183 | + const pkgJson = await getPkgJson(); |
| 184 | + assert.equal(pkgJson.dependencies, undefined); |
| 185 | + } |
| 186 | + ); |
| 187 | + }); |
| 188 | +}); |
0 commit comments