From e255fe4190009523814242fcd1037a8004d2d6a7 Mon Sep 17 00:00:00 2001 From: Timeless0911 <1604889533@qq.com> Date: Tue, 24 Dec 2024 15:13:29 +0800 Subject: [PATCH] test: stabilize mf-dev tests --- tests/integration/cli/mf-dev/dev.test.ts | 14 ++++++++------ tests/integration/cli/mf-dev/rslib.config.ts | 6 +++--- tests/integration/server/index.test.ts | 4 +++- tests/integration/server/mf-dev/rslib.config.ts | 15 +++++++++++++++ 4 files changed, 29 insertions(+), 10 deletions(-) diff --git a/tests/integration/cli/mf-dev/dev.test.ts b/tests/integration/cli/mf-dev/dev.test.ts index bc7fd79b2..76b5302c3 100644 --- a/tests/integration/cli/mf-dev/dev.test.ts +++ b/tests/integration/cli/mf-dev/dev.test.ts @@ -5,13 +5,12 @@ import fse, { existsSync } from 'fs-extra'; import { awaitFileExists } from 'test-helper'; import { expect, test } from 'vitest'; -const distFolder = join(__dirname, 'dist'); - describe('mf-dev', () => { test('mf-dev --lib', async () => { const fixturePath = join(__dirname); + const distFolder = join(__dirname, 'dist-mf0'); fse.removeSync(distFolder); - const distPath = join(distFolder, 'mf0', 'index.js'); + const distPath = join(distFolder, 'index.js'); const childProcess = exec('npx rslib mf-dev --lib mf0', { cwd: fixturePath, @@ -25,9 +24,12 @@ describe('mf-dev', () => { test('mf-dev --lib multiple', async () => { const fixturePath = join(__dirname); - fse.removeSync(distFolder); - const distPath1 = join(distFolder, 'mf1', 'index.js'); - const distPath2 = join(distFolder, 'mf2', 'index.js'); + const distFolder1 = join(__dirname, 'dist-mf1'); + const distFolder2 = join(__dirname, 'dist-mf2'); + fse.removeSync(distFolder1); + fse.removeSync(distFolder2); + const distPath1 = join(distFolder1, 'index.js'); + const distPath2 = join(distFolder2, 'index.js'); const childProcess = exec('npx rslib mf-dev --lib mf1 --lib mf2', { cwd: fixturePath, diff --git a/tests/integration/cli/mf-dev/rslib.config.ts b/tests/integration/cli/mf-dev/rslib.config.ts index 8db39f5f6..1a7fba16a 100644 --- a/tests/integration/cli/mf-dev/rslib.config.ts +++ b/tests/integration/cli/mf-dev/rslib.config.ts @@ -7,7 +7,7 @@ export default defineConfig({ format: 'mf', output: { distPath: { - root: 'dist/mf0', + root: 'dist-mf0', }, }, }, @@ -15,7 +15,7 @@ export default defineConfig({ format: 'mf', output: { distPath: { - root: 'dist/mf1', + root: 'dist-mf1', }, }, }, @@ -24,7 +24,7 @@ export default defineConfig({ format: 'mf', output: { distPath: { - root: 'dist/mf2', + root: 'dist-mf2', }, }, }, diff --git a/tests/integration/server/index.test.ts b/tests/integration/server/index.test.ts index 6139f8b4b..1adeb6ec4 100644 --- a/tests/integration/server/index.test.ts +++ b/tests/integration/server/index.test.ts @@ -20,6 +20,8 @@ describe('server config', async () => { const fixturePath = join(__dirname, 'mf-dev'); const distPath = join(fixturePath, 'dist'); const rsbuildConfigFile = join(distPath, '.rsbuild/rsbuild.config.mjs'); + const doneFile = join(distPath, 'done.txt'); + fse.removeSync(distPath); const childProcess = exec('npx rslib mf-dev', { @@ -30,7 +32,7 @@ describe('server config', async () => { }, }); - await awaitFileExists(rsbuildConfigFile); + await awaitFileExists(doneFile); const rsbuildConfigContent = await fse.readFile(rsbuildConfigFile, 'utf-8'); expect(rsbuildConfigContent).toContain('open: true'); diff --git a/tests/integration/server/mf-dev/rslib.config.ts b/tests/integration/server/mf-dev/rslib.config.ts index 5bfa949f9..95c7425bd 100644 --- a/tests/integration/server/mf-dev/rslib.config.ts +++ b/tests/integration/server/mf-dev/rslib.config.ts @@ -1,6 +1,20 @@ +import fs from 'node:fs'; +import { join } from 'node:path'; import { pluginModuleFederation } from '@module-federation/rsbuild-plugin'; +import type { RsbuildPlugin } from '@rsbuild/core'; import { defineConfig } from '@rslib/core'; +const distPath = join(__dirname, 'dist'); + +const afterDevCompileDonePlugin: RsbuildPlugin = { + name: 'dev-done', + setup(api) { + api.onDevCompileDone(() => { + fs.writeFileSync(join(distPath, 'done.txt'), 'done'); + }); + }, +}; + export default defineConfig({ lib: [ { @@ -15,5 +29,6 @@ export default defineConfig({ pluginModuleFederation({ name: 'test', }), + afterDevCompileDonePlugin, ], });