-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathunit.test.ts
56 lines (49 loc) · 1.62 KB
/
unit.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import * as path from "path";
import { runInTempDir } from "./test_utils";
import { setupNpmRc } from "../src/commands";
import * as assert from "assert/strict";
import { NpmPackage, readTextFile, writeTextFile } from "../src/utils";
describe("npmrc", () => {
it("doesn't overwrite exising jsr mapping", async () => {
await runInTempDir(async (dir) => {
const npmrc = path.join(dir, ".npmrc");
await writeTextFile(npmrc, "@jsr:registry=https://example.com\n");
await setupNpmRc(dir);
const content = await readTextFile(npmrc);
assert.equal(content.trim(), "@jsr:registry=https://example.com");
});
});
it("adds newline in between entries if necessary", async () => {
await runInTempDir(async (dir) => {
const npmrc = path.join(dir, ".npmrc");
await writeTextFile(npmrc, "@foo:registry=https://example.com");
await setupNpmRc(dir);
const content = await readTextFile(npmrc);
assert.equal(
content.trim(),
[
"@foo:registry=https://example.com",
"@jsr:registry=https://npm.jsr.io",
].join("\n"),
);
});
});
});
describe("NpmPackage", () => {
it("parse", () => {
assert.equal(NpmPackage.from("foo").toString(), "foo");
assert.equal(NpmPackage.from("foo-bar").toString(), "foo-bar");
assert.equal(
NpmPackage.from("@foo-bar/foo-bar").toString(),
"@foo-bar/foo-bar",
);
assert.equal(
NpmPackage.from("@[email protected]").toString(),
);
assert.equal(
NpmPackage.from("@foo-bar/[email protected]").toString(),
"@foo-bar/[email protected]",
);
});
});