Skip to content

Commit e97fe67

Browse files
committed
test: failed pty tests logs
1 parent 532c50a commit e97fe67

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

tests/specs/cli.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ export default testSuite(({ describe }, node: NodeApis) => {
326326

327327
onTestFail(() => {
328328
p.kill();
329+
console.log(p.logs);
329330
});
330331

331332
expect(await p.output).toMatch(/EXIT_CODE:\s+130/);
@@ -350,6 +351,7 @@ export default testSuite(({ describe }, node: NodeApis) => {
350351

351352
onTestFail(() => {
352353
p.kill();
354+
console.log(p.logs);
353355
});
354356

355357
expectMatchInOrder(await p.output, [
@@ -380,6 +382,7 @@ export default testSuite(({ describe }, node: NodeApis) => {
380382

381383
onTestFail(() => {
382384
p.kill();
385+
console.log(p.logs);
383386
});
384387

385388
expect(await p.output).toMatch(/EXIT_CODE:\s+130/);

tests/utils/pty-shell/index.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,11 @@ type API = {
3131
export const ptyShell = (
3232
callback: (api: API) => Promise<void>,
3333
options?: NodeOptions<'utf8'>,
34-
debugTitle?: string,
3534
) => {
3635
const timeStart = Date.now();
36+
const logs: string[] = [];
3737
const log = (...messages: any[]) => {
38-
if (debugTitle) {
39-
console.log(`[${debugTitle}][${Date.now() - timeStart}ms]`, ...messages);
40-
}
38+
logs.push(`[${Date.now() - timeStart}ms] ${messages.map(message => JSON.stringify(message)).join(' ')}`);
4139
};
4240

4341
const childProcess = execaNode(
@@ -58,7 +56,7 @@ export const ptyShell = (
5856
deferred.resolve(line);
5957
lineMap.delete(pattern);
6058

61-
log('line', JSON.stringify(line));
59+
log('line', line);
6260
}
6361
}
6462
};
@@ -104,17 +102,17 @@ export const ptyShell = (
104102
return promptDeferred.promise;
105103
},
106104
waitForLine: (pattern) => {
107-
log('waitForLine', pattern);
105+
log('waitForLine', pattern.toString());
108106
const deferred = new Deferred<string>();
109107
lineMap.set(pattern, deferred);
110108
return deferred.promise;
111109
},
112110
type: (text) => {
113-
log('type', JSON.stringify(text));
111+
log('type', text);
114112
childProcess.send(`${text}\r`);
115113
},
116114
press: (key) => {
117-
log('press', JSON.stringify(key));
115+
log('press', key);
118116
childProcess.send(key);
119117
},
120118
});
@@ -126,5 +124,8 @@ export const ptyShell = (
126124
return stripAnsi(buffer);
127125
})();
128126

129-
return Object.assign(childProcess, { output });
127+
return Object.assign(childProcess, {
128+
output,
129+
logs,
130+
});
130131
};

0 commit comments

Comments
 (0)