Skip to content

Commit

Permalink
test(e2e): proxy logs to avoid redundant e2e outputs (#4250)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan authored Dec 24, 2024
1 parent eb2702a commit ca5d561
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 77 deletions.
20 changes: 19 additions & 1 deletion e2e/cases/config/inspect-config/debug.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'node:fs';
import path from 'node:path';
import { build, dev, gotoPage } from '@e2e/helper';
import { build, dev, gotoPage, proxyConsole } from '@e2e/helper';
import { expect, test } from '@playwright/test';
import { logger } from '@rsbuild/core';

Expand All @@ -18,6 +18,7 @@ test('should generate config files when build (with DEBUG)', async () => {
logger.level = 'verbose';

const distRoot = 'dist-1';
const { logs, restore } = proxyConsole();

await build({
cwd: __dirname,
Expand All @@ -34,15 +35,24 @@ test('should generate config files when build (with DEBUG)', async () => {
expect(fs.existsSync(getRsbuildConfig(distRoot))).toBeTruthy();
expect(fs.existsSync(getBundlerConfig(distRoot))).toBeTruthy();

expect(
logs.some((log) => log.includes('Inspect config succeed')),
).toBeTruthy();

expect(logs.some((log) => log.includes('create compiler'))).toBeTruthy();

delete process.env.DEBUG;
logger.level = 'log';

restore();
});

test('should generate config files when dev (with DEBUG)', async ({ page }) => {
process.env.DEBUG = 'rsbuild';
logger.level = 'verbose';

const distRoot = 'dist-2';
const { logs, restore } = proxyConsole();

const rsbuild = await dev({
cwd: __dirname,
Expand All @@ -63,8 +73,16 @@ test('should generate config files when dev (with DEBUG)', async ({ page }) => {
expect(fs.existsSync(getRsbuildConfig(distRoot))).toBeTruthy();
expect(fs.existsSync(getBundlerConfig(distRoot))).toBeTruthy();

expect(
logs.some((log) => log.includes('Inspect config succeed')),
).toBeTruthy();

expect(logs.some((log) => log.includes('create compiler'))).toBeTruthy();

delete process.env.DEBUG;
logger.level = 'log';

await rsbuild.close();

restore();
});
192 changes: 118 additions & 74 deletions e2e/cases/config/inspect-config/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'node:fs';
import path from 'node:path';
import { createRsbuild, rspackOnlyTest } from '@e2e/helper';
import { expect, test } from '@playwright/test';
import { createRsbuild, proxyConsole, rspackOnlyTest } from '@e2e/helper';
import { expect } from '@playwright/test';

const rsbuildConfig = path.resolve(
__dirname,
Expand All @@ -21,92 +21,130 @@ const bundlerNodeConfig = path.resolve(
`./dist/.rsbuild/${process.env.PROVIDE_TYPE || 'rspack'}.config.node.mjs`,
);

test('should generate config files when writeToDisk is true', async () => {
const rsbuild = await createRsbuild({
cwd: __dirname,
});
await rsbuild.inspectConfig({
writeToDisk: true,
});
rspackOnlyTest(
'should generate config files when writeToDisk is true',
async () => {
const { logs, restore } = proxyConsole();

expect(fs.existsSync(bundlerConfig)).toBeTruthy();
expect(fs.existsSync(rsbuildConfig)).toBeTruthy();
const rsbuild = await createRsbuild({
cwd: __dirname,
});
await rsbuild.inspectConfig({
writeToDisk: true,
});

fs.rmSync(rsbuildConfig, { force: true });
fs.rmSync(bundlerConfig, { force: true });
});

test('should generate config files correctly when output is specified', async () => {
const rsbuild = await createRsbuild({
cwd: __dirname,
});
await rsbuild.inspectConfig({
writeToDisk: true,
outputPath: 'foo',
});
expect(fs.existsSync(bundlerConfig)).toBeTruthy();
expect(fs.existsSync(rsbuildConfig)).toBeTruthy();

const bundlerConfig = path.resolve(
__dirname,
`./dist/foo/${process.env.PROVIDE_TYPE || 'rspack'}.config.web.mjs`,
);
expect(
logs.some((log) => log.includes('Inspect config succeed')),
).toBeTruthy();

const rsbuildConfig = path.resolve(
__dirname,
'./dist/foo/rsbuild.config.mjs',
);
fs.rmSync(rsbuildConfig, { force: true });
fs.rmSync(bundlerConfig, { force: true });

expect(fs.existsSync(bundlerConfig)).toBeTruthy();
expect(fs.existsSync(rsbuildConfig)).toBeTruthy();
restore();
},
);

fs.rmSync(rsbuildConfig, { force: true });
fs.rmSync(bundlerConfig, { force: true });
});
rspackOnlyTest(
'should generate config files correctly when output is specified',
async () => {
const { logs, restore } = proxyConsole();

const rsbuild = await createRsbuild({
cwd: __dirname,
});
await rsbuild.inspectConfig({
writeToDisk: true,
outputPath: 'foo',
});

const bundlerConfig = path.resolve(
__dirname,
`./dist/foo/${process.env.PROVIDE_TYPE || 'rspack'}.config.web.mjs`,
);

const rsbuildConfig = path.resolve(
__dirname,
'./dist/foo/rsbuild.config.mjs',
);

expect(fs.existsSync(bundlerConfig)).toBeTruthy();
expect(fs.existsSync(rsbuildConfig)).toBeTruthy();

expect(
logs.some((log) => log.includes('Inspect config succeed')),
).toBeTruthy();

fs.rmSync(rsbuildConfig, { force: true });
fs.rmSync(bundlerConfig, { force: true });

restore();
},
);

test('should generate bundler config for node when target contains node', async () => {
const rsbuild = await createRsbuild({
cwd: __dirname,
rsbuildConfig: {
environments: {
web: {
output: {
target: 'web',
rspackOnlyTest(
'should generate bundler config for node when target contains node',
async () => {
const { logs, restore } = proxyConsole();

const rsbuild = await createRsbuild({
cwd: __dirname,
rsbuildConfig: {
environments: {
web: {
output: {
target: 'web',
},
},
},
node: {
output: {
target: 'node',
node: {
output: {
target: 'node',
},
},
},
},
},
});
await rsbuild.inspectConfig({
writeToDisk: true,
});

expect(fs.existsSync(rsbuildNodeConfig)).toBeTruthy();
expect(fs.existsSync(bundlerConfig)).toBeTruthy();
expect(fs.existsSync(bundlerNodeConfig)).toBeTruthy();

fs.rmSync(rsbuildConfig, { force: true });
fs.rmSync(rsbuildNodeConfig, { force: true });
fs.rmSync(bundlerConfig, { force: true });
fs.rmSync(bundlerNodeConfig, { force: true });
});

test('should not generate config files when writeToDisk is false', async () => {
const rsbuild = await createRsbuild({
cwd: __dirname,
});
await rsbuild.inspectConfig({
writeToDisk: false,
});
});
await rsbuild.inspectConfig({
writeToDisk: true,
});

expect(fs.existsSync(rsbuildNodeConfig)).toBeTruthy();
expect(fs.existsSync(bundlerConfig)).toBeTruthy();
expect(fs.existsSync(bundlerNodeConfig)).toBeTruthy();

expect(
logs.some((log) => log.includes('Inspect config succeed')),
).toBeTruthy();

fs.rmSync(rsbuildConfig, { force: true });
fs.rmSync(rsbuildNodeConfig, { force: true });
fs.rmSync(bundlerConfig, { force: true });
fs.rmSync(bundlerNodeConfig, { force: true });

restore();
},
);

expect(fs.existsSync(rsbuildConfig)).toBeFalsy();
expect(fs.existsSync(bundlerConfig)).toBeFalsy();
});
rspackOnlyTest(
'should not generate config files when writeToDisk is false',
async () => {
const rsbuild = await createRsbuild({
cwd: __dirname,
});
await rsbuild.inspectConfig({
writeToDisk: false,
});

expect(fs.existsSync(rsbuildConfig)).toBeFalsy();
expect(fs.existsSync(bundlerConfig)).toBeFalsy();
},
);

rspackOnlyTest('should allow to specify absolute output path', async () => {
const { logs, restore } = proxyConsole();

const rsbuild = await createRsbuild({
cwd: __dirname,
});
Expand All @@ -117,9 +155,15 @@ rspackOnlyTest('should allow to specify absolute output path', async () => {
outputPath,
});

expect(
logs.some((log) => log.includes('Inspect config succeed')),
).toBeTruthy();

expect(
fs.existsSync(path.join(outputPath, 'rspack.config.web.mjs')),
).toBeTruthy();

fs.rmSync(rsbuildConfig, { force: true });

restore();
});
18 changes: 17 additions & 1 deletion e2e/cases/performance/bundle-analyzer/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { join } from 'node:path';
import { build, dev, globContentJSON } from '@e2e/helper';
import { build, dev, globContentJSON, proxyConsole } from '@e2e/helper';
import { expect, test } from '@playwright/test';

test('should emit bundle analyze report correctly when dev', async ({
page,
}) => {
const { logs, restore } = proxyConsole();

const rsbuild = await dev({
cwd: __dirname,
});
Expand All @@ -19,10 +21,18 @@ test('should emit bundle analyze report correctly when dev', async ({
);
expect(filePaths.length).toBe(1);

expect(
logs.some((log) => log.includes('Webpack Bundle Analyzer saved report to')),
).toBeTruthy();

await rsbuild.close();

restore();
});

test('should emit bundle analyze report correctly when build', async () => {
const { logs, restore } = proxyConsole();

const rsbuild = await build({
cwd: __dirname,
});
Expand All @@ -32,5 +42,11 @@ test('should emit bundle analyze report correctly when build', async () => {
file.endsWith('report-web.html'),
);

expect(
logs.some((log) => log.includes('Webpack Bundle Analyzer saved report to')),
).toBeTruthy();

expect(filePaths.length).toBe(1);

restore();
});
1 change: 0 additions & 1 deletion e2e/cases/server/ssr/rsbuild.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ export default defineConfig({
runtimeChunk: true,
splitChunks: {
chunks: 'all',
enforceSizeThreshold: 50000,
minSize: 0,
cacheGroups: {
'lib-react': {
Expand Down

0 comments on commit ca5d561

Please sign in to comment.