Skip to content

Commit 9808dca

Browse files
committed
test(e2e): remove redundant cwd declarations
1 parent 4f5b166 commit 9808dca

File tree

18 files changed

+57
-132
lines changed

18 files changed

+57
-132
lines changed

e2e/cases/hmr/basic/index.test.ts

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,46 @@ import fs from 'node:fs';
22
import { join } from 'node:path';
33
import { expect, rspackTest } from '@e2e/helper';
44

5-
const cwd = __dirname;
6-
7-
rspackTest('HMR should work by default', async ({ page, dev, editFile }) => {
8-
await fs.promises.cp(join(cwd, 'src'), join(cwd, 'test-temp-src'), {
9-
recursive: true,
10-
});
11-
12-
await dev({
13-
config: {
14-
source: {
15-
entry: {
16-
index: join(cwd, 'test-temp-src/index.ts'),
5+
rspackTest(
6+
'HMR should work by default',
7+
async ({ cwd, page, dev, editFile }) => {
8+
await fs.promises.cp(join(cwd, 'src'), join(cwd, 'test-temp-src'), {
9+
recursive: true,
10+
});
11+
12+
await dev({
13+
config: {
14+
source: {
15+
entry: {
16+
index: join(cwd, 'test-temp-src/index.ts'),
17+
},
1718
},
1819
},
19-
},
20-
});
20+
});
2121

22-
const locator = page.locator('#test');
23-
await expect(locator).toHaveText('Hello Rsbuild!');
24-
await expect(locator).toHaveCSS('color', 'rgb(255, 0, 0)');
22+
const locator = page.locator('#test');
23+
await expect(locator).toHaveText('Hello Rsbuild!');
24+
await expect(locator).toHaveCSS('color', 'rgb(255, 0, 0)');
2525

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

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

33-
await expect(locator).toHaveText('Hello Test!');
33+
await expect(locator).toHaveText('Hello Test!');
3434

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

38-
await editFile(
39-
'test-temp-src/App.css',
40-
() => `#test {
38+
await editFile(
39+
'test-temp-src/App.css',
40+
() => `#test {
4141
color: rgb(0, 0, 255);
4242
}`,
43-
);
43+
);
4444

45-
await expect(locator).toHaveCSS('color', 'rgb(0, 0, 255)');
46-
});
45+
await expect(locator).toHaveCSS('color', 'rgb(0, 0, 255)');
46+
},
47+
);

e2e/cases/hmr/client-host/index.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ import fs from 'node:fs';
22
import { join } from 'node:path';
33
import { expect, rspackTest } from '@e2e/helper';
44

5-
const cwd = __dirname;
6-
75
rspackTest(
86
'HMR should work when setting dev.port and dev.client.host',
9-
async ({ page, dev, editFile }) => {
7+
async ({ cwd, page, dev, editFile }) => {
108
await fs.promises.cp(join(cwd, 'src'), join(cwd, 'test-temp-src'), {
119
recursive: true,
1210
});

e2e/cases/hmr/client-port-placeholder/index.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ import fs from 'node:fs';
22
import { join } from 'node:path';
33
import { expect, rspackTest } from '@e2e/helper';
44

5-
const cwd = __dirname;
6-
75
rspackTest(
86
'HMR should work when dev.client.port is `<port>`',
9-
async ({ page, dev, editFile }) => {
7+
async ({ cwd, page, dev, editFile }) => {
108
await fs.promises.cp(join(cwd, 'src'), join(cwd, 'test-temp-src'), {
119
recursive: true,
1210
});

e2e/cases/hmr/error-recovery/index.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ import fs from 'node:fs';
22
import { join } from 'node:path';
33
import { expect, rspackTest } from '@e2e/helper';
44

5-
const cwd = __dirname;
6-
75
rspackTest(
86
'HMR should work after fixing compilation error',
9-
async ({ page, dev, editFile }) => {
7+
async ({ cwd, page, dev, editFile }) => {
108
await fs.promises.cp(join(cwd, 'src'), join(cwd, 'test-temp-src'), {
119
recursive: true,
1210
});

e2e/cases/hmr/multiple-connection/index.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ import fs from 'node:fs';
22
import { join } from 'node:path';
33
import { expect, gotoPage, rspackTest } from '@e2e/helper';
44

5-
const cwd = __dirname;
6-
75
rspackTest(
86
'should allow to create multiple HMR connections',
9-
async ({ page: page1, context, devOnly, editFile }) => {
7+
async ({ cwd, page: page1, context, devOnly, editFile }) => {
108
await fs.promises.cp(join(cwd, 'src'), join(cwd, 'test-temp-src'), {
119
recursive: true,
1210
});

e2e/cases/hmr/rebuild-logs/index.test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ import fs from 'node:fs';
22
import { join } from 'node:path';
33
import { expect, rspackTest } from '@e2e/helper';
44

5-
const cwd = __dirname;
6-
75
rspackTest(
86
'should print changed files in logs',
9-
async ({ page, dev, editFile }) => {
7+
async ({ cwd, page, dev, editFile }) => {
108
await fs.promises.cp(join(cwd, 'src'), join(cwd, 'test-temp-src'), {
119
recursive: true,
1210
});
@@ -32,7 +30,7 @@ rspackTest(
3230
},
3331
);
3432

35-
rspackTest('should print removed files in logs', async ({ page, dev }) => {
33+
rspackTest('should print removed files in logs', async ({ cwd, page, dev }) => {
3634
await fs.promises.cp(join(cwd, 'src'), join(cwd, 'test-temp-src'), {
3735
recursive: true,
3836
});

e2e/cases/hmr/reconnect/index.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ import fs from 'node:fs';
22
import { join } from 'node:path';
33
import { expect, rspackTest } from '@e2e/helper';
44

5-
const cwd = __dirname;
6-
75
rspackTest(
86
'should reconnect WebSocket server as expected',
9-
async ({ page, dev, devOnly, editFile }) => {
7+
async ({ cwd, page, dev, devOnly, editFile }) => {
108
await fs.promises.cp(join(cwd, 'src'), join(cwd, 'test-temp-src'), {
119
recursive: true,
1210
});

e2e/cases/output/clean-dist-path/index.test.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@ const testDeepDistFile = join(cwd, 'dist/foo/bar/test.json');
99

1010
test('should clean dist path by default', async ({ build }) => {
1111
await fse.outputFile(testDistFile, `{ "test": 1 }`);
12-
13-
await build({
14-
cwd,
15-
});
16-
12+
await build();
1713
expect(fs.existsSync(testDistFile)).toBeFalsy();
1814
});
1915

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

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

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

10296
await build({
103-
cwd,
10497
config: {
10598
output: {
10699
cleanDistPath: {

e2e/cases/performance/remove-console/index.test.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import type { BuildResult } from '@e2e/helper';
22
import { expect, getFileContent, test } from '@e2e/helper';
33

4-
const cwd = __dirname;
5-
64
const expectConsoleType = async (
75
rsbuild: Awaited<BuildResult>,
86
consoleType: Record<string, boolean>,
@@ -17,7 +15,6 @@ const expectConsoleType = async (
1715

1816
test('should remove specified console correctly', async ({ build }) => {
1917
const rsbuild = await build({
20-
cwd,
2118
config: {
2219
performance: {
2320
removeConsole: ['log', 'warn'],
@@ -35,7 +32,6 @@ test('should remove specified console correctly', async ({ build }) => {
3532

3633
test('should remove all console correctly', async ({ build }) => {
3734
const rsbuild = await build({
38-
cwd,
3935
config: {
4036
performance: {
4137
removeConsole: true,

e2e/cases/plugin-react/disable-fast-refresh/index.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ import fs from 'node:fs';
22
import { join } from 'node:path';
33
import { expect, rspackTest } from '@e2e/helper';
44

5-
const cwd = __dirname;
6-
75
rspackTest(
86
'HMR should work when Fast Refresh is disabled',
9-
async ({ page, dev, editFile }) => {
7+
async ({ cwd, page, dev, editFile }) => {
108
await fs.promises.cp(join(cwd, 'src'), join(cwd, 'test-temp-src'), {
119
recursive: true,
1210
});

0 commit comments

Comments
 (0)