tangled
alpha
login
or
join now
tylur.dev
/
prototypey
prototypey.org - atproto lexicon typescript toolkit - mirror https://github.com/tylersayshi/prototypey
1
fork
atom
overview
issues
pulls
pipelines
test util for runCLI
Tyler
3 months ago
8cf91a48
513fc05d
+40
-138
6 changed files
expand all
collapse all
unified
split
packages
cli
tests
integration
cli.test.ts
error-handling.test.ts
filesystem.test.ts
workflow.test.ts
performance
large-schema-set.test.ts
test-utils.ts
+1
-27
packages/cli/tests/integration/cli.test.ts
···
1
import { expect, test, describe } from "vitest";
2
-
import { spawn } from "node:child_process";
3
-
import { join, dirname } from "node:path";
4
-
import { fileURLToPath } from "node:url";
5
6
describe("CLI Integration", () => {
7
test("shows error when called without arguments", async () => {
···
51
);
52
});
53
});
54
-
55
-
function runCLI(
56
-
args: string[] = [],
57
-
): Promise<{ stdout: string; stderr: string; code: number }> {
58
-
return new Promise((resolve) => {
59
-
const cliPath = join(dirname(fileURLToPath(import.meta.url)), "../../lib/index.js");
60
-
const child = spawn("node", [cliPath, ...args]);
61
-
62
-
let stdout = "";
63
-
let stderr = "";
64
-
65
-
child.stdout.on("data", (data) => {
66
-
stdout += data.toString();
67
-
});
68
-
69
-
child.stderr.on("data", (data) => {
70
-
stderr += data.toString();
71
-
});
72
-
73
-
child.on("close", (code) => {
74
-
resolve({ stdout, stderr, code: code ?? 0 });
75
-
});
76
-
});
77
-
}
···
1
import { expect, test, describe } from "vitest";
2
+
import { runCLI } from "../test-utils.js";
0
0
3
4
describe("CLI Integration", () => {
5
test("shows error when called without arguments", async () => {
···
49
);
50
});
51
});
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
+2
-27
packages/cli/tests/integration/error-handling.test.ts
···
1
import { expect, test, describe, beforeEach, afterEach } from "vitest";
2
import { mkdir, writeFile, rm } from "node:fs/promises";
3
-
import { join, dirname } from "node:path";
4
import { tmpdir } from "node:os";
5
-
import { spawn } from "node:child_process";
6
-
import { fileURLToPath } from "node:url";
7
8
describe("CLI Error Handling", () => {
9
let testDir: string;
···
154
expect(stderr).toContain("Error generating inferred types");
155
});
156
});
157
-
158
-
function runCLI(
159
-
args: string[],
160
-
): Promise<{ stdout: string; stderr: string; code: number }> {
161
-
return new Promise((resolve) => {
162
-
const cliPath = join(dirname(fileURLToPath(import.meta.url)), "../../lib/index.js");
163
-
const child = spawn("node", [cliPath, ...args]);
164
-
165
-
let stdout = "";
166
-
let stderr = "";
167
-
168
-
child.stdout.on("data", (data) => {
169
-
stdout += data.toString();
170
-
});
171
-
172
-
child.stderr.on("data", (data) => {
173
-
stderr += data.toString();
174
-
});
175
-
176
-
child.on("close", (code) => {
177
-
resolve({ stdout, stderr, code: code ?? 0 });
178
-
});
179
-
});
180
-
}
···
1
import { expect, test, describe, beforeEach, afterEach } from "vitest";
2
import { mkdir, writeFile, rm } from "node:fs/promises";
3
+
import { join } from "node:path";
4
import { tmpdir } from "node:os";
5
+
import { runCLI } from "../test-utils.js";
0
6
7
describe("CLI Error Handling", () => {
8
let testDir: string;
···
153
expect(stderr).toContain("Error generating inferred types");
154
});
155
});
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
+2
-27
packages/cli/tests/integration/filesystem.test.ts
···
7
access,
8
constants,
9
} from "node:fs/promises";
10
-
import { join, dirname } from "node:path";
11
import { tmpdir } from "node:os";
12
-
import { spawn } from "node:child_process";
13
-
import { fileURLToPath } from "node:url";
14
15
describe("CLI File System Handling", () => {
16
let testDir: string;
···
185
expect([0, 1]).toContain(code);
186
});
187
});
188
-
189
-
function runCLI(
190
-
args: string[],
191
-
): Promise<{ stdout: string; stderr: string; code: number }> {
192
-
return new Promise((resolve) => {
193
-
const cliPath = join(dirname(fileURLToPath(import.meta.url)), "../../lib/index.js");
194
-
const child = spawn("node", [cliPath, ...args]);
195
-
196
-
let stdout = "";
197
-
let stderr = "";
198
-
199
-
child.stdout.on("data", (data) => {
200
-
stdout += data.toString();
201
-
});
202
-
203
-
child.stderr.on("data", (data) => {
204
-
stderr += data.toString();
205
-
});
206
-
207
-
child.on("close", (code) => {
208
-
resolve({ stdout, stderr, code: code ?? 0 });
209
-
});
210
-
});
211
-
}
···
7
access,
8
constants,
9
} from "node:fs/promises";
10
+
import { join } from "node:path";
11
import { tmpdir } from "node:os";
12
+
import { runCLI } from "../test-utils.js";
0
13
14
describe("CLI File System Handling", () => {
15
let testDir: string;
···
184
expect([0, 1]).toContain(code);
185
});
186
});
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
+2
-30
packages/cli/tests/integration/workflow.test.ts
···
1
import { expect, test, describe, beforeEach, afterEach } from "vitest";
2
import { mkdir, writeFile, rm, readFile } from "node:fs/promises";
3
-
import { join, dirname } from "node:path";
4
import { tmpdir } from "node:os";
5
-
import { spawn } from "node:child_process";
6
-
import { fileURLToPath } from "node:url";
7
8
describe("CLI End-to-End Workflow", () => {
9
let testDir: string;
···
190
);
191
});
192
});
193
-
194
-
function runCLI(
195
-
args: string[],
196
-
): Promise<{ stdout: string; stderr: string; code: number }> {
197
-
return new Promise((resolve) => {
198
-
const cliPath = join(dirname(fileURLToPath(import.meta.url)), "../../lib/index.js");
199
-
const child = spawn("node", [cliPath, ...args], {
200
-
cwd: process.cwd(),
201
-
env: process.env,
202
-
});
203
-
204
-
let stdout = "";
205
-
let stderr = "";
206
-
207
-
child.stdout.on("data", (data) => {
208
-
stdout += data.toString();
209
-
});
210
-
211
-
child.stderr.on("data", (data) => {
212
-
stderr += data.toString();
213
-
});
214
-
215
-
child.on("close", (code) => {
216
-
resolve({ stdout, stderr, code: code ?? 0 });
217
-
});
218
-
});
219
-
}
···
1
import { expect, test, describe, beforeEach, afterEach } from "vitest";
2
import { mkdir, writeFile, rm, readFile } from "node:fs/promises";
3
+
import { join } from "node:path";
4
import { tmpdir } from "node:os";
5
+
import { runCLI } from "../test-utils.js";
0
6
7
describe("CLI End-to-End Workflow", () => {
8
let testDir: string;
···
189
);
190
});
191
});
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
+2
-27
packages/cli/tests/performance/large-schema-set.test.ts
···
1
import { expect, test, describe, beforeEach, afterEach } from "vitest";
2
import { mkdir, writeFile, rm } from "node:fs/promises";
3
-
import { join, dirname } from "node:path";
4
import { tmpdir } from "node:os";
5
-
import { spawn } from "node:child_process";
6
-
import { fileURLToPath } from "node:url";
7
8
describe("CLI Performance", () => {
9
let testDir: string;
···
209
);
210
});
211
});
212
-
213
-
function runCLI(
214
-
args: string[],
215
-
): Promise<{ stdout: string; stderr: string; code: number }> {
216
-
return new Promise((resolve) => {
217
-
const cliPath = join(dirname(fileURLToPath(import.meta.url)), "../../lib/index.js");
218
-
const child = spawn("node", [cliPath, ...args]);
219
-
220
-
let stdout = "";
221
-
let stderr = "";
222
-
223
-
child.stdout.on("data", (data) => {
224
-
stdout += data.toString();
225
-
});
226
-
227
-
child.stderr.on("data", (data) => {
228
-
stderr += data.toString();
229
-
});
230
-
231
-
child.on("close", (code) => {
232
-
resolve({ stdout, stderr, code: code ?? 0 });
233
-
});
234
-
});
235
-
}
···
1
import { expect, test, describe, beforeEach, afterEach } from "vitest";
2
import { mkdir, writeFile, rm } from "node:fs/promises";
3
+
import { join } from "node:path";
4
import { tmpdir } from "node:os";
5
+
import { runCLI } from "../test-utils.js";
0
6
7
describe("CLI Performance", () => {
8
let testDir: string;
···
208
);
209
});
210
});
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
+31
packages/cli/tests/test-utils.ts
···
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
···
1
+
import { spawn } from "node:child_process";
2
+
import { dirname, join } from "node:path";
3
+
import { fileURLToPath } from "node:url";
4
+
5
+
export function runCLI(
6
+
args: string[] = [],
7
+
options?: { cwd?: string; env?: NodeJS.ProcessEnv },
8
+
): Promise<{ stdout: string; stderr: string; code: number }> {
9
+
return new Promise((resolve) => {
10
+
const cliPath = join(dirname(fileURLToPath(import.meta.url)), "../lib/index.js");
11
+
const child = spawn("node", [cliPath, ...args], {
12
+
cwd: options?.cwd ?? process.cwd(),
13
+
env: options?.env ?? process.env,
14
+
});
15
+
16
+
let stdout = "";
17
+
let stderr = "";
18
+
19
+
child.stdout.on("data", (data) => {
20
+
stdout += data.toString();
21
+
});
22
+
23
+
child.stderr.on("data", (data) => {
24
+
stderr += data.toString();
25
+
});
26
+
27
+
child.on("close", (code) => {
28
+
resolve({ stdout, stderr, code: code ?? 0 });
29
+
});
30
+
});
31
+
}