2024-01-12 15:53:00 +08:00
|
|
|
import { before, beforeEach } from 'node:test';
|
2024-10-04 16:21:03 +07:00
|
|
|
import { stripVTControlCharacters } from 'node:util';
|
2024-02-22 13:58:10 +00:00
|
|
|
import { setStdout } from '../dist/index.js';
|
2023-11-27 17:00:59 -06:00
|
|
|
|
|
|
|
export function setup() {
|
|
|
|
const ctx = { messages: [] };
|
|
|
|
before(() => {
|
|
|
|
setStdout(
|
|
|
|
Object.assign({}, process.stdout, {
|
|
|
|
write(buf) {
|
2024-10-04 16:21:03 +07:00
|
|
|
ctx.messages.push(stripVTControlCharacters(String(buf)).trim());
|
2023-11-27 17:00:59 -06:00
|
|
|
return true;
|
|
|
|
},
|
2024-08-08 05:12:50 -05:00
|
|
|
}),
|
2023-11-27 17:00:59 -06:00
|
|
|
);
|
|
|
|
});
|
|
|
|
beforeEach(() => {
|
|
|
|
ctx.messages = [];
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
messages() {
|
|
|
|
return ctx.messages;
|
|
|
|
},
|
|
|
|
length() {
|
|
|
|
return ctx.messages.length;
|
|
|
|
},
|
|
|
|
hasMessage(content) {
|
|
|
|
return !!ctx.messages.find((msg) => msg.includes(content));
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|