Skip to content

Commit 7d64a8e

Browse files
authored
test(e2e): migrate all cases to ESM (#4579)
1 parent d5bd6b6 commit 7d64a8e

File tree

346 files changed

+884
-760
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

346 files changed

+884
-760
lines changed

e2e/cases/alias/alias-by-target/index.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { expect, test } from '@playwright/test';
33

44
test('should allow to set alias by build target', async () => {
55
const rsbuild = await build({
6-
cwd: __dirname,
6+
cwd: import.meta.dirname,
77
});
88

99
const files = await rsbuild.unwrapOutputJSON();

e2e/cases/alias/jsconfig-paths/index.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ rspackOnlyTest(
55
'tsconfig paths should work and override the alias config',
66
async ({ page }) => {
77
const rsbuild = await build({
8-
cwd: __dirname,
8+
cwd: import.meta.dirname,
99
page,
1010
rsbuildConfig: {
1111
resolve: {
@@ -30,7 +30,7 @@ rspackOnlyTest(
3030
'tsconfig paths should not work when aliasStrategy is "prefer-alias"',
3131
async ({ page }) => {
3232
const rsbuild = await build({
33-
cwd: __dirname,
33+
cwd: import.meta.dirname,
3434
page,
3535
rsbuildConfig: {
3636
resolve: {

e2e/cases/alias/legacy-alias/index.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { expect, test } from '@playwright/test';
33

44
test('should allow to use the legacy `source.alias` config', async () => {
55
const rsbuild = await build({
6-
cwd: __dirname,
6+
cwd: import.meta.dirname,
77
});
88

99
const files = await rsbuild.unwrapOutputJSON();

e2e/cases/alias/tsconfig-paths-references/index.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ rspackOnlyTest(
55
'tsconfig paths should work with references',
66
async ({ page }) => {
77
const rsbuild = await build({
8-
cwd: __dirname,
8+
cwd: import.meta.dirname,
99
page,
1010
rsbuildConfig: {
1111
resolve: {

e2e/cases/alias/tsconfig-paths-specify-config/index.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ test('tsconfig paths should work and override the alias config', async ({
55
page,
66
}) => {
77
const rsbuild = await build({
8-
cwd: __dirname,
8+
cwd: import.meta.dirname,
99
page,
1010
});
1111

e2e/cases/alias/tsconfig-paths/index.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ test('tsconfig paths should work and override the alias config', async ({
55
page,
66
}) => {
77
const rsbuild = await build({
8-
cwd: __dirname,
8+
cwd: import.meta.dirname,
99
page,
1010
rsbuildConfig: {
1111
resolve: {
@@ -26,7 +26,7 @@ test('tsconfig paths should not work when aliasStrategy is "prefer-alias"', asyn
2626
page,
2727
}) => {
2828
const rsbuild = await build({
29-
cwd: __dirname,
29+
cwd: import.meta.dirname,
3030
page,
3131
rsbuildConfig: {
3232
resolve: {

e2e/cases/assets/addtional-assets/index.test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function isIncludeFile(filenames: string[], includeFilename: string) {
88

99
test('should allow to configure additional assets and match by RegExp', async () => {
1010
const rsbuild = await build({
11-
cwd: __dirname,
11+
cwd: import.meta.dirname,
1212
rsbuildConfig: {
1313
source: {
1414
assetsInclude: [/\.json5$/],
@@ -32,10 +32,10 @@ test('should allow to configure additional assets and match by RegExp', async ()
3232

3333
test('should allow to configure additional assets and match by path', async () => {
3434
const rsbuild = await build({
35-
cwd: __dirname,
35+
cwd: import.meta.dirname,
3636
rsbuildConfig: {
3737
source: {
38-
assetsInclude: path.resolve(__dirname, 'src/assets'),
38+
assetsInclude: path.resolve(import.meta.dirname, 'src/assets'),
3939
},
4040
},
4141
});
@@ -56,7 +56,7 @@ test('should allow to configure additional assets and match by path', async () =
5656

5757
test('should allow to disable emit for additional assets', async () => {
5858
const rsbuild = await build({
59-
cwd: __dirname,
59+
cwd: import.meta.dirname,
6060
rsbuildConfig: {
6161
source: {
6262
assetsInclude: [/\.json5$/],

e2e/cases/assets/addtional-assets/rsbuild.config.ts e2e/cases/assets/addtional-assets/rsbuild.config.mjs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { join } from 'node:path';
22
import { defineConfig } from '@rsbuild/core';
3-
import { outputFileSync } from 'fs-extra';
3+
import fse from 'fs-extra';
44

5-
outputFileSync(
6-
join(__dirname, 'src/assets/test-temp-small.json5'),
5+
fse.outputFileSync(
6+
join(import.meta.dirname, 'src/assets/test-temp-small.json5'),
77
JSON.stringify({ a: 1 }),
88
);
9-
outputFileSync(
10-
join(__dirname, 'src/assets/test-temp-large.json5'),
9+
fse.outputFileSync(
10+
join(import.meta.dirname, 'src/assets/test-temp-large.json5'),
1111
JSON.stringify({ a: '1'.repeat(10000) }),
1212
);
1313

e2e/cases/assets/asset-prefix/index.test.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { expect, test } from '@playwright/test';
33

44
test('should allow dev.assetPrefix to be `auto`', async ({ page }) => {
55
const rsbuild = await dev({
6-
cwd: __dirname,
6+
cwd: import.meta.dirname,
77
page,
88
rsbuildConfig: {
99
dev: {
@@ -23,7 +23,7 @@ test('should allow dev.assetPrefix to be `auto`', async ({ page }) => {
2323

2424
test('should allow dev.assetPrefix to be true', async ({ page }) => {
2525
const rsbuild = await dev({
26-
cwd: __dirname,
26+
cwd: import.meta.dirname,
2727
page,
2828
rsbuildConfig: {
2929
dev: {
@@ -41,7 +41,7 @@ test('should allow dev.assetPrefix to have <port> placeholder', async ({
4141
page,
4242
}) => {
4343
const rsbuild = await dev({
44-
cwd: __dirname,
44+
cwd: import.meta.dirname,
4545
page,
4646
rsbuildConfig: {
4747
dev: {
@@ -61,7 +61,7 @@ test('should allow dev.assetPrefix to have <port> placeholder', async ({
6161

6262
test('should allow output.assetPrefix to be `auto`', async ({ page }) => {
6363
const rsbuild = await build({
64-
cwd: __dirname,
64+
cwd: import.meta.dirname,
6565
page,
6666
rsbuildConfig: {
6767
output: {
@@ -79,7 +79,7 @@ test('should inject assetPrefix to env var and template correctly', async ({
7979
page,
8080
}) => {
8181
const rsbuild = await build({
82-
cwd: __dirname,
82+
cwd: import.meta.dirname,
8383
page,
8484
rsbuildConfig: {
8585
html: {

e2e/cases/assets/assets-inline-auto/index.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { pluginReact } from '@rsbuild/plugin-react';
44

55
test('should inline small assets automatically', async ({ page }) => {
66
const rsbuild = await build({
7-
cwd: __dirname,
7+
cwd: import.meta.dirname,
88
page,
99
plugins: [pluginReact()],
1010
});

e2e/cases/assets/assets-inline-false/index.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ test('should allow to disable assets inline with `?__inline=false`', async ({
66
page,
77
}) => {
88
const rsbuild = await build({
9-
cwd: __dirname,
9+
cwd: import.meta.dirname,
1010
page,
1111
plugins: [pluginReact()],
1212
});

e2e/cases/assets/assets-inline/index.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { pluginReact } from '@rsbuild/plugin-react';
44

55
test('should allow to inline assets with `?inline`', async ({ page }) => {
66
const rsbuild = await build({
7-
cwd: __dirname,
7+
cwd: import.meta.dirname,
88
page,
99
plugins: [pluginReact()],
1010
});

e2e/cases/assets/assets-retry/helper.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export async function createRsbuildWithMiddleware(
8080
assetPrefix?: string,
8181
) {
8282
const rsbuild = await dev({
83-
cwd: __dirname,
83+
cwd: import.meta.dirname,
8484
rsbuildConfig: {
8585
plugins: [pluginReact(), pluginAssetsRetry(options)],
8686
dev: {

e2e/cases/assets/assets-url/index.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { expect, test } from '@playwright/test';
33

44
test('should allow to get assets URL with `?url`', async ({ page }) => {
55
const rsbuild = await build({
6-
cwd: __dirname,
6+
cwd: import.meta.dirname,
77
page,
88
});
99

e2e/cases/assets/custom-dist-path/index.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { expect, test } from '@playwright/test';
33

44
test('should allow to custom dist path of different files', async () => {
55
const rsbuild = await build({
6-
cwd: __dirname,
6+
cwd: import.meta.dirname,
77
});
88

99
const files = await rsbuild.unwrapOutputJSON();

e2e/cases/assets/emit-assets/index.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function isIncludeFile(filenames: string[], includeFilename: string) {
77

88
test('should allow to disable emit assets for node target', async () => {
99
const rsbuild = await build({
10-
cwd: __dirname,
10+
cwd: import.meta.dirname,
1111
});
1212

1313
const files = await rsbuild.unwrapOutputJSON();
@@ -22,7 +22,7 @@ test('should allow to disable emit assets for node target', async () => {
2222

2323
test('should allow to disable emit assets for json assets', async () => {
2424
const rsbuild = await build({
25-
cwd: __dirname,
25+
cwd: import.meta.dirname,
2626
});
2727

2828
const files = await rsbuild.unwrapOutputJSON();

e2e/cases/assets/filename-function/index.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { expect, test } from '@playwright/test';
33

44
test('should allow to custom filename by function', async () => {
55
const rsbuild = await build({
6-
cwd: __dirname,
6+
cwd: import.meta.dirname,
77
});
88

99
const files = await rsbuild.unwrapOutputJSON();

e2e/cases/assets/filename-hash/index.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { expect } from '@playwright/test';
33

44
rspackOnlyTest('should allow to set hash format to fullhash', async () => {
55
const rsbuild = await build({
6-
cwd: __dirname,
6+
cwd: import.meta.dirname,
77
});
88

99
const files = await rsbuild.unwrapOutputJSON();

e2e/cases/assets/filename-template-path/index.test.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@ import { expect, test } from '@playwright/test';
33

44
test('should allow filename.image: "[path]"', async () => {
55
const rsbuild = await build({
6-
cwd: __dirname,
6+
cwd: import.meta.dirname,
77
});
88
const files = await rsbuild.unwrapOutputJSON();
99
const filenames = Object.keys(files);
1010
// Image
1111
expect(
12-
filenames.some((filename) =>
13-
filename.includes('dist/src/assets/icon.png'),
14-
),
12+
filenames.some((filename) => filename.includes('dist/src/assets/icon.png')),
1513
).toBeTruthy();
1614
});

e2e/cases/assets/import-json/index.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { expect } from '@playwright/test';
33

44
rspackOnlyTest('should import JSON correctly', async ({ page }) => {
55
const rsbuild = await build({
6-
cwd: __dirname,
6+
cwd: import.meta.dirname,
77
page,
88
});
99

e2e/cases/assets/script-as-assets/index.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ rspackOnlyTest(
55
'should allow to use `new URL` to reference script as assets',
66
async ({ page }) => {
77
const rsbuild = await build({
8-
cwd: __dirname,
8+
cwd: import.meta.dirname,
99
page,
1010
});
1111

e2e/cases/assets/styles-as-assets/index.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ rspackOnlyTest(
55
'should allow to use `new URL` to reference styles as assets',
66
async ({ page }) => {
77
const rsbuild = await build({
8-
cwd: __dirname,
8+
cwd: import.meta.dirname,
99
page,
1010
});
1111

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

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1+
import { createRequire } from 'node:module';
12
import { build, rspackOnlyTest } from '@e2e/helper';
23
import { expect } from '@playwright/test';
34
import { pluginBabel } from '@rsbuild/plugin-babel';
45

6+
const require = createRequire(import.meta.url);
7+
58
rspackOnlyTest(
69
'should run babel with babel plugin correctly',
710
async ({ page }) => {
811
const rsbuild = await build({
9-
cwd: __dirname,
12+
cwd: import.meta.dirname,
1013
page,
1114
plugins: [
1215
pluginBabel({
1316
babelLoaderOptions: (_, { addPlugins }) => {
14-
addPlugins([require('./plugins/myBabelPlugin')]);
17+
addPlugins([require('./plugins/myBabelPlugin.cjs')]);
1518
},
1619
}),
1720
],
@@ -27,7 +30,7 @@ rspackOnlyTest(
2730
'should allow to exclude file from babel transformation',
2831
async ({ page }) => {
2932
const rsbuild = await build({
30-
cwd: __dirname,
33+
cwd: import.meta.dirname,
3134
page,
3235
rsbuildConfig: {
3336
source: {
@@ -37,7 +40,7 @@ rspackOnlyTest(
3740
plugins: [
3841
pluginBabel({
3942
babelLoaderOptions: (_, { addPlugins }) => {
40-
addPlugins([require('./plugins/myBabelPlugin')]);
43+
addPlugins([require('./plugins/myBabelPlugin.cjs')]);
4144
},
4245
}),
4346
],

e2e/cases/babel/decorator/index.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ rspackOnlyTest(
66
'should support legacy decorators and source.decorators.version in TypeScript',
77
async ({ page }) => {
88
const rsbuild = await build({
9-
cwd: __dirname,
9+
cwd: import.meta.dirname,
1010
page,
1111
plugins: [pluginBabel()],
1212
});
@@ -22,7 +22,7 @@ rspackOnlyTest(
2222
'should support legacy decorators and source.decorators.version in JavaScript',
2323
async ({ page }) => {
2424
const rsbuild = await build({
25-
cwd: __dirname,
25+
cwd: import.meta.dirname,
2626
page,
2727
plugins: [pluginBabel()],
2828
rsbuildConfig: {
+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"private": true,
33
"name": "@e2e/babel-decorator",
4+
"type": "module",
45
"version": "1.0.0"
56
}

e2e/cases/browserslist/browserslist-config-mock/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
"private": true,
33
"name": "@e2e/browserslist-config-mock",
44
"version": "1.0.0",
5+
"type": "module",
56
"main": "index.json"
67
}

e2e/cases/browserslist/extends-browserslist/index.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import { expect, test } from '@playwright/test';
33

44
test('extends browserslist and downgrade the syntax', async () => {
55
const originalCwd = process.cwd();
6-
process.chdir(__dirname);
6+
process.chdir(import.meta.dirname);
77

88
const rsbuild = await build({
9-
cwd: __dirname,
9+
cwd: import.meta.dirname,
1010
});
1111

1212
const files = await rsbuild.unwrapOutputJSON();

e2e/cases/browserslist/extends-browserslist/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"private": true,
33
"name": "@e2e/extends-browserslist",
44
"version": "1.0.0",
5+
"type": "module",
56
"dependencies": {
67
"@e2e/browserslist-config-mock": "workspace:*"
78
},

0 commit comments

Comments
 (0)