Skip to content

Commit 2c6f75b

Browse files
committed
fix: code review and simplification
1 parent fd42d43 commit 2c6f75b

File tree

2 files changed

+18
-24
lines changed

2 files changed

+18
-24
lines changed

packages/runtime/src/tutorial-runner.spec.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,9 @@ describe('TutorialRunner', () => {
6161
const processFactory = vi.fn(() => {
6262
resolve(JSON.stringify(mock._fakeFs, undefined, 2));
6363

64-
return [
65-
new Promise<number>(() => {}),
66-
new ReadableStream<string>({
67-
start(controller) {
68-
controller.close();
69-
},
70-
}),
71-
new WritableStream<string>({
72-
write() {},
73-
}),
74-
] as const;
64+
return {
65+
exit: new Promise<number>(() => {}),
66+
};
7567
});
7668

7769
setProcessFactory(processFactory);

packages/test-utils/src/index.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,12 @@ export type FakeProcessFactory = (
2525
command: string,
2626
args: string[],
2727
options?: SpawnOptions,
28-
) => readonly [exit: Promise<number>, output: ReadableStream<string>, input: WritableStream<string>];
28+
) => { exit: Promise<number>; output?: ReadableStream<string>; input?: WritableStream<string> };
2929

3030
const defaultProcessFactory: FakeProcessFactory = () => {
31-
return [
32-
Promise.resolve(0),
33-
new ReadableStream<string>({
34-
start(controller) {
35-
controller.close();
36-
},
37-
}),
38-
new WritableStream<string>({
39-
write() {},
40-
}),
41-
];
31+
return {
32+
exit: Promise.resolve(0),
33+
};
4234
};
4335

4436
let fakeProcessFactory = defaultProcessFactory;
@@ -113,7 +105,17 @@ vi.mock('@webcontainer/api', () => {
113105
args: string[],
114106
options?: SpawnOptions,
115107
) {
116-
const [exit, output, input] = fakeProcessFactory(command, args, options);
108+
const {
109+
exit,
110+
output = new ReadableStream<string>({
111+
start(controller) {
112+
controller.close();
113+
},
114+
}),
115+
input = new WritableStream<string>({
116+
write() {},
117+
}),
118+
} = fakeProcessFactory(command, args, options);
117119
const fakeProcess: FakeProcess = {
118120
pid: this._fakeProcesses.length,
119121
command,

0 commit comments

Comments
 (0)