Skip to content

Commit a59cccd

Browse files
authored
tests: add parseCommonConfig's sourceMap tests. (#7691)
1 parent 73d3e8d commit a59cccd

File tree

1 file changed

+150
-1
lines changed

1 file changed

+150
-1
lines changed

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

Lines changed: 150 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { OutputConfig } from '@rsbuild/core';
2-
import { afterAll, describe, expect, test } from 'vitest';
2+
import { afterAll, afterEach, describe, expect, test } from 'vitest';
33
import { parseCommonConfig } from '../src/shared/parseCommonConfig';
44
import type { BuilderConfig } from '../src/types';
55

@@ -137,4 +137,153 @@ describe('parseCommonConfig', () => {
137137
});
138138
}
139139
});
140+
141+
describe('CSS source map configuration', () => {
142+
const originalEnv = process.env.NODE_ENV;
143+
144+
afterEach(() => {
145+
process.env.NODE_ENV = originalEnv;
146+
});
147+
148+
test('should not set css source map when output.sourceMap is true', async () => {
149+
const config = await parseCommonConfig({
150+
output: {
151+
sourceMap: true,
152+
},
153+
});
154+
155+
expect(config.rsbuildConfig.output?.sourceMap).toBe(true);
156+
expect(config.rsbuildConfig.output?.sourceMap).not.toHaveProperty('css');
157+
});
158+
159+
test('should set css source map to false when output.sourceMap is false', async () => {
160+
const config = await parseCommonConfig({
161+
output: {
162+
sourceMap: false,
163+
},
164+
});
165+
166+
expect(config.rsbuildConfig.output?.sourceMap).toEqual(false);
167+
});
168+
169+
test('should set css source map to true when output.sourceMap.css is explicitly true', async () => {
170+
const config = await parseCommonConfig({
171+
output: {
172+
sourceMap: {
173+
css: true,
174+
},
175+
},
176+
});
177+
178+
expect(config.rsbuildConfig.output?.sourceMap).toEqual({
179+
css: true,
180+
});
181+
});
182+
183+
test('should set css source map to false when output.sourceMap.css is explicitly false', async () => {
184+
const config = await parseCommonConfig({
185+
output: {
186+
sourceMap: {
187+
css: false,
188+
},
189+
},
190+
});
191+
192+
expect(config.rsbuildConfig.output?.sourceMap).toEqual({
193+
css: false,
194+
});
195+
});
196+
197+
test('should set css source map to true when output.sourceMap.css is undefined in development', async () => {
198+
process.env.NODE_ENV = 'development';
199+
200+
const config = await parseCommonConfig({
201+
output: {
202+
sourceMap: {
203+
js: true,
204+
},
205+
},
206+
});
207+
208+
expect(config.rsbuildConfig.output?.sourceMap).toEqual({
209+
js: true,
210+
css: true,
211+
});
212+
});
213+
214+
test('should set css source map to false when output.sourceMap.css is undefined in production', async () => {
215+
process.env.NODE_ENV = 'production';
216+
217+
const config = await parseCommonConfig({
218+
output: {
219+
sourceMap: {
220+
js: true,
221+
},
222+
},
223+
});
224+
225+
expect(config.rsbuildConfig.output?.sourceMap).toEqual({
226+
js: true,
227+
css: false,
228+
});
229+
});
230+
231+
test('should set css source map to true when output.sourceMap is undefined in development', async () => {
232+
process.env.NODE_ENV = 'development';
233+
234+
const config = await parseCommonConfig({
235+
output: {},
236+
});
237+
238+
expect(config.rsbuildConfig.output?.sourceMap).toEqual({
239+
css: true,
240+
});
241+
});
242+
243+
test('should set css source map to false when output.sourceMap is undefined in production', async () => {
244+
process.env.NODE_ENV = 'production';
245+
246+
const config = await parseCommonConfig({
247+
output: {},
248+
});
249+
250+
expect(config.rsbuildConfig.output?.sourceMap).toEqual({
251+
css: false,
252+
});
253+
});
254+
255+
test('should respect explicitly set css source map in development', async () => {
256+
process.env.NODE_ENV = 'development';
257+
258+
const config = await parseCommonConfig({
259+
output: {
260+
sourceMap: {
261+
css: false,
262+
},
263+
},
264+
});
265+
266+
// Even in development, if explicitly set to false, it should remain false
267+
expect(config.rsbuildConfig.output?.sourceMap).toEqual({
268+
css: false,
269+
});
270+
});
271+
272+
test('should respect explicitly set css source map in production', async () => {
273+
process.env.NODE_ENV = 'production';
274+
275+
const config = await parseCommonConfig({
276+
output: {
277+
sourceMap: {
278+
css: true,
279+
},
280+
},
281+
});
282+
283+
// Even in production, if explicitly set to true, it should remain true
284+
expect(config.rsbuildConfig.output?.sourceMap).toEqual({
285+
css: true,
286+
});
287+
});
288+
});
140289
});

0 commit comments

Comments
 (0)