Skip to content

Commit 9e7e2f6

Browse files
committed
chore: update
1 parent ef64644 commit 9e7e2f6

File tree

2 files changed

+33
-12
lines changed

2 files changed

+33
-12
lines changed

tests/integration/cli/build-watch/build.test.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import { spawn } from 'node:child_process';
21
import path from 'node:path';
32
import { stripVTControlCharacters as stripAnsi } from 'node:util';
43
import { describe, expect, onTestFinished, test } from '@rstest/core';
54
import fse from 'fs-extra';
65
import {
6+
expectBuildEnd,
77
expectFile,
88
expectFileWithContent,
9-
rslibBinPath,
109
runCli,
1110
} from 'test-helper';
1211

@@ -90,6 +89,10 @@ export default defineConfig({
9089
index: ['./test-temp-src/**'],
9190
},
9291
},
92+
performance: {
93+
buildCache: false,
94+
printFileSize: false,
95+
},
9396
});
9497
`,
9598
);
@@ -101,20 +104,17 @@ export default defineConfig({
101104
const distFooFile = path.join(__dirname, 'dist/esm/foo.js');
102105
const distFoo2File = path.join(__dirname, 'dist/esm/foo2.js');
103106

104-
const child = spawn(
105-
'node',
106-
[rslibBinPath, 'build', '--watch', '-c', tempConfigFile],
107-
{
108-
cwd: __dirname,
109-
stdio: 'pipe',
110-
shell: true,
111-
},
112-
);
107+
const { child } = runCli(`build --watch -c ${tempConfigFile}`, {
108+
cwd: __dirname,
109+
});
113110
await expectFileWithContent(distIndexFile, 'index');
114111

115112
fse.outputFileSync(srcFooFile, `export const foo = 'foo';`);
116-
fse.outputFileSync(srcFoo2File, `export const foo2 = 'foo2';`);
113+
await expectBuildEnd(child);
117114
await expectFileWithContent(distFooFile, `'foo'`);
115+
116+
fse.outputFileSync(srcFoo2File, `export const foo2 = 'foo2';`);
117+
await expectBuildEnd(child);
118118
await expectFileWithContent(distFoo2File, 'foo2');
119119

120120
const content1 = await fse.readFile(distFooFile, 'utf-8');
@@ -136,6 +136,7 @@ export default defineConfig({
136136

137137
// change
138138
fse.outputFileSync(srcFooFile, `export const foo1 = 'foo1';`);
139+
await expectBuildEnd(child);
139140
await expectFileWithContent(distFooFile, 'foo1');
140141
const content3 = await fse.readFile(distFooFile, 'utf-8');
141142
expect(content3!).toMatchInlineSnapshot(`

tests/scripts/helper.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import type { ChildProcess } from 'node:child_process';
12
import fs from 'node:fs';
23
import { platform } from 'node:os';
34
import { join } from 'node:path';
5+
import { stripVTControlCharacters as stripAnsi } from 'node:util';
46
import { expect } from '@playwright/test';
57
import fse from 'fs-extra';
68
import { convertPathToPattern, type GlobOptions, glob } from 'tinyglobby';
@@ -100,3 +102,21 @@ export const expectFileWithContent = (
100102
return false;
101103
}
102104
}).toBeTruthy();
105+
106+
/**
107+
* Expect log output from child process
108+
*/
109+
export const expectLog = (child: ChildProcess, log: string) =>
110+
new Promise<void>((resolve) => {
111+
const listener = (chunk: Buffer) => {
112+
console.log('chunk: ', chunk);
113+
if (stripAnsi(chunk.toString()).includes(log)) {
114+
resolve();
115+
}
116+
};
117+
child.stdout?.on('data', listener);
118+
child.stderr?.on('data', listener);
119+
});
120+
121+
export const expectBuildEnd = (child: ChildProcess) =>
122+
expectLog(child, 'built in');

0 commit comments

Comments
 (0)