2024-01-12 02:53:00 -05:00
|
|
|
import { before, beforeEach } from 'node:test';
|
2023-11-27 18:00:59 -05:00
|
|
|
import stripAnsi from 'strip-ansi';
|
2024-02-22 08:58:10 -05:00
|
|
|
import { setStdout } from '../dist/index.js';
|
2023-11-27 18:00:59 -05:00
|
|
|
|
|
|
|
export function setup() {
|
|
|
|
const ctx = { messages: [] };
|
|
|
|
before(() => {
|
|
|
|
setStdout(
|
|
|
|
Object.assign({}, process.stdout, {
|
|
|
|
write(buf) {
|
|
|
|
ctx.messages.push(stripAnsi(String(buf)).trim());
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
beforeEach(() => {
|
|
|
|
ctx.messages = [];
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
messages() {
|
|
|
|
return ctx.messages;
|
|
|
|
},
|
|
|
|
length() {
|
|
|
|
return ctx.messages.length;
|
|
|
|
},
|
|
|
|
hasMessage(content) {
|
|
|
|
return !!ctx.messages.find((msg) => msg.includes(content));
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|