-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsync-tool-version.test.js
More file actions
71 lines (66 loc) · 1.56 KB
/
Copy pathsync-tool-version.test.js
File metadata and controls
71 lines (66 loc) · 1.56 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import assert from "node:assert/strict";
import { mkdir, readFile, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import path from "node:path";
import { test } from "node:test";
import { DEFAULT_LOCK_FILENAME, runSync } from "../dist/api.mjs";
test("sync writes lock toolVersion from package.json", async () => {
const tmpRoot = path.join(
tmpdir(),
`docs-cache-tool-version-${Date.now().toString(36)}`,
);
await mkdir(tmpRoot, { recursive: true });
const configPath = path.join(tmpRoot, "docs.config.json");
const cacheDir = path.join(tmpRoot, ".docs");
await writeFile(
configPath,
JSON.stringify(
{
$schema:
"https://raw.githubusercontent.com/fbosch/docs-cache/main/docs.config.schema.json",
sources: [
{
id: "local",
repo: "https://example.com/repo.git",
},
],
},
null,
2,
),
"utf8",
);
await writeFile(
path.join(tmpRoot, "package.json"),
JSON.stringify({
name: "not-docs-cache",
version: "9.9.9",
}),
"utf8",
);
const originalCwd = process.cwd();
try {
process.chdir(tmpRoot);
await runSync({
configPath,
cacheDirOverride: cacheDir,
json: true,
lockOnly: true,
offline: true,
failOnMiss: false,
});
} finally {
process.chdir(originalCwd);
}
const lockRaw = await readFile(
path.join(tmpRoot, DEFAULT_LOCK_FILENAME),
"utf8",
);
const lock = JSON.parse(lockRaw);
const pkgRaw = await readFile(
new URL("../package.json", import.meta.url),
"utf8",
);
const pkg = JSON.parse(pkgRaw);
assert.equal(lock.toolVersion, pkg.version);
});