@adamhl8/configs 3.4.1 → 3.5.0
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/README.md +11 -3
- package/dist/env/index.d.ts.map +1 -1
- package/dist/env/index.js.map +1 -1
- package/dist/test-utils/subprocess-coverage/preload.js +12 -1
- package/dist/test-utils/subprocess-coverage/preload.js.map +1 -1
- package/dist/test-utils/subprocess-coverage/report.js +11 -2
- package/dist/test-utils/subprocess-coverage/report.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -440,10 +440,18 @@ preload = ["@adamhl8/configs/test/preload", "@adamhl8/configs/test/subprocess-co
|
|
|
440
440
|
const { run } = await copyFixture(FIXTURE, { shell: { env: minimalEnv(subprocessCoverageEnv()) } })
|
|
441
441
|
```
|
|
442
442
|
|
|
443
|
-
- After the run, the coverage from every process is merged, mapped back to `src/` through the package's source maps, printed as a table (statements, branches, functions, lines), and written to `coverage/lcov.info
|
|
444
|
-
-
|
|
443
|
+
- After the run, the coverage from every process is merged, mapped back to `src/` through the package's source maps, printed as a table (statements, branches, functions, lines), and written to `coverage/subprocess/lcov.info`, which keeps it apart from the `coverage/lcov.info` that Bun writes.
|
|
444
|
+
- To keep Bun's own coverage for code that tests import directly, leave `coverage = true` under `[test]` and list the files that subprocess coverage owns in `coveragePathIgnorePatterns`. Bun then skips those files, and the subprocess report keeps only them, so each file appears in one of the two tables. A file you don't list is left to Bun, so a file that only child processes load shows up in neither table. With `coverage = false`, the subprocess report keeps every file.
|
|
445
|
+
|
|
446
|
+
```toml
|
|
447
|
+
[test]
|
|
448
|
+
coverage = true
|
|
449
|
+
coveragePathIgnorePatterns = ["**/__tests__/**", "src/cli/**"]
|
|
450
|
+
```
|
|
451
|
+
|
|
452
|
+
- This reads `bunfig.toml` from the project root, so turning on Bun's coverage with `--coverage` instead leaves the subprocess report unfiltered.
|
|
445
453
|
- The project needs the optional peer dependencies listed under [Installation](#installation) and a build with source maps, which `tsdownConfig` produces. Tests have to install the packed tarball, as with `packPackage`, because only the installed `dist/` is instrumented.
|
|
446
|
-
-
|
|
454
|
+
- A process killed by a signal writes no coverage. An `exit` listener that the package adds in the same tick as a synchronous `process.exit()` isn't counted.
|
|
447
455
|
|
|
448
456
|
Import it only from a preload. Imported from a test file, its `afterAll` would be scoped to that file, so the report would run after that file instead of after the whole run.
|
|
449
457
|
|
package/dist/env/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/env/index.ts"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/env/index.ts"],"mappings":";;KAiBK,gBAAgB;qBAER,UAOP"}
|
package/dist/env/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/env/index.ts"],"sourcesContent":["import process from \"node:process\"\n\nimport arkenv from \"arkenv\"\nimport { attempt, isErr } from \"ts-explicit-errors\"\n\ntype ArkEnv = typeof arkenv\n\nexport const parseEnv = ((...args: Parameters<ArkEnv>) => {\n const env = attempt(() => arkenv(...args))\n if (isErr(env)) {\n console.error(env.message)\n process.exit(1)\n }\n return env\n}) as ArkEnv\n\nexport { requireWhen } from \"#env/utils.ts\"\n"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/env/index.ts"],"sourcesContent":["// Migrate to ArkEnv 1.0 once it's stable, because 1.0 turns the `arkenv` package into its CLI.\n// Importing `arkenv` as a library throws on 1.0.\n// Swap the `arkenv` dependency for `@arkenv/core`, and import from it here and in `utils.ts`.\n// Rewrite `parseEnv` with `arkenv` from `@arkenv/core/safe` and `formatIssues` from `@arkenv/core/issues`.\n// That lets us drop `ts-explicit-errors`, which nothing else uses.\n// Fix `requireWhen` so its `unset` placeholder stops leaking into errors like \"must be a number or a symbol\".\n// Check whether the RC still prints \"(was [REDACTED])\" for a missing secret-looking key, where 0.12 says \"(was missing)\".\n// Look at the new features we might use:\n// - `emptyAsUndefined`, so `PORT=` in a `.env` file counts as unset and defaults apply\n// - `onUndeclaredKey: \"reject\"`, to fail on keys the schema doesn't declare\n// - issue `code`s like `MISSING_VARIABLE` on `ArkEnvError`\n// - `arkenv check`, to validate the env in CI\nimport process from \"node:process\"\n\nimport arkenv from \"arkenv\"\nimport { attempt, isErr } from \"ts-explicit-errors\"\n\ntype ArkEnv = typeof arkenv\n\nexport const parseEnv = ((...args: Parameters<ArkEnv>) => {\n const env = attempt(() => arkenv(...args))\n if (isErr(env)) {\n console.error(env.message)\n process.exit(1)\n }\n return env\n}) as ArkEnv\n\nexport { requireWhen } from \"#env/utils.ts\"\n"],"mappings":";;;;;AAmBA,MAAa,aAAa,GAAG,SAA6B;CACxD,MAAM,MAAM,cAAc,OAAO,GAAG,IAAI,CAAC;CACzC,IAAI,MAAM,GAAG,GAAG;EACd,QAAQ,MAAM,IAAI,OAAO;EACzB,QAAQ,KAAK,CAAC;CAChB;CACA,OAAO;AACT"}
|
|
@@ -9,9 +9,20 @@ import { afterAll } from "bun:test";
|
|
|
9
9
|
// src/test-utils/subprocess-coverage/preload.ts
|
|
10
10
|
const CHILD_PRELOAD = path.join(import.meta.dir, `child-preload${path.extname(import.meta.path)}`);
|
|
11
11
|
const hasName = (value) => typeof value === "object" && value !== null && "name" in value && typeof value.name === "string";
|
|
12
|
+
const isRecord = (value) => typeof value === "object" && value !== null;
|
|
12
13
|
const root = process.cwd();
|
|
13
14
|
const packageJson = await bun.file(path.join(root, "package.json")).json();
|
|
14
15
|
if (!hasName(packageJson)) throw new Error(`subprocess coverage needs a package name in ${root}/package.json`);
|
|
16
|
+
const REPORT_DIR = path.join(root, "coverage/subprocess");
|
|
17
|
+
/** Returns Bun's `coveragePathIgnorePatterns` while its coverage is on, or `undefined` when it's off. */
|
|
18
|
+
const readBunIgnorePatterns = async () => {
|
|
19
|
+
const bunfigFile = bun.file(path.join(root, "bunfig.toml"));
|
|
20
|
+
const bunfig = await bunfigFile.exists() ? bun.TOML.parse(await bunfigFile.text()) : {};
|
|
21
|
+
const test = isRecord(bunfig) && isRecord(bunfig["test"]) ? bunfig["test"] : {};
|
|
22
|
+
if (!(test["coverage"] === true)) return;
|
|
23
|
+
return [test["coveragePathIgnorePatterns"]].flat().filter((pattern) => typeof pattern === "string");
|
|
24
|
+
};
|
|
25
|
+
const includePatterns = (await readBunIgnorePatterns())?.map((pattern) => path.join(root, pattern));
|
|
15
26
|
const rawDir = await fs.mkdtemp(path.join(os.tmpdir(), "subprocess-coverage-"));
|
|
16
27
|
const settings = {
|
|
17
28
|
rawDir,
|
|
@@ -21,7 +32,7 @@ const settings = {
|
|
|
21
32
|
process.env["BUN_OPTIONS"] = `--preload=${CHILD_PRELOAD}`;
|
|
22
33
|
process.env[SUBPROCESS_COVERAGE_SETTINGS_VAR] = JSON.stringify(settings);
|
|
23
34
|
afterAll(async () => {
|
|
24
|
-
await reportCoverage(rawDir,
|
|
35
|
+
await reportCoverage(rawDir, REPORT_DIR, includePatterns);
|
|
25
36
|
await fs.rm(rawDir, {
|
|
26
37
|
recursive: true,
|
|
27
38
|
force: true
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preload.js","names":[],"sources":["../../../src/test-utils/subprocess-coverage/preload.ts"],"sourcesContent":["// Turns on coverage for the package's own bins and modules that tests run in child processes.\n// Import it once, from the test preload, in the package's repo.\nimport { afterAll } from \"bun:test\"\nimport fs from \"node:fs/promises\"\nimport os from \"node:os\"\nimport path from \"node:path\"\nimport process from \"node:process\"\n\nimport bun from \"bun\"\n\nimport { SUBPROCESS_COVERAGE_SETTINGS_VAR } from \"#test-utils/subprocess-coverage/env.ts\"\nimport type { CoverageSettings } from \"#test-utils/subprocess-coverage/env.ts\"\nimport { reportCoverage } from \"#test-utils/subprocess-coverage/report.ts\"\n\n// Match this file's extension so the preload is the `.ts` source in this repo and the built `.js` in `dist/`.\nconst CHILD_PRELOAD = path.join(import.meta.dir, `child-preload${path.extname(import.meta.path)}`)\n\nconst hasName = (value: unknown): value is { name: string } =>\n typeof value === \"object\" && value !== null && \"name\" in value && typeof value.name === \"string\"\n\nconst root = process.cwd()\nconst packageJson: unknown = await bun.file(path.join(root, \"package.json\")).json()\nif (!hasName(packageJson)) throw new Error(`subprocess coverage needs a package name in ${root}/package.json`)\n\nconst rawDir = await fs.mkdtemp(path.join(os.tmpdir(), \"subprocess-coverage-\"))\nconst settings: CoverageSettings = { rawDir, root, packageName: packageJson.name }\n\n// Set these on `process.env` so `subprocessCoverageEnv` and shells that inherit `process.env` pass them on.\nprocess.env[\"BUN_OPTIONS\"] = `--preload=${CHILD_PRELOAD}`\nprocess.env[SUBPROCESS_COVERAGE_SETTINGS_VAR] = JSON.stringify(settings)\n\nafterAll(async () => {\n await reportCoverage(rawDir,
|
|
1
|
+
{"version":3,"file":"preload.js","names":[],"sources":["../../../src/test-utils/subprocess-coverage/preload.ts"],"sourcesContent":["// Turns on coverage for the package's own bins and modules that tests run in child processes.\n// Import it once, from the test preload, in the package's repo.\nimport { afterAll } from \"bun:test\"\nimport fs from \"node:fs/promises\"\nimport os from \"node:os\"\nimport path from \"node:path\"\nimport process from \"node:process\"\n\nimport bun from \"bun\"\n\nimport { SUBPROCESS_COVERAGE_SETTINGS_VAR } from \"#test-utils/subprocess-coverage/env.ts\"\nimport type { CoverageSettings } from \"#test-utils/subprocess-coverage/env.ts\"\nimport { reportCoverage } from \"#test-utils/subprocess-coverage/report.ts\"\n\n// Match this file's extension so the preload is the `.ts` source in this repo and the built `.js` in `dist/`.\nconst CHILD_PRELOAD = path.join(import.meta.dir, `child-preload${path.extname(import.meta.path)}`)\n\nconst hasName = (value: unknown): value is { name: string } =>\n typeof value === \"object\" && value !== null && \"name\" in value && typeof value.name === \"string\"\n\nconst isRecord = (value: unknown): value is Record<string, unknown> => typeof value === \"object\" && value !== null\n\nconst root = process.cwd()\nconst packageJson: unknown = await bun.file(path.join(root, \"package.json\")).json()\nif (!hasName(packageJson)) throw new Error(`subprocess coverage needs a package name in ${root}/package.json`)\n\n// Write to a subdir because Bun writes its own `coverage/lcov.info` after this report.\nconst REPORT_DIR = path.join(root, \"coverage/subprocess\")\n\n/** Returns Bun's `coveragePathIgnorePatterns` while its coverage is on, or `undefined` when it's off. */\nconst readBunIgnorePatterns = async () => {\n const bunfigFile = bun.file(path.join(root, \"bunfig.toml\"))\n const bunfig: unknown = (await bunfigFile.exists()) ? bun.TOML.parse(await bunfigFile.text()) : {}\n const test = isRecord(bunfig) && isRecord(bunfig[\"test\"]) ? bunfig[\"test\"] : {}\n\n const isBunCoverageOn = test[\"coverage\"] === true\n if (!isBunCoverageOn) return\n\n const coverageIgnorePatterns = test[\"coveragePathIgnorePatterns\"]\n return [coverageIgnorePatterns].flat().filter((pattern) => typeof pattern === \"string\")\n}\n\n// Report only the files that Bun's coverage ignores, so each file appears in one report.\n// Join each pattern onto `root` because Bun's patterns are root-relative and the report's paths are absolute.\nconst includePatterns = (await readBunIgnorePatterns())?.map((pattern) => path.join(root, pattern))\n\nconst rawDir = await fs.mkdtemp(path.join(os.tmpdir(), \"subprocess-coverage-\"))\nconst settings: CoverageSettings = { rawDir, root, packageName: packageJson.name }\n\n// Set these on `process.env` so `subprocessCoverageEnv` and shells that inherit `process.env` pass them on.\nprocess.env[\"BUN_OPTIONS\"] = `--preload=${CHILD_PRELOAD}`\nprocess.env[SUBPROCESS_COVERAGE_SETTINGS_VAR] = JSON.stringify(settings)\n\nafterAll(async () => {\n await reportCoverage(rawDir, REPORT_DIR, includePatterns)\n await fs.rm(rawDir, { recursive: true, force: true })\n})\n"],"mappings":";;;;;;;;;AAeA,MAAM,gBAAgB,KAAK,KAAK,YAAY,KAAK,gBAAgB,KAAK,QAAQ,YAAY,IAAI,GAAG;AAEjG,MAAM,WAAW,UACf,OAAO,UAAU,YAAY,UAAU,QAAQ,UAAU,SAAS,OAAO,MAAM,SAAS;AAE1F,MAAM,YAAY,UAAqD,OAAO,UAAU,YAA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/subprocess-coverage/report.ts
|
|
8
8
|
const isCoverageMapData = (value) => typeof value === "object" && value !== null;
|
|
9
|
-
/**
|
|
10
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Merges the coverage from every process in `rawDir`, maps it back to the source, and writes a text and lcov report.
|
|
11
|
+
* Reports only the source files that match a glob in `includePatterns`, or every file when it's `undefined`.
|
|
12
|
+
*/
|
|
13
|
+
const reportCoverage = async (rawDir, reportDir, includePatterns) => {
|
|
11
14
|
const rawFiles = await fs.readdir(rawDir);
|
|
12
15
|
if (rawFiles.length === 0) return;
|
|
13
16
|
const rawCoverages = await Promise.all(rawFiles.map(async (rawFile) => bun.file(path.join(rawDir, rawFile)).json()));
|
|
14
17
|
const coverageMap = createCoverageMap({});
|
|
15
18
|
for (const rawCoverage of rawCoverages) if (isCoverageMapData(rawCoverage)) coverageMap.merge(rawCoverage);
|
|
16
19
|
const sourceCoverageMap = await createSourceMapStore().transformCoverage(coverageMap);
|
|
20
|
+
if (includePatterns) {
|
|
21
|
+
const globs = includePatterns.map((pattern) => new bun.Glob(pattern));
|
|
22
|
+
sourceCoverageMap.filter((file) => globs.some((glob) => glob.match(file)));
|
|
23
|
+
}
|
|
24
|
+
if (sourceCoverageMap.files().length === 0) return;
|
|
25
|
+
console.log("\nSubprocess coverage:");
|
|
17
26
|
const context = createContext({
|
|
18
27
|
dir: reportDir,
|
|
19
28
|
coverageMap: sourceCoverageMap
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"report.js","names":[],"sources":["../../../src/test-utils/subprocess-coverage/report.ts"],"sourcesContent":["import fs from \"node:fs/promises\"\nimport path from \"node:path\"\n\nimport { createCoverageMap } from \"@vitest/istanbul-lib-coverage\"\nimport type { CoverageMapData } from \"@vitest/istanbul-lib-coverage\"\nimport { create as createReport, createContext } from \"@vitest/istanbul-lib-report\"\nimport { createSourceMapStore } from \"@vitest/istanbul-lib-source-maps\"\nimport bun from \"bun\"\n\nconst isCoverageMapData = (value: unknown): value is CoverageMapData => typeof value === \"object\" && value !== null\n\n
|
|
1
|
+
{"version":3,"file":"report.js","names":[],"sources":["../../../src/test-utils/subprocess-coverage/report.ts"],"sourcesContent":["import fs from \"node:fs/promises\"\nimport path from \"node:path\"\n\nimport { createCoverageMap } from \"@vitest/istanbul-lib-coverage\"\nimport type { CoverageMapData } from \"@vitest/istanbul-lib-coverage\"\nimport { create as createReport, createContext } from \"@vitest/istanbul-lib-report\"\nimport { createSourceMapStore } from \"@vitest/istanbul-lib-source-maps\"\nimport bun from \"bun\"\n\nconst isCoverageMapData = (value: unknown): value is CoverageMapData => typeof value === \"object\" && value !== null\n\n/**\n * Merges the coverage from every process in `rawDir`, maps it back to the source, and writes a text and lcov report.\n * Reports only the source files that match a glob in `includePatterns`, or every file when it's `undefined`.\n */\nexport const reportCoverage = async (rawDir: string, reportDir: string, includePatterns?: string[]) => {\n const rawFiles = await fs.readdir(rawDir)\n if (rawFiles.length === 0) return\n\n const rawCoverages = await Promise.all(\n rawFiles.map(async (rawFile): Promise<unknown> => bun.file(path.join(rawDir, rawFile)).json()),\n )\n const coverageMap = createCoverageMap({})\n for (const rawCoverage of rawCoverages) if (isCoverageMapData(rawCoverage)) coverageMap.merge(rawCoverage)\n\n const sourceCoverageMap = await createSourceMapStore().transformCoverage(coverageMap)\n if (includePatterns) {\n const globs = includePatterns.map((pattern) => new bun.Glob(pattern))\n sourceCoverageMap.filter((file) => globs.some((glob) => glob.match(file)))\n }\n if (sourceCoverageMap.files().length === 0) return\n\n // Label the table because Bun's own coverage table can print next to it.\n console.log(\"\\nSubprocess coverage:\")\n const context = createContext({ dir: reportDir, coverageMap: sourceCoverageMap })\n createReport(\"text\").execute(context)\n createReport(\"lcovonly\").execute(context)\n}\n"],"mappings":";;;;;;;AASA,MAAM,qBAAqB,UAA6C,OAAO,UAAU,YAAY,UAAU;;;;;AAM/G,MAAa,iBAAiB,OAAO,QAAgB,WAAmB,oBAA+B;CACrG,MAAM,WAAW,MAAM,GAAG,QAAQ,MAAM;CACxC,IAAI,SAAS,WAAW,GAAG;CAE3B,MAAM,eAAe,MAAM,QAAQ,IACjC,SAAS,IAAI,OAAO,YAA8B,IAAI,KAAK,KAAK,KAAK,QAAQ,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAC/F;CACA,MAAM,cAAc,kBAAkB,CAAC,CAAC;CACxC,KAAK,MAAM,eAAe,cAAc,IAAI,kBAAkB,WAAW,GAAG,YAAY,MAAM,WAAW;CAEzG,MAAM,oBAAoB,MAAM,qBAAqB,CAAC,CAAC,kBAAkB,WAAW;CACpF,IAAI,iBAAiB;EACnB,MAAM,QAAQ,gBAAgB,KAAK,YAAY,IAAI,IAAI,KAAK,OAAO,CAAC;EACpE,kBAAkB,QAAQ,SAAS,MAAM,MAAM,SAAS,KAAK,MAAM,IAAI,CAAC,CAAC;CAC3E;CACA,IAAI,kBAAkB,MAAM,CAAC,CAAC,WAAW,GAAG;CAG5C,QAAQ,IAAI,wBAAwB;CACpC,MAAM,UAAU,cAAc;EAAE,KAAK;EAAW,aAAa;CAAkB,CAAC;CAChF,OAAa,MAAM,CAAC,CAAC,QAAQ,OAAO;CACpC,OAAa,UAAU,CAAC,CAAC,QAAQ,OAAO;AAC1C"}
|