Skip to content
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
63 changes: 32 additions & 31 deletions e2e/cases/hmr/basic/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,46 @@ import fs from 'node:fs';
import { join } from 'node:path';
import { expect, rspackTest } from '@e2e/helper';

const cwd = __dirname;

rspackTest('HMR should work by default', async ({ page, dev, editFile }) => {
await fs.promises.cp(join(cwd, 'src'), join(cwd, 'test-temp-src'), {
recursive: true,
});

await dev({
config: {
source: {
entry: {
index: join(cwd, 'test-temp-src/index.ts'),
rspackTest(
'HMR should work by default',
async ({ cwd, page, dev, editFile }) => {
await fs.promises.cp(join(cwd, 'src'), join(cwd, 'test-temp-src'), {
recursive: true,
});

await dev({
config: {
source: {
entry: {
index: join(cwd, 'test-temp-src/index.ts'),
},
},
},
},
});
});

const locator = page.locator('#test');
await expect(locator).toHaveText('Hello Rsbuild!');
await expect(locator).toHaveCSS('color', 'rgb(255, 0, 0)');
const locator = page.locator('#test');
await expect(locator).toHaveText('Hello Rsbuild!');
await expect(locator).toHaveCSS('color', 'rgb(255, 0, 0)');

const locatorKeep = page.locator('#test-keep');
const keepNum = await locatorKeep.innerHTML();
const locatorKeep = page.locator('#test-keep');
const keepNum = await locatorKeep.innerHTML();

await editFile('test-temp-src/App.tsx', (code) =>
code.replace('Hello Rsbuild', 'Hello Test'),
);
await editFile('test-temp-src/App.tsx', (code) =>
code.replace('Hello Rsbuild', 'Hello Test'),
);

await expect(locator).toHaveText('Hello Test!');
await expect(locator).toHaveText('Hello Test!');

// #test-keep should remain unchanged when app.tsx HMR
expect(await locatorKeep.innerHTML()).toBe(keepNum);
// #test-keep should remain unchanged when app.tsx HMR
expect(await locatorKeep.innerHTML()).toBe(keepNum);

await editFile(
'test-temp-src/App.css',
() => `#test {
await editFile(
'test-temp-src/App.css',
() => `#test {
color: rgb(0, 0, 255);
}`,
);
);

await expect(locator).toHaveCSS('color', 'rgb(0, 0, 255)');
});
await expect(locator).toHaveCSS('color', 'rgb(0, 0, 255)');
},
);
4 changes: 1 addition & 3 deletions e2e/cases/hmr/client-host/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ import fs from 'node:fs';
import { join } from 'node:path';
import { expect, rspackTest } from '@e2e/helper';

const cwd = __dirname;

rspackTest(
'HMR should work when setting dev.port and dev.client.host',
async ({ page, dev, editFile }) => {
async ({ cwd, page, dev, editFile }) => {
await fs.promises.cp(join(cwd, 'src'), join(cwd, 'test-temp-src'), {
recursive: true,
});
Expand Down
4 changes: 1 addition & 3 deletions e2e/cases/hmr/client-port-placeholder/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ import fs from 'node:fs';
import { join } from 'node:path';
import { expect, rspackTest } from '@e2e/helper';

const cwd = __dirname;

rspackTest(
'HMR should work when dev.client.port is `<port>`',
async ({ page, dev, editFile }) => {
async ({ cwd, page, dev, editFile }) => {
await fs.promises.cp(join(cwd, 'src'), join(cwd, 'test-temp-src'), {
recursive: true,
});
Expand Down
4 changes: 1 addition & 3 deletions e2e/cases/hmr/error-recovery/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ import fs from 'node:fs';
import { join } from 'node:path';
import { expect, rspackTest } from '@e2e/helper';

const cwd = __dirname;

rspackTest(
'HMR should work after fixing compilation error',
async ({ page, dev, editFile }) => {
async ({ cwd, page, dev, editFile }) => {
await fs.promises.cp(join(cwd, 'src'), join(cwd, 'test-temp-src'), {
recursive: true,
});
Expand Down
4 changes: 1 addition & 3 deletions e2e/cases/hmr/multiple-connection/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ import fs from 'node:fs';
import { join } from 'node:path';
import { expect, gotoPage, rspackTest } from '@e2e/helper';

const cwd = __dirname;

rspackTest(
'should allow to create multiple HMR connections',
async ({ page: page1, context, devOnly, editFile }) => {
async ({ cwd, page: page1, context, devOnly, editFile }) => {
await fs.promises.cp(join(cwd, 'src'), join(cwd, 'test-temp-src'), {
recursive: true,
});
Expand Down
6 changes: 2 additions & 4 deletions e2e/cases/hmr/rebuild-logs/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ import fs from 'node:fs';
import { join } from 'node:path';
import { expect, rspackTest } from '@e2e/helper';

const cwd = __dirname;

rspackTest(
'should print changed files in logs',
async ({ page, dev, editFile }) => {
async ({ cwd, page, dev, editFile }) => {
await fs.promises.cp(join(cwd, 'src'), join(cwd, 'test-temp-src'), {
recursive: true,
});
Expand All @@ -32,7 +30,7 @@ rspackTest(
},
);

rspackTest('should print removed files in logs', async ({ page, dev }) => {
rspackTest('should print removed files in logs', async ({ cwd, page, dev }) => {
await fs.promises.cp(join(cwd, 'src'), join(cwd, 'test-temp-src'), {
recursive: true,
});
Expand Down
4 changes: 1 addition & 3 deletions e2e/cases/hmr/reconnect/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ import fs from 'node:fs';
import { join } from 'node:path';
import { expect, rspackTest } from '@e2e/helper';

const cwd = __dirname;

rspackTest(
'should reconnect WebSocket server as expected',
async ({ page, dev, devOnly, editFile }) => {
async ({ cwd, page, dev, devOnly, editFile }) => {
await fs.promises.cp(join(cwd, 'src'), join(cwd, 'test-temp-src'), {
recursive: true,
});
Expand Down
9 changes: 1 addition & 8 deletions e2e/cases/output/clean-dist-path/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ const testDeepDistFile = join(cwd, 'dist/foo/bar/test.json');

test('should clean dist path by default', async ({ build }) => {
await fse.outputFile(testDistFile, `{ "test": 1 }`);

await build({
cwd,
});

await build();
expect(fs.existsSync(testDistFile)).toBeFalsy();
});

Expand Down Expand Up @@ -55,7 +51,6 @@ test('should not clean dist path if it is outside root', async ({ build }) => {
await fse.outputFile(testOutsideFile, `{ "test": 1 }`);

const rsbuild = await build({
cwd,
config: {
output: {
distPath: {
Expand All @@ -80,7 +75,6 @@ test('should allow to disable cleanDistPath', async ({ build }) => {
await fse.outputFile(testDistFile, `{ "test": 1 }`);

await build({
cwd,
config: {
output: {
cleanDistPath: false,
Expand All @@ -100,7 +94,6 @@ test('should allow to use `cleanDistPath.keep` to keep some files', async ({
await fse.outputFile(testDeepDistFile, `{ "test": 1 }`);

await build({
cwd,
config: {
output: {
cleanDistPath: {
Expand Down
4 changes: 0 additions & 4 deletions e2e/cases/performance/remove-console/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import type { BuildResult } from '@e2e/helper';
import { expect, getFileContent, test } from '@e2e/helper';

const cwd = __dirname;

const expectConsoleType = async (
rsbuild: Awaited<BuildResult>,
consoleType: Record<string, boolean>,
Expand All @@ -17,7 +15,6 @@ const expectConsoleType = async (

test('should remove specified console correctly', async ({ build }) => {
const rsbuild = await build({
cwd,
config: {
performance: {
removeConsole: ['log', 'warn'],
Expand All @@ -35,7 +32,6 @@ test('should remove specified console correctly', async ({ build }) => {

test('should remove all console correctly', async ({ build }) => {
const rsbuild = await build({
cwd,
config: {
performance: {
removeConsole: true,
Expand Down
4 changes: 1 addition & 3 deletions e2e/cases/plugin-react/disable-fast-refresh/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ import fs from 'node:fs';
import { join } from 'node:path';
import { expect, rspackTest } from '@e2e/helper';

const cwd = __dirname;

rspackTest(
'HMR should work when Fast Refresh is disabled',
async ({ page, dev, editFile }) => {
async ({ cwd, page, dev, editFile }) => {
await fs.promises.cp(join(cwd, 'src'), join(cwd, 'test-temp-src'), {
recursive: true,
});
Expand Down
20 changes: 2 additions & 18 deletions e2e/cases/print-file-size/basic/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { expect, test, toPosixPath } from '@e2e/helper';

const cwd = __dirname;

function extractFileSizeLogs(logs: string[]) {
const result: string[] = [];

Expand Down Expand Up @@ -40,9 +38,7 @@ test.describe('should print file size correctly', async () => {
test('should print file size after building by default', async ({
build,
}) => {
const rsbuild = await build({
cwd,
});
const rsbuild = await build();

expect(extractFileSizeLogs(rsbuild.logs)).toEqual(`
File (web) Size Gzip
Expand All @@ -58,7 +54,6 @@ dist/static/js/lib-react.[[hash]].js X.X kB X.X kB
build,
}) => {
const rsbuild = await build({
cwd,
config: {
output: {
filenameHash: false,
Expand Down Expand Up @@ -99,7 +94,6 @@ dist/static/js/lib-react.js X.X kB X.X kB
build,
}) => {
const rsbuild = await build({
cwd,
config: {
performance: {
printFileSize: false,
Expand All @@ -114,7 +108,6 @@ dist/static/js/lib-react.js X.X kB X.X kB
build,
}) => {
const rsbuild = await build({
cwd,
config: {
performance: {
printFileSize: {
Expand All @@ -130,7 +123,6 @@ Total size (web): X.X kB (X.X kB gzipped)`);

test('printFileSize.total: false should work', async ({ build }) => {
const rsbuild = await build({
cwd,
config: {
performance: {
printFileSize: {
Expand All @@ -153,7 +145,6 @@ dist/static/js/lib-react.[[hash]].js X.X kB X.X kB`);
build,
}) => {
const rsbuild = await build({
cwd,
config: {
output: {
distPath: {
Expand All @@ -175,7 +166,6 @@ File (web) Size Gzip

test('should allow to disable gzip-compressed size', async ({ build }) => {
const rsbuild = await build({
cwd,
config: {
performance: {
printFileSize: {
Expand All @@ -197,7 +187,6 @@ dist/static/js/lib-react.[[hash]].js X.X kB

test('should allow to filter assets by name', async ({ build }) => {
const rsbuild = await build({
cwd,
config: {
performance: {
printFileSize: {
Expand All @@ -216,7 +205,6 @@ dist/static/js/lib-react.[[hash]].js X.X kB X.X kB

test('should allow to filter assets by size', async ({ build }) => {
const rsbuild = await build({
cwd,
config: {
performance: {
printFileSize: {
Expand All @@ -233,7 +221,6 @@ dist/static/js/lib-react.[[hash]].js X.X kB X.X kB`);

test('should allow to custom exclude function', async ({ build }) => {
const rsbuild = await build({
cwd,
config: {
performance: {
printFileSize: {
Expand All @@ -257,9 +244,7 @@ dist/static/js/lib-react.[[hash]].js X.X kB X.X kB
test('should not calculate gzip size if the asset is not compressible', async ({
build,
}) => {
const rsbuild = await build({
cwd,
});
const rsbuild = await build();

expect(extractFileSizeLogs(rsbuild.logs)).toEqual(`
File (web) Size Gzip
Expand All @@ -275,7 +260,6 @@ dist/static/js/lib-react.[[hash]].js X.X kB X.X kB
build,
}) => {
const rsbuild = await build({
cwd,
config: {
performance: {
printFileSize: {
Expand Down
3 changes: 0 additions & 3 deletions e2e/cases/print-file-size/with-error/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { expect, test } from '@e2e/helper';

const cwd = __dirname;

test('should not print file size if has errors', async ({ build }) => {
const rsbuild = await build({
cwd,
catchBuildError: true,
});
expect(rsbuild.buildError).toBeTruthy();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { join } from 'node:path';
import { expect, rspackTest, test } from '@e2e/helper';
import { pluginReact } from '@rsbuild/plugin-react';

const cwd = __dirname;

rspackTest(
'should provide history api fallback for dev server correctly',
async ({ page, devOnly }) => {
Expand All @@ -12,7 +9,7 @@ rspackTest(
plugins: [pluginReact()],
source: {
entry: {
main: join(cwd, 'src/index.jsx'),
main: './src/index.jsx',
},
},
server: {
Expand All @@ -39,13 +36,11 @@ test('should provide history api fallback for preview server correctly', async (
buildPreview,
}) => {
const rsbuild = await buildPreview({
cwd,

config: {
plugins: [pluginReact()],
source: {
entry: {
main: join(cwd, 'src/index.jsx'),
main: './src/index.jsx',
},
},
server: {
Expand Down
Loading
Loading