|
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 |
|
| 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' ? new URL(value).href : value, |
| 11 | + ); |
| 12 | + } |
| 13 | + if (typeof output.html?.favicon === 'string') { |
| 14 | + output.html.favicon = new URL(output.html.favicon).href; |
| 15 | + } |
| 16 | + return output; |
| 17 | +} |
| 18 | + |
6 | 19 | describe('parseCommonConfig', () => {
|
7 | 20 | const env = process.env.NODE_ENV;
|
8 | 21 |
|
@@ -137,18 +150,17 @@ describe('parseCommonConfig', () => {
|
137 | 150 | ).rsbuildConfig,
|
138 | 151 | ).toMatchSnapshot();
|
139 | 152 |
|
140 |
| - expect( |
141 |
| - ( |
142 |
| - await parseCommonConfig({ |
143 |
| - html: { |
144 |
| - favicon: 'https://www.foo.com/default.ico', |
145 |
| - faviconByEntries: { |
146 |
| - foo: 'https://www.foo.com/foo.ico', |
147 |
| - }, |
| 153 | + const config = ( |
| 154 | + await parseCommonConfig({ |
| 155 | + html: { |
| 156 | + favicon: 'https://www.foo.com/default.ico', |
| 157 | + faviconByEntries: { |
| 158 | + foo: 'https://www.foo.com/foo.ico', |
148 | 159 | },
|
149 |
| - }) |
150 |
| - ).rsbuildConfig, |
151 |
| - ).toMatchSnapshot(); |
| 160 | + }, |
| 161 | + }) |
| 162 | + ).rsbuildConfig; |
| 163 | + expect(normalizePathsInOutput(config)).toMatchSnapshot(); |
152 | 164 | });
|
153 | 165 |
|
154 | 166 | test('html.faviconByEntries', async () => {
|
@@ -240,7 +252,7 @@ describe('parseCommonConfig', () => {
|
240 | 252 |
|
241 | 253 | test('output.assetsRetry', async () => {
|
242 | 254 | expect(
|
243 |
| - (await parseCommonConfig({}, {})).rsbuildPlugins.some( |
| 255 | + (await parseCommonConfig({}, { cwd: '' })).rsbuildPlugins.some( |
244 | 256 | item => item.name === 'rsbuild:assets-retry',
|
245 | 257 | ),
|
246 | 258 | ).toBeFalsy();
|
|
0 commit comments