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
5 changes: 3 additions & 2 deletions e2e/assets/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "@e2e/assets",
"description": "Common static assets used in E2E test cases.",
"version": "1.0.0",
"private": true,
"version": "1.0.0"
"description": "Common static assets used in E2E test cases.",
"type": "module"
}
2 changes: 1 addition & 1 deletion e2e/cases/assets/addtional-assets/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ test('should support configuring additional assets matched by path', async ({
const rsbuild = await build({
config: {
source: {
assetsInclude: path.resolve(__dirname, 'src/assets'),
assetsInclude: path.resolve(import.meta.dirname, 'src/assets'),
},
},
});
Expand Down
10 changes: 5 additions & 5 deletions e2e/cases/assets/addtional-assets/rsbuild.config.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { join } from 'node:path';
import { defineConfig } from '@rsbuild/core';
import { outputFileSync } from 'fs-extra';
import fse from 'fs-extra';

outputFileSync(
join(__dirname, 'src/assets/test-temp-small.json5'),
fse.outputFileSync(
join(import.meta.dirname, 'src/assets/test-temp-small.json5'),
JSON.stringify({ a: 1 }),
);
outputFileSync(
join(__dirname, 'src/assets/test-temp-large.json5'),
fse.outputFileSync(
join(import.meta.dirname, 'src/assets/test-temp-large.json5'),
JSON.stringify({ a: '1'.repeat(10000) }),
);

Expand Down
4 changes: 2 additions & 2 deletions e2e/cases/assets/import-json-raw-query/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ rspackTest(
await buildPreview();

expect(await page.evaluate('window.a')).toBe(
readFileSync(join(__dirname, './src/a.json'), 'utf-8'),
readFileSync(join(import.meta.dirname, './src/a.json'), 'utf-8'),
);
expect(await page.evaluate('window.b')).toBe(
readFileSync(join(__dirname, './src/b.json'), 'utf-8'),
readFileSync(join(import.meta.dirname, './src/b.json'), 'utf-8'),
);
},
);
12 changes: 6 additions & 6 deletions e2e/cases/assets/raw-query/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ test('should return raw asset content with `?raw` in dev', async ({

expect(await page.evaluate('window.rawSvg')).toEqual(
await promises.readFile(
join(__dirname, '../../../assets/circle.svg'),
join(import.meta.dirname, '../../../assets/circle.svg'),
'utf-8',
),
);
Expand All @@ -26,7 +26,7 @@ test('should return raw asset content with `?raw` in build', async ({

expect(await page.evaluate('window.rawSvg')).toEqual(
await promises.readFile(
join(__dirname, '../../../assets/circle.svg'),
join(import.meta.dirname, '../../../assets/circle.svg'),
'utf-8',
),
);
Expand All @@ -44,7 +44,7 @@ test('should return raw SVG content with `?raw` when using pluginSvgr', async ({

expect(await page.evaluate('window.rawSvg')).toEqual(
await promises.readFile(
join(__dirname, '../../../assets/circle.svg'),
join(import.meta.dirname, '../../../assets/circle.svg'),
'utf-8',
),
);
Expand All @@ -54,15 +54,15 @@ test('should return raw JS content with `?raw`', async ({ page, dev }) => {
await dev();

expect(await page.evaluate('window.rawJs')).toEqual(
await promises.readFile(join(__dirname, 'src/foo.js'), 'utf-8'),
await promises.readFile(join(import.meta.dirname, 'src/foo.js'), 'utf-8'),
);
});

test('should return raw TS content with `?raw`', async ({ page, dev }) => {
await dev();

const tsContent = await promises.readFile(
join(__dirname, 'src/bar.ts'),
join(import.meta.dirname, 'src/bar.ts'),
'utf-8',
);
expect(await page.evaluate('window.rawTs1')).toEqual(tsContent);
Expand All @@ -82,7 +82,7 @@ test('should return raw TSX content with `?raw` when using pluginReact', async (
});

expect(await page.evaluate('window.rawTsx')).toEqual(
await promises.readFile(join(__dirname, 'src/baz.tsx'), 'utf-8'),
await promises.readFile(join(import.meta.dirname, 'src/baz.tsx'), 'utf-8'),
);
});

Expand Down
2 changes: 1 addition & 1 deletion e2e/cases/browser-logs/custom-source-map/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ rspackTest(
rspackTest(
'should parse source map correctly if source path is relative to source map path',
async ({ dev }) => {
const sourceMapPath = join(__dirname, 'dist/static/js');
const sourceMapPath = join(import.meta.dirname, 'dist/static/js');
const rsbuild = await dev({
config: {
tools: {
Expand Down
3 changes: 2 additions & 1 deletion e2e/cases/browserslist/browserslist-config-mock/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"private": true,
"name": "@e2e/browserslist-config-mock",
"version": "1.0.0",
"private": true,
"type": "module",
"main": "index.json"
}
2 changes: 1 addition & 1 deletion e2e/cases/browserslist/extends-browserslist/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { expect, getFileContent, test } from '@e2e/helper';

test('should extend browserslist and downgrade syntax', async ({ build }) => {
const originalCwd = process.cwd();
process.chdir(__dirname);
process.chdir(import.meta.dirname);

const rsbuild = await build();
const files = rsbuild.getDistFiles();
Expand Down
11 changes: 6 additions & 5 deletions e2e/cases/browserslist/extends-browserslist/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"private": true,
"name": "@e2e/extends-browserslist",
"version": "1.0.0",
"dependencies": {
"@e2e/browserslist-config-mock": "workspace:*"
},
"private": true,
"type": "module",
"browserslist": [
"extends @e2e/browserslist-config-mock"
]
],
"dependencies": {
"@e2e/browserslist-config-mock": "workspace:*"
}
}
1 change: 1 addition & 0 deletions e2e/cases/browserslist/package-config-array/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"private": true,
"type": "module",
"browserslist": "Chrome >= 40, Edge >= 79"
}
1 change: 1 addition & 0 deletions e2e/cases/browserslist/package-config-object/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"private": true,
"type": "module",
"browserslist": {
"production": [
"Chrome >= 40",
Expand Down
1 change: 1 addition & 0 deletions e2e/cases/browserslist/package-config-string/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"private": true,
"type": "module",
"browserslist": [
"Chrome >= 40",
"Edge >= 79"
Expand Down
8 changes: 4 additions & 4 deletions e2e/cases/cache/build-dependencies/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ import path from 'node:path';

import { expect, test } from '@e2e/helper';
import type { RsbuildConfig } from '@rsbuild/core';
import { remove } from 'fs-extra';
import fse from 'fs-extra';

test('should respect `buildCache.buildDependencies`', async ({ build }) => {
const cacheDirectory = path.resolve(
__dirname,
import.meta.dirname,
'./node_modules/.cache/test-cache-build-dependencies',
);

const testDepsPath = path.resolve(__dirname, './test-temp-deps.js');
const testDepsPath = path.resolve(import.meta.dirname, './test-temp-deps.js');

await remove(cacheDirectory);
await fse.remove(cacheDirectory);

const getBuildConfig = (input: string) => {
fs.writeFileSync(testDepsPath, input);
Expand Down
6 changes: 3 additions & 3 deletions e2e/cases/cache/cache-digest/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import path from 'node:path';

import { expect, test } from '@e2e/helper';
import type { RsbuildConfig } from '@rsbuild/core';
import { remove } from 'fs-extra';
import fse from 'fs-extra';

test('should respect `buildCache.cacheDigest`', async ({ build }) => {
const cacheDirectory = path.resolve(
__dirname,
import.meta.dirname,
'./node_modules/.cache/test-cache-digest',
);

await remove(cacheDirectory);
await fse.remove(cacheDirectory);

const getBuildConfig = (input: string) => ({
config: {
Expand Down
30 changes: 21 additions & 9 deletions e2e/cases/cache/cache-directory/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import fs from 'node:fs';
import path from 'node:path';
import { expect, test } from '@e2e/helper';
import { remove } from 'fs-extra';
import fse from 'fs-extra';

test('should use `buildCache.cacheDirectory` as expected in dev', async ({
dev,
}) => {
const defaultDirectory = path.resolve(__dirname, './node_modules/.cache');
const cacheDirectory = path.resolve(__dirname, './node_modules/.cache2');
await remove(defaultDirectory);
await remove(cacheDirectory);
const defaultDirectory = path.resolve(
import.meta.dirname,
'./node_modules/.cache',
);
const cacheDirectory = path.resolve(
import.meta.dirname,
'./node_modules/.cache2',
);
await fse.remove(defaultDirectory);
await fse.remove(cacheDirectory);

await dev({
config: {
Expand All @@ -28,10 +34,16 @@ test('should use `buildCache.cacheDirectory` as expected in dev', async ({
test('should use `buildCache.cacheDirectory` as expected in build', async ({
build,
}) => {
const defaultDirectory = path.resolve(__dirname, './node_modules/.cache');
const cacheDirectory = path.resolve(__dirname, './node_modules/.cache2');
await remove(defaultDirectory);
await remove(cacheDirectory);
const defaultDirectory = path.resolve(
import.meta.dirname,
'./node_modules/.cache',
);
const cacheDirectory = path.resolve(
import.meta.dirname,
'./node_modules/.cache2',
);
await fse.remove(defaultDirectory);
await fse.remove(cacheDirectory);

await build({
config: {
Expand Down
2 changes: 1 addition & 1 deletion e2e/cases/cli/base/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { expect, readDirContents, rspackTest } from '@e2e/helper';
rspackTest('should run allow to specify base path', async ({ execCliSync }) => {
execCliSync('build --base /test');

const outputs = await readDirContents(path.join(__dirname, 'dist'));
const outputs = await readDirContents(path.join(import.meta.dirname, 'dist'));
const outputFiles = Object.keys(outputs);

expect(
Expand Down
5 changes: 4 additions & 1 deletion e2e/cases/cli/build-watch-options/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ rspackTest(
'should allow to custom watch options for build watch',
async ({ execCli, logHelper, copySrcDir }) => {
const tempSrc = await copySrcDir();
const distIndexFile = path.join(__dirname, 'dist/static/js/index.js');
const distIndexFile = path.join(
import.meta.dirname,
'dist/static/js/index.js',
);
const fooFile = path.join(tempSrc, 'foo.js');
const barFile = path.join(tempSrc, 'bar.js');

Expand Down
12 changes: 9 additions & 3 deletions e2e/cases/cli/build-watch-restart/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@ import fse from 'fs-extra';
rspackTest(
'should support restart build when config changed',
async ({ execCli, logHelper }) => {
const indexFile = path.join(__dirname, 'src/index.js');
const distIndexFile = path.join(__dirname, 'dist/static/js/index.js');
const tempConfig = path.join(__dirname, 'test-temp-rsbuild.config.mjs');
const indexFile = path.join(import.meta.dirname, 'src/index.js');
const distIndexFile = path.join(
import.meta.dirname,
'dist/static/js/index.js',
);
const tempConfig = path.join(
import.meta.dirname,
'test-temp-rsbuild.config.mjs',
);

fse.outputFileSync(indexFile, `console.log('hello!');`);
fse.outputFileSync(
Expand Down
7 changes: 5 additions & 2 deletions e2e/cases/cli/build-watch/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ import fse from 'fs-extra';
rspackTest(
'should support watch mode for build command',
async ({ execCli, logHelper }) => {
const indexFile = path.join(__dirname, 'src/index.js');
const distIndexFile = path.join(__dirname, 'dist/static/js/index.js');
const indexFile = path.join(import.meta.dirname, 'src/index.js');
const distIndexFile = path.join(
import.meta.dirname,
'dist/static/js/index.js',
);

fse.outputFileSync(indexFile, `console.log('hello!');`);

Expand Down
2 changes: 1 addition & 1 deletion e2e/cases/cli/build/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { expect, readDirContents, rspackTest } from '@e2e/helper';
rspackTest('should run build command correctly', async ({ execCliSync }) => {
execCliSync('build');

const outputs = await readDirContents(path.join(__dirname, 'dist'));
const outputs = await readDirContents(path.join(import.meta.dirname, 'dist'));
const outputFiles = Object.keys(outputs);

expect(outputFiles.find((item) => item.includes('index.html'))).toBeTruthy();
Expand Down
8 changes: 6 additions & 2 deletions e2e/cases/cli/config-loader/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ rspackTest(
},
});

const outputs = await readDirContents(path.join(__dirname, 'dist-custom'));
const outputs = await readDirContents(
path.join(import.meta.dirname, 'dist-custom'),
);
const outputFiles = Object.keys(outputs);

expect(outputFiles.length > 1).toBeTruthy();
Expand All @@ -30,7 +32,9 @@ rspackTest(
},
});

const outputs = await readDirContents(path.join(__dirname, 'dist-auto'));
const outputs = await readDirContents(
path.join(import.meta.dirname, 'dist-auto'),
);
const outputFiles = Object.keys(outputs);

expect(outputFiles.length > 1).toBeTruthy();
Expand Down
10 changes: 7 additions & 3 deletions e2e/cases/cli/custom-config/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ rspackTest(
async ({ execCliSync }) => {
execCliSync('build --config ./custom.config.mjs');

const outputs = await readDirContents(path.join(__dirname, 'dist-custom'));
const outputs = await readDirContents(
path.join(import.meta.dirname, 'dist-custom'),
);
const outputFiles = Object.keys(outputs);

expect(outputFiles.length > 1).toBeTruthy();
Expand All @@ -16,9 +18,11 @@ rspackTest(
rspackTest(
'should support custom config to find absolute path',
async ({ execCliSync }) => {
const absPath = path.join(__dirname, 'custom.config.mjs');
const absPath = path.join(import.meta.dirname, 'custom.config.mjs');
execCliSync(`build --config ${absPath}`);
const outputs = await readDirContents(path.join(__dirname, 'dist-custom'));
const outputs = await readDirContents(
path.join(import.meta.dirname, 'dist-custom'),
);
const outputFiles = Object.keys(outputs);

expect(outputFiles.length > 1).toBeTruthy();
Expand Down
2 changes: 1 addition & 1 deletion e2e/cases/cli/custom-env-dir/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { expect, rspackTest } from '@e2e/helper';
rspackTest('should support a custom env directory', async ({ execCliSync }) => {
execCliSync('build --env-dir env');
const content = fs.readFileSync(
path.join(__dirname, 'dist/static/js/index.js'),
path.join(import.meta.dirname, 'dist/static/js/index.js'),
'utf-8',
);
expect(content).not.toContain('jack');
Expand Down
2 changes: 1 addition & 1 deletion e2e/cases/cli/custom-env-prefix/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ rspackTest(
async ({ execCliSync }) => {
execCliSync('build');
const content = fs.readFileSync(
path.join(__dirname, 'dist/static/js/index.js'),
path.join(import.meta.dirname, 'dist/static/js/index.js'),
'utf-8',
);
expect(content).not.toContain('jack');
Expand Down
2 changes: 1 addition & 1 deletion e2e/cases/cli/falsy-plugins/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { expect, readDirContents, rspackTest } from '@e2e/helper';
rspackTest('should run build command correctly', async ({ execCliSync }) => {
execCliSync('build');

const outputs = await readDirContents(path.join(__dirname, 'dist'));
const outputs = await readDirContents(path.join(import.meta.dirname, 'dist'));
const outputFiles = Object.keys(outputs);

expect(outputFiles.find((item) => item.includes('index.html'))).toBeTruthy();
Expand Down
Loading
Loading