|
| 1 | +import { exec } from 'node:child_process'; |
| 2 | +import { existsSync } from 'node:fs'; |
| 3 | +import { join } from 'node:path'; |
| 4 | +import fse from 'fs-extra'; |
| 5 | +import { awaitFileExists, buildAndGetResults } from 'test-helper'; |
| 6 | +import { describe, expect, test } from 'vitest'; |
| 7 | + |
| 8 | +describe('server config', async () => { |
| 9 | + test('basic config', async () => { |
| 10 | + const fixturePath = join(__dirname, 'basic'); |
| 11 | + await buildAndGetResults({ fixturePath }); |
| 12 | + |
| 13 | + // Check if logo.svg in public is copied to dist/esm |
| 14 | + const logoPath = join(__dirname, 'dist', 'esm', 'logo.svg'); |
| 15 | + const logoExists = existsSync(logoPath); |
| 16 | + expect(logoExists).toBe(false); |
| 17 | + }); |
| 18 | + |
| 19 | + test('mf dev command', async () => { |
| 20 | + const fixturePath = join(__dirname, 'mf-dev'); |
| 21 | + const distPath = join(fixturePath, 'dist'); |
| 22 | + const rsbuildConfigFile = join(distPath, '.rsbuild/rsbuild.config.mjs'); |
| 23 | + fse.removeSync(distPath); |
| 24 | + |
| 25 | + const childProcess = exec('npx rslib mf dev', { |
| 26 | + cwd: fixturePath, |
| 27 | + env: { |
| 28 | + ...process.env, |
| 29 | + DEBUG: 'rsbuild', |
| 30 | + }, |
| 31 | + }); |
| 32 | + |
| 33 | + await awaitFileExists(rsbuildConfigFile); |
| 34 | + childProcess.kill(); |
| 35 | + |
| 36 | + // Check if the server config is merged correctly |
| 37 | + const rsbuildConfig = await import(rsbuildConfigFile); |
| 38 | + expect(rsbuildConfig.default.server).toMatchInlineSnapshot(` |
| 39 | + { |
| 40 | + "base": "/", |
| 41 | + "compress": true, |
| 42 | + "host": "0.0.0.0", |
| 43 | + "htmlFallback": "index", |
| 44 | + "open": true, |
| 45 | + "port": 3002, |
| 46 | + "printUrls": false, |
| 47 | + "strictPort": false, |
| 48 | + } |
| 49 | + `); |
| 50 | + }); |
| 51 | +}); |
0 commit comments