Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
151 changes: 150 additions & 1 deletion packages/cli/builder/tests/parseConfig.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { OutputConfig } from '@rsbuild/core';
import { afterAll, describe, expect, test } from 'vitest';
import { afterAll, afterEach, describe, expect, test } from 'vitest';
import { parseCommonConfig } from '../src/shared/parseCommonConfig';
import type { BuilderConfig } from '../src/types';

Expand Down Expand Up @@ -137,4 +137,153 @@ describe('parseCommonConfig', () => {
});
}
});

describe('CSS source map configuration', () => {
const originalEnv = process.env.NODE_ENV;

afterEach(() => {
process.env.NODE_ENV = originalEnv;
});

test('should not set css source map when output.sourceMap is true', async () => {
const config = await parseCommonConfig({
output: {
sourceMap: true,
},
});

expect(config.rsbuildConfig.output?.sourceMap).toBe(true);
expect(config.rsbuildConfig.output?.sourceMap).not.toHaveProperty('css');
});

test('should set css source map to false when output.sourceMap is false', async () => {
const config = await parseCommonConfig({
output: {
sourceMap: false,
},
});

expect(config.rsbuildConfig.output?.sourceMap).toEqual(false);
});

test('should set css source map to true when output.sourceMap.css is explicitly true', async () => {
const config = await parseCommonConfig({
output: {
sourceMap: {
css: true,
},
},
});

expect(config.rsbuildConfig.output?.sourceMap).toEqual({
css: true,
});
});

test('should set css source map to false when output.sourceMap.css is explicitly false', async () => {
const config = await parseCommonConfig({
output: {
sourceMap: {
css: false,
},
},
});

expect(config.rsbuildConfig.output?.sourceMap).toEqual({
css: false,
});
});

test('should set css source map to true when output.sourceMap.css is undefined in development', async () => {
process.env.NODE_ENV = 'development';

const config = await parseCommonConfig({
output: {
sourceMap: {
js: true,
},
},
});

expect(config.rsbuildConfig.output?.sourceMap).toEqual({
js: true,
css: true,
});
});

test('should set css source map to false when output.sourceMap.css is undefined in production', async () => {
process.env.NODE_ENV = 'production';

const config = await parseCommonConfig({
output: {
sourceMap: {
js: true,
},
},
});

expect(config.rsbuildConfig.output?.sourceMap).toEqual({
js: true,
css: false,
});
});

test('should set css source map to true when output.sourceMap is undefined in development', async () => {
process.env.NODE_ENV = 'development';

const config = await parseCommonConfig({
output: {},
});

expect(config.rsbuildConfig.output?.sourceMap).toEqual({
css: true,
});
});

test('should set css source map to false when output.sourceMap is undefined in production', async () => {
process.env.NODE_ENV = 'production';

const config = await parseCommonConfig({
output: {},
});

expect(config.rsbuildConfig.output?.sourceMap).toEqual({
css: false,
});
});

test('should respect explicitly set css source map in development', async () => {
process.env.NODE_ENV = 'development';

const config = await parseCommonConfig({
output: {
sourceMap: {
css: false,
},
},
});

// Even in development, if explicitly set to false, it should remain false
expect(config.rsbuildConfig.output?.sourceMap).toEqual({
css: false,
});
});

test('should respect explicitly set css source map in production', async () => {
process.env.NODE_ENV = 'production';

const config = await parseCommonConfig({
output: {
sourceMap: {
css: true,
},
},
});

// Even in production, if explicitly set to true, it should remain true
expect(config.rsbuildConfig.output?.sourceMap).toEqual({
css: true,
});
});
});
});
Loading