Skip to content

Commit 2422661

Browse files
committed
fix: unit test
1 parent c61a3a1 commit 2422661

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

packages/cli/uni-builder/tests/parseConfig.test.ts

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
1-
import type { OutputConfig } from '@rsbuild/core';
1+
import path from 'path';
2+
import type { OutputConfig, RsbuildConfig } from '@rsbuild/core';
23
import { afterAll, describe, expect, test } from 'vitest';
34
import { parseCommonConfig } from '../src/shared/parseCommonConfig';
45
import type { UniBuilderConfig } from '../src/types';
56

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+
619
describe('parseCommonConfig', () => {
720
const env = process.env.NODE_ENV;
821

@@ -137,18 +150,17 @@ describe('parseCommonConfig', () => {
137150
).rsbuildConfig,
138151
).toMatchSnapshot();
139152

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',
148159
},
149-
})
150-
).rsbuildConfig,
151-
).toMatchSnapshot();
160+
},
161+
})
162+
).rsbuildConfig;
163+
expect(normalizePathsInOutput(config)).toMatchSnapshot();
152164
});
153165

154166
test('html.faviconByEntries', async () => {
@@ -240,7 +252,7 @@ describe('parseCommonConfig', () => {
240252

241253
test('output.assetsRetry', async () => {
242254
expect(
243-
(await parseCommonConfig({}, {})).rsbuildPlugins.some(
255+
(await parseCommonConfig({}, { cwd: '' })).rsbuildPlugins.some(
244256
item => item.name === 'rsbuild:assets-retry',
245257
),
246258
).toBeFalsy();

0 commit comments

Comments
 (0)