Skip to content

Commit aef8c09

Browse files
committed
Change CLI snapshot format and allow options
1 parent 14c73d3 commit aef8c09

17 files changed

+383
-186
lines changed

packages/cli/test/snapshots.test.ts

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import fs from "fs";
21
import { access, readFile, writeFile } from "fs/promises";
32
import { execSync, type SpawnSyncReturns } from "child_process";
43
import assert from "node:assert";
@@ -7,6 +6,27 @@ import { after, describe, test } from "node:test";
76
const attw = `node ${new URL("../../dist/index.js", import.meta.url).pathname}`;
87
const updateSnapshots = process.env.UPDATE_SNAPSHOTS;
98

9+
const tests = [
10+
["@apollo__client-3.7.16.tgz"],
11+
12+
13+
14+
15+
16+
17+
["[email protected]", "-f table"],
18+
19+
20+
["[email protected]", "-f ascii"],
21+
22+
23+
24+
25+
26+
];
27+
28+
const defaultOpts = "-f table-flipped";
29+
1030
describe("snapshots", async () => {
1131
const snapshotsWritten: URL[] = [];
1232

@@ -22,16 +42,17 @@ describe("snapshots", async () => {
2242
}
2343
});
2444

25-
for (const fixture of fs.readdirSync(new URL("../../../core/test/fixtures", import.meta.url))) {
26-
if (fixture === ".DS_Store") {
27-
continue;
28-
}
45+
for (const [tarball, options] of tests) {
46+
const fixture = tarball + (options ? ` ${options}` : "");
2947
test(fixture, async () => {
30-
const tarballPath = new URL(`../../../core/test/fixtures/${fixture}`, import.meta.url).pathname;
48+
const tarballPath = new URL(`../../../core/test/fixtures/${tarball}`, import.meta.url).pathname;
3149
let stdout;
3250
let exitCode = 0;
3351
try {
34-
stdout = execSync(`${attw} ${tarballPath}`, { encoding: "utf8", env: { ...process.env, FORCE_COLOR: "0" } });
52+
stdout = execSync(`${attw} ${tarballPath} ${options ?? defaultOpts}`, {
53+
encoding: "utf8",
54+
env: { ...process.env, FORCE_COLOR: "0" },
55+
});
3556
} catch (error) {
3657
stdout = (error as SpawnSyncReturns<string>).stdout;
3758
exitCode = (error as SpawnSyncReturns<string>).status ?? 1;
@@ -42,7 +63,7 @@ describe("snapshots", async () => {
4263
`# ${fixture}`,
4364
"",
4465
"```",
45-
`$ attw ${fixture}`,
66+
`$ attw ${tarball} ${options ?? defaultOpts}`,
4667
"",
4768
stdout,
4869
"",

packages/cli/test/snapshots/@apollo__client-3.7.16.tgz.md

Lines changed: 110 additions & 14 deletions
Large diffs are not rendered by default.

packages/cli/test/snapshots/@[email protected]

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,17 @@ $ attw @[email protected]
1111
🥴 Import found in a type declaration file failed to resolve. Either this indicates that runtime resolution errors will occur, or (more likely) the types misrepresent the contents of the JavaScript files. https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/InternalResolutionError.md
1212
1313
14-
┌────────────────────┬───────────────────────────────────┬───────────────────────────────────┬───────────────────────────────────┐
15-
│ │ "@ice/app" │ "@ice/app/types" │ "@ice/app/analyze" │
16-
├────────────────────┼───────────────────────────────────┼───────────────────────────────────┼───────────────────────────────────┤
17-
│ node10 │ 🟢 │ 🟢 │ 💀 Resolution failed │
18-
├────────────────────┼───────────────────────────────────┼───────────────────────────────────┼───────────────────────────────────┤
19-
│ node16 (from CJS) │ ⚠️ ESM (dynamic import only) │ ⚠️ ESM (dynamic import only) │ ⚠️ ESM (dynamic import only) │
20-
│ │ 🥴 Internal resolution error │ 🥴 Internal resolution error │ │
21-
├────────────────────┼───────────────────────────────────┼───────────────────────────────────┼───────────────────────────────────┤
22-
│ node16 (from ESM) │ 🥴 Internal resolution error │ 🥴 Internal resolution error │ 🟢 (ESM) │
23-
├────────────────────┼───────────────────────────────────┼───────────────────────────────────┼───────────────────────────────────┤
24-
│ bundler │ 🟢 │ 🟢 │ 🟢 │
25-
└────────────────────┴───────────────────────────────────┴───────────────────────────────────┴───────────────────────────────────┘
14+
┌────────────────────┬─────────────────────────┬─────────────────────────┬─────────────────────────┬─────────────────────────┐
15+
│ │ node10 │ node16 (from CJS) │ node16 (from ESM) │ bundler │
16+
├────────────────────┼─────────────────────────┼─────────────────────────┼─────────────────────────┼─────────────────────────┤
17+
│ "@ice/app" │ 🟢 │ ⚠️ ESM (dynamic import… │ 🥴 Internal resolution… │ 🟢 │
18+
│ │ │ 🥴 Internal resolution… │ │ │
19+
├────────────────────┼─────────────────────────┼─────────────────────────┼─────────────────────────┼─────────────────────────┤
20+
│ "@ice/app/types" │ 🟢 │ ⚠️ ESM (dynamic import… │ 🥴 Internal resolution… │ 🟢 │
21+
│ │ │ 🥴 Internal resolution… │ │ │
22+
├────────────────────┼─────────────────────────┼─────────────────────────┼─────────────────────────┼─────────────────────────┤
23+
│ "@ice/app/analyze" │ 💀 Resolution failed │ ⚠️ ESM (dynamic import… │ 🟢 (ESM) │ 🟢 │
24+
└────────────────────┴─────────────────────────┴─────────────────────────┴─────────────────────────┴─────────────────────────┘
2625
2726
2827
```

packages/cli/test/snapshots/@[email protected]

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,21 @@ $ attw @[email protected]
99
🥴 Import found in a type declaration file failed to resolve. Either this indicates that runtime resolution errors will occur, or (more likely) the types misrepresent the contents of the JavaScript files. https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/InternalResolutionError.md
1010
1111
12-
┌────────────────────┬───────────────────────────────────┬───────────────────────────────────┬───────────────────────────────────┬───────────────────────────────────┬───────────────────────────────────┐
13-
│ │ "@reduxjs/toolkit/package.json" │ "@reduxjs/toolkit" │ "@reduxjs/toolkit/react" │ "@reduxjs/toolkit/query" │ "@reduxjs/toolkit/query/react" │
14-
├────────────────────┼───────────────────────────────────┼───────────────────────────────────┼───────────────────────────────────┼───────────────────────────────────┼───────────────────────────────────┤
15-
│ node10 │ 🟢 (JSON) │ 🟢 │ 🟢 │ 🟢 │ 🟢 │
16-
├────────────────────┼───────────────────────────────────┼───────────────────────────────────┼───────────────────────────────────┼───────────────────────────────────┼───────────────────────────────────┤
17-
│ node16 (from CJS) │ 🟢 (JSON) │ 🟢 (CJS) │ 🥴 Internal resolution error │ 🟢 (CJS) │ 🥴 Internal resolution error │
18-
├────────────────────┼───────────────────────────────────┼───────────────────────────────────┼───────────────────────────────────┼───────────────────────────────────┼───────────────────────────────────┤
19-
│ node16 (from ESM) │ 🟢 (JSON) │ 🎭 Masquerading as CJS │ 🎭 Masquerading as CJS │ 🎭 Masquerading as CJS │ 🎭 Masquerading as CJS │
20-
│ │ │ │ 🥴 Internal resolution error │ │ 🥴 Internal resolution error │
21-
├────────────────────┼───────────────────────────────────┼───────────────────────────────────┼───────────────────────────────────┼───────────────────────────────────┼───────────────────────────────────┤
22-
│ bundler │ 🟢 (JSON) │ 🟢 │ 🥴 Internal resolution error │ 🟢 │ 🥴 Internal resolution error │
23-
└────────────────────┴───────────────────────────────────┴───────────────────────────────────┴───────────────────────────────────┴───────────────────────────────────┴───────────────────────────────────┘
12+
┌────────────────────┬─────────────────────────┬─────────────────────────┬─────────────────────────┬─────────────────────────┐
13+
│ │ node10 │ node16 (from CJS) │ node16 (from ESM) │ bundler │
14+
├────────────────────┼─────────────────────────┼─────────────────────────┼─────────────────────────┼─────────────────────────┤
15+
│ "@reduxjs/toolkit… │ 🟢 (JSON) │ 🟢 (JSON) │ 🟢 (JSON) │ 🟢 (JSON) │
16+
├────────────────────┼─────────────────────────┼─────────────────────────┼─────────────────────────┼─────────────────────────┤
17+
│ "@reduxjs/toolkit" │ 🟢 │ 🟢 (CJS) │ 🎭 Masquerading as CJS │ 🟢 │
18+
├────────────────────┼─────────────────────────┼─────────────────────────┼─────────────────────────┼─────────────────────────┤
19+
│ "@reduxjs/toolkit… │ 🟢 │ 🥴 Internal resolution… │ 🎭 Masquerading as CJS │ 🥴 Internal resolution… │
20+
│ │ │ │ 🥴 Internal resolution… │ │
21+
├────────────────────┼─────────────────────────┼─────────────────────────┼─────────────────────────┼─────────────────────────┤
22+
│ "@reduxjs/toolkit… │ 🟢 │ 🟢 (CJS) │ 🎭 Masquerading as CJS │ 🟢 │
23+
├────────────────────┼─────────────────────────┼─────────────────────────┼─────────────────────────┼─────────────────────────┤
24+
│ "@reduxjs/toolkit… │ 🟢 │ 🥴 Internal resolution… │ 🎭 Masquerading as CJS │ 🥴 Internal resolution… │
25+
│ │ │ │ 🥴 Internal resolution… │ │
26+
└────────────────────┴─────────────────────────┴─────────────────────────┴─────────────────────────┴─────────────────────────┘
2427
2528
2629
```

0 commit comments

Comments
 (0)