Skip to content

Commit 507a060

Browse files
committed
fix: unit test
1 parent 39ce064 commit 507a060

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

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

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +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

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+
}
1119

1220
describe('parseCommonConfig', () => {
1321
const env = process.env.NODE_ENV;
@@ -143,18 +151,17 @@ describe('parseCommonConfig', () => {
143151
).rsbuildConfig,
144152
).toMatchSnapshot();
145153

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',
154160
},
155-
})
156-
).rsbuildConfig,
157-
).toMatchSnapshot();
161+
},
162+
})
163+
).rsbuildConfig;
164+
expect(normalizePathsInOutput(config)).toMatchSnapshot();
158165
});
159166

160167
test('html.faviconByEntries', async () => {
@@ -246,7 +253,7 @@ describe('parseCommonConfig', () => {
246253

247254
test('output.assetsRetry', async () => {
248255
expect(
249-
(await parseCommonConfig({}, {})).rsbuildPlugins.some(
256+
(await parseCommonConfig({}, { cwd: '' })).rsbuildPlugins.some(
250257
item => item.name === 'rsbuild:assets-retry',
251258
),
252259
).toBeFalsy();

0 commit comments

Comments
 (0)