@specific.dev/spectest 0.119.5 → 0.120.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/src/next.ts DELETED
@@ -1,74 +0,0 @@
1
- import { promises as fs } from "node:fs";
2
- import path from "node:path";
3
-
4
- /** Keep each traced script's map alongside it in standalone output. Turbopack
5
- * versions that do not apply outputFileTracingIncludes still emit these traces
6
- * before runAfterProductionCompile. No source files or generated code change. */
7
- async function includeTracedMaps(distDir: string): Promise<void> {
8
- async function walk(dir: string): Promise<void> {
9
- for (const entry of await fs.readdir(dir, { withFileTypes: true })) {
10
- const file = path.join(dir, entry.name);
11
- if (entry.isDirectory() && entry.name !== "cache" && entry.name !== "standalone") await walk(file);
12
- else if (entry.isFile() && entry.name.endsWith(".nft.json")) {
13
- const trace = JSON.parse(await fs.readFile(file, "utf8"));
14
- if (!Array.isArray(trace.files)) throw new Error(`Invalid Next trace: ${file}`);
15
- const scripts = [entry.name.slice(0, -".nft.json".length), ...trace.files];
16
- const maps: string[] = [];
17
- for (const script of scripts) {
18
- if (typeof script !== "string" || !script.endsWith(".js")) continue;
19
- const map = script + ".map";
20
- try { if ((await fs.stat(path.resolve(dir, map))).isFile()) maps.push(map); }
21
- catch (e) { if ((e as NodeJS.ErrnoException).code !== "ENOENT") throw e; }
22
- }
23
- trace.files = [...new Set([...trace.files, ...maps])];
24
- await fs.writeFile(file, JSON.stringify(trace));
25
- }
26
- }
27
- }
28
- await walk(distDir);
29
- }
30
-
31
- /** Build-time companion for coverage.next(). Import this lightweight module in
32
- * next.config; it does not load the Spectest harness or require Next at runtime.
33
- * Apply only in the test build if production should not expose source maps. */
34
- export function withCoverage<T extends object>(config: T): T {
35
- const c = config as Record<string, any>;
36
- const distDir = c.distDir ?? ".next";
37
- const includes = c.outputFileTracingIncludes ?? {};
38
- return {
39
- ...config,
40
- productionBrowserSourceMaps: true,
41
- turbopack: c.turbopack ?? {},
42
- webpack(webpackConfig: any, context: any) {
43
- const configured = c.webpack ? c.webpack(webpackConfig, context) : webpackConfig;
44
- configured.plugins ??= [];
45
- configured.plugins.push({
46
- apply(compiler: any) {
47
- compiler.hooks.compilation.tap("SpectestCoverage", (compilation: any) => {
48
- compiler.webpack.NormalModule.getCompilationHooks(compilation).loader.tap(
49
- "SpectestCoverage", (loader: any, module: any) => {
50
- // Keep dependencies identifiable as dependencies. Chaining a
51
- // package's published maps can replace node_modules provenance
52
- // with ambiguous paths such as ../../src/client/router.ts.
53
- if (/[\\/]node_modules[\\/]/.test(module.resource ?? "")) loader.sourceMap = false;
54
- },
55
- );
56
- });
57
- },
58
- });
59
- return configured;
60
- },
61
- experimental: { ...c.experimental, serverSourceMaps: true },
62
- compiler: {
63
- ...c.compiler,
64
- async runAfterProductionCompile(metadata: { projectDir: string; distDir: string }) {
65
- await c.compiler?.runAfterProductionCompile?.(metadata);
66
- await includeTracedMaps(metadata.distDir);
67
- },
68
- },
69
- outputFileTracingIncludes: {
70
- ...includes,
71
- "/**": [...(includes["/**"] ?? []), `./${distDir}/server/**/*.map`],
72
- },
73
- };
74
- }