aboutsummaryrefslogtreecommitdiff
path: root/packages/upgrade/test/utils.js
blob: 64850a7908170efdaf24cf67a6cd03ee179265ad (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { before, beforeEach } from 'node:test';
import stripAnsi from 'strip-ansi';
import { setStdout } from '../dist/index.js';

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));
		},
	};
}