Skip to content

Commit 9f9fa77

Browse files
authored
test: stabilize mf-dev tests (#597)
1 parent bf897f4 commit 9f9fa77

File tree

4 files changed

+29
-10
lines changed

4 files changed

+29
-10
lines changed

tests/integration/cli/mf-dev/dev.test.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@ import fse, { existsSync } from 'fs-extra';
55
import { awaitFileExists } from 'test-helper';
66
import { expect, test } from 'vitest';
77

8-
const distFolder = join(__dirname, 'dist');
9-
108
describe('mf-dev', () => {
119
test('mf-dev --lib', async () => {
1210
const fixturePath = join(__dirname);
11+
const distFolder = join(__dirname, 'dist-mf0');
1312
fse.removeSync(distFolder);
14-
const distPath = join(distFolder, 'mf0', 'index.js');
13+
const distPath = join(distFolder, 'index.js');
1514

1615
const childProcess = exec('npx rslib mf-dev --lib mf0', {
1716
cwd: fixturePath,
@@ -25,9 +24,12 @@ describe('mf-dev', () => {
2524

2625
test('mf-dev --lib multiple', async () => {
2726
const fixturePath = join(__dirname);
28-
fse.removeSync(distFolder);
29-
const distPath1 = join(distFolder, 'mf1', 'index.js');
30-
const distPath2 = join(distFolder, 'mf2', 'index.js');
27+
const distFolder1 = join(__dirname, 'dist-mf1');
28+
const distFolder2 = join(__dirname, 'dist-mf2');
29+
fse.removeSync(distFolder1);
30+
fse.removeSync(distFolder2);
31+
const distPath1 = join(distFolder1, 'index.js');
32+
const distPath2 = join(distFolder2, 'index.js');
3133

3234
const childProcess = exec('npx rslib mf-dev --lib mf1 --lib mf2', {
3335
cwd: fixturePath,

tests/integration/cli/mf-dev/rslib.config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ export default defineConfig({
77
format: 'mf',
88
output: {
99
distPath: {
10-
root: 'dist/mf0',
10+
root: 'dist-mf0',
1111
},
1212
},
1313
},
1414
{
1515
format: 'mf',
1616
output: {
1717
distPath: {
18-
root: 'dist/mf1',
18+
root: 'dist-mf1',
1919
},
2020
},
2121
},
@@ -24,7 +24,7 @@ export default defineConfig({
2424
format: 'mf',
2525
output: {
2626
distPath: {
27-
root: 'dist/mf2',
27+
root: 'dist-mf2',
2828
},
2929
},
3030
},

tests/integration/server/index.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ describe('server config', async () => {
2020
const fixturePath = join(__dirname, 'mf-dev');
2121
const distPath = join(fixturePath, 'dist');
2222
const rsbuildConfigFile = join(distPath, '.rsbuild/rsbuild.config.mjs');
23+
const doneFile = join(distPath, 'done.txt');
24+
2325
fse.removeSync(distPath);
2426

2527
const childProcess = exec('npx rslib mf-dev', {
@@ -30,7 +32,7 @@ describe('server config', async () => {
3032
},
3133
});
3234

33-
await awaitFileExists(rsbuildConfigFile);
35+
await awaitFileExists(doneFile);
3436

3537
const rsbuildConfigContent = await fse.readFile(rsbuildConfigFile, 'utf-8');
3638
expect(rsbuildConfigContent).toContain('open: true');

tests/integration/server/mf-dev/rslib.config.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
1+
import fs from 'node:fs';
2+
import { join } from 'node:path';
13
import { pluginModuleFederation } from '@module-federation/rsbuild-plugin';
4+
import type { RsbuildPlugin } from '@rsbuild/core';
25
import { defineConfig } from '@rslib/core';
36

7+
const distPath = join(__dirname, 'dist');
8+
9+
const afterDevCompileDonePlugin: RsbuildPlugin = {
10+
name: 'dev-done',
11+
setup(api) {
12+
api.onDevCompileDone(() => {
13+
fs.writeFileSync(join(distPath, 'done.txt'), 'done');
14+
});
15+
},
16+
};
17+
418
export default defineConfig({
519
lib: [
620
{
@@ -15,5 +29,6 @@ export default defineConfig({
1529
pluginModuleFederation({
1630
name: 'test',
1731
}),
32+
afterDevCompileDonePlugin,
1833
],
1934
});

0 commit comments

Comments
 (0)