Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
9 changes: 5 additions & 4 deletions e2e/cases/alias/legacy-alias/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { build, proxyConsole } from '@e2e/helper';
import { build } from '@e2e/helper';
import { expect, test } from '@playwright/test';

test('should allow to use the legacy `source.alias` config', async () => {
const { logs, restore } = proxyConsole();
const rsbuild = await build({
cwd: __dirname,
});
Expand All @@ -20,7 +19,9 @@ test('should allow to use the legacy `source.alias` config', async () => {
expect(files[nodeIndex!]).toContain('for node target');

expect(
logs.some((log) => log.includes('"source.alias" config is deprecated')),
rsbuild.logs.some((log) =>
log.includes('"source.alias" config is deprecated'),
),
).toBeTruthy();
restore();
await rsbuild.close();
});
28 changes: 12 additions & 16 deletions 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, proxyConsole } from '@e2e/helper';
import { build, dev, gotoPage } from '@e2e/helper';
import { expect, test } from '@playwright/test';
import { logger } from '@rsbuild/core';

Expand All @@ -14,13 +14,12 @@ const getBundlerConfig = (dist: string) =>
);

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

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

await build({
const { logs, close } = await build({
cwd: __dirname,
rsbuildConfig: {
output: {
Expand All @@ -42,18 +41,16 @@ test('should generate config files when build (with DEBUG)', async () => {
expect(logs.some((log) => log.includes('create compiler'))).toBeTruthy();

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

restore();
logger.level = level;
await close();
});

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

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

const rsbuild = await dev({
cwd: __dirname,
rsbuildConfig: {
Expand All @@ -74,15 +71,14 @@ test('should generate config files when dev (with DEBUG)', async ({ page }) => {
expect(fs.existsSync(getBundlerConfig(distRoot))).toBeTruthy();

expect(
logs.some((log) => log.includes('config inspection completed')),
rsbuild.logs.some((log) => log.includes('config inspection completed')),
).toBeTruthy();

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

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

logger.level = level;
await rsbuild.close();

restore();
});
21 changes: 11 additions & 10 deletions e2e/cases/config/rspack-config-validate/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { stripVTControlCharacters as stripAnsi } from 'node:util';
import { build, proxyConsole, rspackOnlyTest } from '@e2e/helper';
import { build, rspackOnlyTest } from '@e2e/helper';
import { expect } from '@playwright/test';
import { pluginReact } from '@rsbuild/plugin-react';

Expand All @@ -23,8 +23,7 @@ rspackOnlyTest('should validate Rspack config by default', async () => {
});

rspackOnlyTest('should warn when passing unrecognized keys', async () => {
const { logs, restore } = proxyConsole();
await build({
const rsbuild = await build({
cwd: __dirname,
rsbuildConfig: {
tools: {
Expand All @@ -37,20 +36,18 @@ rspackOnlyTest('should warn when passing unrecognized keys', async () => {
});

expect(
logs.some((log) =>
rsbuild.logs.some((log) =>
log.includes(`Unrecognized key(s) in object: 'unrecognized'`),
),
);
restore();
await rsbuild.close();
});

rspackOnlyTest('should allow to override Rspack config validate', async () => {
const { RSPACK_CONFIG_VALIDATE } = process.env;
process.env.RSPACK_CONFIG_VALIDATE = 'loose';

const { logs, restore } = proxyConsole();

await build({
const rsbuild = await build({
cwd: __dirname,
rsbuildConfig: {
tools: {
Expand All @@ -62,10 +59,14 @@ rspackOnlyTest('should allow to override Rspack config validate', async () => {
},
});

expect(logs.some((log) => log.includes('Expected object, received number')));
expect(
rsbuild.logs.some((log) =>
log.includes('Expected object, received number'),
),
);

process.env.RSPACK_CONFIG_VALIDATE = RSPACK_CONFIG_VALIDATE;
restore();
await rsbuild.close();
});

rspackOnlyTest(
Expand Down
24 changes: 11 additions & 13 deletions e2e/cases/config/stats-module-trace/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import { build, proxyConsole } from '@e2e/helper';
import { build } from '@e2e/helper';
import { expect, test } from '@playwright/test';

test('should log error module trace', async () => {
const { restore, logs } = proxyConsole();

await expect(
build({
cwd: __dirname,
rsbuildConfig: {},
}),
).rejects.toThrowError('build failed');

expect(logs.some((log) => log.includes('@ ./src/index.tsx'))).toBeTruthy();

restore();
const rsbuild = await build({
cwd: __dirname,
catchBuildError: true,
});

expect(rsbuild.buildError).toBeTruthy();
expect(
rsbuild.logs.some((log) => log.includes('@ ./src/index.tsx')),
).toBeTruthy();
await rsbuild.close();
});
19 changes: 7 additions & 12 deletions e2e/cases/config/stats-options/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
import { build, proxyConsole } from '@e2e/helper';
import { build } from '@e2e/helper';
import { expect, test } from '@playwright/test';

test('should log warning by default', async () => {
const { restore, logs } = proxyConsole();

await build({
const rsbuild = await build({
cwd: __dirname,
rsbuildConfig: {},
});

expect(
logs.some((log) =>
rsbuild.logs.some((log) =>
log.includes('Using / for division outside of calc() is deprecated'),
),
).toBeTruthy();

restore();
await rsbuild.close();
});

test('should not log warning when set stats.warnings false', async () => {
const { restore, logs } = proxyConsole();

await build({
const rsbuild = await build({
cwd: __dirname,
rsbuildConfig: {
tools: {
Expand All @@ -35,10 +30,10 @@ test('should not log warning when set stats.warnings false', async () => {
});

expect(
logs.some((log) =>
rsbuild.logs.some((log) =>
log.includes('Using / for division outside of calc() is deprecated'),
),
).toBeFalsy();

restore();
await rsbuild.close();
});
18 changes: 9 additions & 9 deletions e2e/cases/css/enable-experiments-css/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { build, proxyConsole, rspackOnlyTest } from '@e2e/helper';
import { build, rspackOnlyTest } from '@e2e/helper';
import { expect } from '@playwright/test';

rspackOnlyTest('should allow to enable Rspack experiments.css', async () => {
const { logs, restore } = proxyConsole();

const rsbuild = await build({
cwd: __dirname,
});
Expand All @@ -13,16 +11,16 @@ rspackOnlyTest('should allow to enable Rspack experiments.css', async () => {

expect(content).toEqual('body{color:red}');
// should have no warnings
expect(logs.some((log) => log.includes('Compile Warning'))).toBeFalsy();
expect(
rsbuild.logs.some((log) => log.includes('Compile Warning')),
).toBeFalsy();

restore();
await rsbuild.close();
});

rspackOnlyTest(
'should allow to enable Rspack experiments.css with style-loader',
async () => {
const { logs, restore } = proxyConsole();

const rsbuild = await build({
cwd: __dirname,
rsbuildConfig: {
Expand All @@ -38,8 +36,10 @@ rspackOnlyTest(
expect(content).toContain('color:red');

// should have no warnings
expect(logs.some((log) => log.includes('Compile Warning'))).toBeFalsy();
expect(
rsbuild.logs.some((log) => log.includes('Compile Warning')),
).toBeFalsy();

restore();
await rsbuild.close();
},
);
10 changes: 5 additions & 5 deletions e2e/cases/css/import-common-css/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { build, proxyConsole, rspackOnlyTest } from '@e2e/helper';
import { build, rspackOnlyTest } from '@e2e/helper';
import { expect } from '@playwright/test';

rspackOnlyTest('should compile common CSS import correctly', async () => {
const { restore, logs } = proxyConsole();

const rsbuild = await build({
cwd: __dirname,
rsbuildConfig: {
Expand All @@ -20,12 +18,14 @@ rspackOnlyTest('should compile common CSS import correctly', async () => {

// there will be a deprecation log for `~`.
expect(
logs.some((log) => log.includes(`a request starts with '~' is deprecated`)),
rsbuild.logs.some((log) =>
log.includes(`a request starts with '~' is deprecated`),
),
);

expect(files[cssFiles]).toEqual(
'html{min-height:100%}#a{color:red}#b{color:#00f}',
);

restore();
await rsbuild.close();
});
10 changes: 5 additions & 5 deletions e2e/cases/css/nested-npm-import/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import fs from 'node:fs';
import path from 'node:path';
import { build, proxyConsole, rspackOnlyTest } from '@e2e/helper';
import { build, rspackOnlyTest } from '@e2e/helper';
import { expect } from '@playwright/test';

rspackOnlyTest('should compile nested npm import correctly', async () => {
const { restore, logs } = proxyConsole();

fs.cpSync(
path.resolve(__dirname, '_node_modules'),
path.resolve(__dirname, 'node_modules'),
Expand All @@ -25,8 +23,10 @@ rspackOnlyTest('should compile nested npm import correctly', async () => {

// there will be a deprecation log for `~`.
expect(
logs.some((log) => log.includes(`a request starts with '~' is deprecated`)),
rsbuild.logs.some((log) =>
log.includes(`a request starts with '~' is deprecated`),
),
);

restore();
await rsbuild.close();
});
22 changes: 9 additions & 13 deletions e2e/cases/css/resolve-ts-paths/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
import { build, proxyConsole, rspackOnlyTest } from '@e2e/helper';
import { build, rspackOnlyTest } from '@e2e/helper';
import { expect } from '@playwright/test';

rspackOnlyTest('should resolve ts paths correctly in SCSS file', async () => {
const { restore } = proxyConsole();
try {
const rsbuild = await build({
cwd: __dirname,
});
const rsbuild = await build({
cwd: __dirname,
});

const files = await rsbuild.getDistFiles();
const files = await rsbuild.getDistFiles();

const content =
files[Object.keys(files).find((file) => file.endsWith('.css'))!];
const content =
files[Object.keys(files).find((file) => file.endsWith('.css'))!];

expect(content).toContain('background-image:url(/static/image/icon');
} finally {
restore();
}
expect(content).toContain('background-image:url(/static/image/icon');
await rsbuild.close();
});
13 changes: 6 additions & 7 deletions e2e/cases/javascript-api/custom-logger/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { build, proxyConsole, rspackOnlyTest } from '@e2e/helper';
import { build, rspackOnlyTest } from '@e2e/helper';
import { expect } from '@playwright/test';

rspackOnlyTest('should allow to customize logger', async () => {
const { logs, restore } = proxyConsole('log');

await build({
const rsbuild = await build({
cwd: __dirname,
});

expect(logs.find((item) => item.includes('[READY] built in'))).toBeTruthy();

restore();
expect(
rsbuild.logs.find((item) => item.includes('[READY] built in')),
).toBeTruthy();
await rsbuild.close();
});
Loading
Loading