|
1 |
| -import type { OutputConfig } from '@rsbuild/core'; |
| 1 | +import path from 'path'; |
| 2 | +import type { OutputConfig, RsbuildConfig } from '@rsbuild/core'; |
2 | 3 | import { afterAll, describe, expect, test } from 'vitest';
|
3 | 4 | import { parseCommonConfig } from '../src/shared/parseCommonConfig';
|
4 | 5 | import type { UniBuilderConfig } from '../src/types';
|
5 | 6 |
|
6 |
| -// fix windows test snap |
7 |
| -expect.addSnapshotSerializer({ |
8 |
| - test: val => typeof val === 'string' && val.includes('\\'), |
9 |
| - print: val => `"${(val as string).replace(/\\/g, '/')}"`, |
10 |
| -}); |
| 7 | +function normalizePathsInOutput(output: RsbuildConfig) { |
| 8 | + if (Array.isArray(output.html?.favicon)) { |
| 9 | + output.html.favicon = output.html.favicon.map(value => |
| 10 | + typeof value === 'string' ? path.posix.normalize(value) : value, |
| 11 | + ); |
| 12 | + } |
| 13 | + if (typeof output.html?.favicon === 'string') { |
| 14 | + output.html.favicon = path.posix.normalize(output.html.favicon); |
| 15 | + } |
| 16 | + |
| 17 | + return output; |
| 18 | +} |
11 | 19 |
|
12 | 20 | describe('parseCommonConfig', () => {
|
13 | 21 | const env = process.env.NODE_ENV;
|
@@ -143,18 +151,17 @@ describe('parseCommonConfig', () => {
|
143 | 151 | ).rsbuildConfig,
|
144 | 152 | ).toMatchSnapshot();
|
145 | 153 |
|
146 |
| - expect( |
147 |
| - ( |
148 |
| - await parseCommonConfig({ |
149 |
| - html: { |
150 |
| - favicon: 'https://www.foo.com/default.ico', |
151 |
| - faviconByEntries: { |
152 |
| - foo: 'https://www.foo.com/foo.ico', |
153 |
| - }, |
| 154 | + const config = ( |
| 155 | + await parseCommonConfig({ |
| 156 | + html: { |
| 157 | + favicon: 'https://www.foo.com/default.ico', |
| 158 | + faviconByEntries: { |
| 159 | + foo: 'https://www.foo.com/foo.ico', |
154 | 160 | },
|
155 |
| - }) |
156 |
| - ).rsbuildConfig, |
157 |
| - ).toMatchSnapshot(); |
| 161 | + }, |
| 162 | + }) |
| 163 | + ).rsbuildConfig; |
| 164 | + expect(normalizePathsInOutput(config)).toMatchSnapshot(); |
158 | 165 | });
|
159 | 166 |
|
160 | 167 | test('html.faviconByEntries', async () => {
|
@@ -246,7 +253,7 @@ describe('parseCommonConfig', () => {
|
246 | 253 |
|
247 | 254 | test('output.assetsRetry', async () => {
|
248 | 255 | expect(
|
249 |
| - (await parseCommonConfig({}, {})).rsbuildPlugins.some( |
| 256 | + (await parseCommonConfig({}, { cwd: '' })).rsbuildPlugins.some( |
250 | 257 | item => item.name === 'rsbuild:assets-retry',
|
251 | 258 | ),
|
252 | 259 | ).toBeFalsy();
|
|
0 commit comments