Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(e2e): validate dev source map #3501

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
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
46 changes: 33 additions & 13 deletions e2e/cases/source-map/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { build } from '@e2e/helper';
import { readFileSync } from 'node:fs';
import { join } from 'node:path';
import { build, dev } from '@e2e/helper';
import { expect, test } from '@playwright/test';
import type { Rspack } from '@rsbuild/core';
import { pluginReact } from '@rsbuild/plugin-react';

import sourceMap from 'source-map';

const fixtures = __dirname;
Expand Down Expand Up @@ -30,22 +30,13 @@ async function validateSourceMap(
async function testSourceMapType(devtool: Rspack.Configuration['devtool']) {
const rsbuild = await build({
cwd: fixtures,
plugins: [pluginReact()],
rsbuildConfig: {
dev: {
writeToDisk: true,
},
output: {
sourceMap: {
js: devtool,
},
legalComments: 'none',
},
performance: {
chunkSplit: {
strategy: 'all-in-one',
},
},
},
});

Expand Down Expand Up @@ -108,7 +99,6 @@ for (const devtool of productionDevtools) {
test('should not generate source map by default in production build', async () => {
const rsbuild = await build({
cwd: fixtures,
plugins: [pluginReact()],
});

const files = await rsbuild.unwrapOutputJSON(false);
Expand All @@ -122,3 +112,33 @@ test('should not generate source map by default in production build', async () =
expect(jsMapFiles.length).toEqual(0);
expect(cssMapFiles.length).toEqual(0);
});

test('should generate source map correctly in development build', async ({
page,
}) => {
const rsbuild = await dev({
cwd: fixtures,
page,
});

const files = await rsbuild.unwrapOutputJSON(false);

const jsMapFile = Object.keys(files).find((files) =>
files.endsWith('.js.map'),
);
expect(jsMapFile).not.toBeUndefined();

const jsContent = await readFileSync(jsMapFile!, 'utf-8');
const jsMap = JSON.parse(jsContent);
expect(jsMap.sources.length).toBeGreaterThan(1);
expect(jsMap.file).toEqual('static/js/index.js');
expect(jsMap.sourcesContent).toContain(
readFileSync(join(fixtures, 'src/App.jsx'), 'utf-8'),
);
expect(jsMap.sourcesContent).toContain(
readFileSync(join(fixtures, 'src/index.js'), 'utf-8'),
);
expect(jsMap.mappings).not.toBeUndefined();

await rsbuild.close();
});
14 changes: 14 additions & 0 deletions e2e/cases/source-map/rsbuild.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { defineConfig } from '@rsbuild/core';
import { pluginReact } from '@rsbuild/plugin-react';

export default defineConfig({
plugins: [pluginReact()],
dev: {
writeToDisk: true,
},
performance: {
chunkSplit: {
strategy: 'all-in-one',
},
},
});
Loading