Skip to content

Commit

Permalink
fix: unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
caohuilin committed Feb 5, 2025
1 parent 39ce064 commit 507a060
Showing 1 changed file with 25 additions and 18 deletions.
43 changes: 25 additions & 18 deletions packages/cli/uni-builder/tests/parseConfig.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import type { OutputConfig } from '@rsbuild/core';
import path from 'path';
import type { OutputConfig, RsbuildConfig } from '@rsbuild/core';
import { afterAll, describe, expect, test } from 'vitest';
import { parseCommonConfig } from '../src/shared/parseCommonConfig';
import type { UniBuilderConfig } from '../src/types';

// fix windows test snap
expect.addSnapshotSerializer({
test: val => typeof val === 'string' && val.includes('\\'),
print: val => `"${(val as string).replace(/\\/g, '/')}"`,
});
function normalizePathsInOutput(output: RsbuildConfig) {
if (Array.isArray(output.html?.favicon)) {
output.html.favicon = output.html.favicon.map(value =>
typeof value === 'string' ? path.posix.normalize(value) : value,
);
}
if (typeof output.html?.favicon === 'string') {
output.html.favicon = path.posix.normalize(output.html.favicon);
}

return output;
}

describe('parseCommonConfig', () => {
const env = process.env.NODE_ENV;
Expand Down Expand Up @@ -143,18 +151,17 @@ describe('parseCommonConfig', () => {
).rsbuildConfig,
).toMatchSnapshot();

expect(
(
await parseCommonConfig({
html: {
favicon: 'https://www.foo.com/default.ico',
faviconByEntries: {
foo: 'https://www.foo.com/foo.ico',
},
const config = (
await parseCommonConfig({
html: {
favicon: 'https://www.foo.com/default.ico',
faviconByEntries: {
foo: 'https://www.foo.com/foo.ico',
},
})
).rsbuildConfig,
).toMatchSnapshot();
},
})
).rsbuildConfig;
expect(normalizePathsInOutput(config)).toMatchSnapshot();
});

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

test('output.assetsRetry', async () => {
expect(
(await parseCommonConfig({}, {})).rsbuildPlugins.some(
(await parseCommonConfig({}, { cwd: '' })).rsbuildPlugins.some(
item => item.name === 'rsbuild:assets-retry',
),
).toBeFalsy();
Expand Down

0 comments on commit 507a060

Please sign in to comment.