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