@riebeckite/test 0.0.22 → 0.0.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/e2e/index.js +21 -3
- package/dist/fixtures.d.ts +3 -0
- package/dist/fixtures.js +33 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +40 -8
- package/package.json +7 -1
package/dist/e2e/index.js
CHANGED
|
@@ -317,6 +317,16 @@ function createLogger(label = "e2e") {
|
|
|
317
317
|
// e2e/pack.ts
|
|
318
318
|
import fs3 from "node:fs";
|
|
319
319
|
import path4 from "node:path";
|
|
320
|
+
function assertPackArtifacts(packageDir, pkg) {
|
|
321
|
+
const manifest = JSON.parse(
|
|
322
|
+
fs3.readFileSync(path4.join(packageDir, "package.json"), "utf8")
|
|
323
|
+
);
|
|
324
|
+
if (manifest.files?.includes("dist") && !fs3.existsSync(path4.join(packageDir, "dist"))) {
|
|
325
|
+
throw new Error(
|
|
326
|
+
`Cannot pack ${pkg.name}: dist/ is missing. Build workspace packages before running isolated package tests.`
|
|
327
|
+
);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
320
330
|
function packageLevels(repoRoot, packages) {
|
|
321
331
|
const byName = new Map(packages.map((pkg) => [pkg.name, pkg]));
|
|
322
332
|
const dependencies = /* @__PURE__ */ new Map();
|
|
@@ -361,12 +371,20 @@ async function packPackages(tarballDir, options) {
|
|
|
361
371
|
if (!fs3.existsSync(packageDir)) {
|
|
362
372
|
logger.fail(`Package directory is missing: ${pkg.directory}`);
|
|
363
373
|
}
|
|
374
|
+
assertPackArtifacts(packageDir, pkg);
|
|
364
375
|
const manifest = JSON.parse(
|
|
365
376
|
fs3.readFileSync(path4.join(packageDir, "package.json"), "utf8")
|
|
366
377
|
);
|
|
367
|
-
await runAsync(
|
|
368
|
-
|
|
369
|
-
|
|
378
|
+
await runAsync(
|
|
379
|
+
"pnpm",
|
|
380
|
+
[
|
|
381
|
+
"--config.ignore-scripts=true",
|
|
382
|
+
"pack",
|
|
383
|
+
"--pack-destination",
|
|
384
|
+
tarballDir
|
|
385
|
+
],
|
|
386
|
+
{ cwd: packageDir }
|
|
387
|
+
);
|
|
370
388
|
const sanitized = pkg.name.replace(/^@/, "").replace(/\//g, "-");
|
|
371
389
|
const tarball = path4.join(
|
|
372
390
|
tarballDir,
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export type Frontmatter = Readonly<Record<string, string | number | boolean | readonly string[]>>;
|
|
2
|
+
export declare function markdown(body: string, frontmatter?: Frontmatter): string;
|
|
3
|
+
export declare function withTemporaryDirectory<T>(prefixOrCallback: string | ((directory: string) => Promise<T>), callback?: (directory: string) => Promise<T>): Promise<T>;
|
package/dist/fixtures.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// fixtures.ts
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
function frontmatterValue(value) {
|
|
6
|
+
if (Array.isArray(value))
|
|
7
|
+
return `[${value.map((item) => JSON.stringify(item)).join(", ")}]`;
|
|
8
|
+
return String(value);
|
|
9
|
+
}
|
|
10
|
+
function markdown(body, frontmatter) {
|
|
11
|
+
if (!frontmatter || Object.keys(frontmatter).length === 0) return body;
|
|
12
|
+
const fields = Object.entries(frontmatter).map(([key, value]) => `${key}: ${frontmatterValue(value)}`).join("\n");
|
|
13
|
+
return `---
|
|
14
|
+
${fields}
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
${body}`;
|
|
18
|
+
}
|
|
19
|
+
async function withTemporaryDirectory(prefixOrCallback, callback) {
|
|
20
|
+
const prefix = typeof prefixOrCallback === "string" ? prefixOrCallback : "riebeckite-test-";
|
|
21
|
+
const operation = typeof prefixOrCallback === "function" ? prefixOrCallback : callback;
|
|
22
|
+
if (!operation) throw new Error("A temporary directory callback is required");
|
|
23
|
+
const directory = await fs.mkdtemp(path.join(os.tmpdir(), prefix));
|
|
24
|
+
try {
|
|
25
|
+
return await operation(directory);
|
|
26
|
+
} finally {
|
|
27
|
+
await fs.rm(directory, { recursive: true, force: true, maxRetries: 3 });
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export {
|
|
31
|
+
markdown,
|
|
32
|
+
withTemporaryDirectory
|
|
33
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -8,4 +8,5 @@
|
|
|
8
8
|
* `@riebeckite/test/e2e` entry point because it orchestrates processes, the
|
|
9
9
|
* filesystem, and published tarballs.
|
|
10
10
|
*/
|
|
11
|
+
export { type Frontmatter, markdown, withTemporaryDirectory, } from "./fixtures.js";
|
|
11
12
|
export { assertGolden, assertGoldenJson, type GoldenOptions, } from "./golden.js";
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,44 @@
|
|
|
1
|
+
// fixtures.ts
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
function frontmatterValue(value) {
|
|
6
|
+
if (Array.isArray(value))
|
|
7
|
+
return `[${value.map((item) => JSON.stringify(item)).join(", ")}]`;
|
|
8
|
+
return String(value);
|
|
9
|
+
}
|
|
10
|
+
function markdown(body, frontmatter) {
|
|
11
|
+
if (!frontmatter || Object.keys(frontmatter).length === 0) return body;
|
|
12
|
+
const fields = Object.entries(frontmatter).map(([key, value]) => `${key}: ${frontmatterValue(value)}`).join("\n");
|
|
13
|
+
return `---
|
|
14
|
+
${fields}
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
${body}`;
|
|
18
|
+
}
|
|
19
|
+
async function withTemporaryDirectory(prefixOrCallback, callback) {
|
|
20
|
+
const prefix = typeof prefixOrCallback === "string" ? prefixOrCallback : "riebeckite-test-";
|
|
21
|
+
const operation = typeof prefixOrCallback === "function" ? prefixOrCallback : callback;
|
|
22
|
+
if (!operation) throw new Error("A temporary directory callback is required");
|
|
23
|
+
const directory = await fs.mkdtemp(path.join(os.tmpdir(), prefix));
|
|
24
|
+
try {
|
|
25
|
+
return await operation(directory);
|
|
26
|
+
} finally {
|
|
27
|
+
await fs.rm(directory, { recursive: true, force: true, maxRetries: 3 });
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
1
31
|
// golden.ts
|
|
2
32
|
import assert from "node:assert/strict";
|
|
3
|
-
import
|
|
4
|
-
import
|
|
33
|
+
import fs2 from "node:fs";
|
|
34
|
+
import path2 from "node:path";
|
|
5
35
|
import { fileURLToPath } from "node:url";
|
|
6
36
|
function normalizeText(value) {
|
|
7
37
|
return `${value.replace(/\r\n?/g, "\n").replace(/\n+$/, "")}
|
|
8
38
|
`;
|
|
9
39
|
}
|
|
10
40
|
function relative(file) {
|
|
11
|
-
return
|
|
41
|
+
return path2.relative(process.cwd(), file) || file;
|
|
12
42
|
}
|
|
13
43
|
function assertGolden(actual, golden, options = {}) {
|
|
14
44
|
const normalize = options.normalize ?? true;
|
|
@@ -16,15 +46,15 @@ function assertGolden(actual, golden, options = {}) {
|
|
|
16
46
|
const file = fileURLToPath(golden);
|
|
17
47
|
const label = options.message ? `${options.message}: ` : "";
|
|
18
48
|
if (process.env.UPDATE_GOLDEN === "1") {
|
|
19
|
-
|
|
20
|
-
|
|
49
|
+
fs2.mkdirSync(path2.dirname(file), { recursive: true });
|
|
50
|
+
fs2.writeFileSync(file, value, "utf8");
|
|
21
51
|
return;
|
|
22
52
|
}
|
|
23
53
|
assert.ok(
|
|
24
|
-
|
|
54
|
+
fs2.existsSync(file),
|
|
25
55
|
`${label}Missing golden file ${relative(file)}. Run \`pnpm test:update\` to create it.`
|
|
26
56
|
);
|
|
27
|
-
const recorded =
|
|
57
|
+
const recorded = fs2.readFileSync(file, "utf8");
|
|
28
58
|
assert.equal(
|
|
29
59
|
value,
|
|
30
60
|
normalize ? normalizeText(recorded) : recorded,
|
|
@@ -36,5 +66,7 @@ function assertGoldenJson(value, golden, options = {}) {
|
|
|
36
66
|
}
|
|
37
67
|
export {
|
|
38
68
|
assertGolden,
|
|
39
|
-
assertGoldenJson
|
|
69
|
+
assertGoldenJson,
|
|
70
|
+
markdown,
|
|
71
|
+
withTemporaryDirectory
|
|
40
72
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@riebeckite/test",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.24",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -17,6 +17,12 @@
|
|
|
17
17
|
"import": "./dist/e2e/index.js",
|
|
18
18
|
"source": "./e2e/index.ts",
|
|
19
19
|
"default": "./dist/e2e/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./fixtures": {
|
|
22
|
+
"types": "./dist/fixtures.d.ts",
|
|
23
|
+
"import": "./dist/fixtures.js",
|
|
24
|
+
"source": "./fixtures.ts",
|
|
25
|
+
"default": "./dist/fixtures.js"
|
|
20
26
|
}
|
|
21
27
|
},
|
|
22
28
|
"files": [
|