Skip to content

Commit

Permalink
test(e2e): increase timeout limit (#4411)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan authored Jan 22, 2025
1 parent a4cf056 commit 4a7a29e
Show file tree
Hide file tree
Showing 21 changed files with 401 additions and 331 deletions.
6 changes: 3 additions & 3 deletions e2e/cases/cli/basic/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { execSync } from 'node:child_process';
import path from 'node:path';
import { globContentJSON } from '@e2e/helper';
import { expect, test } from '@playwright/test';
import { globContentJSON, rspackOnlyTest } from '@e2e/helper';
import { expect } from '@playwright/test';

test('should run build command correctly', async () => {
rspackOnlyTest('should run build command correctly', async () => {
execSync('npx rsbuild build', {
cwd: __dirname,
});
Expand Down
6 changes: 3 additions & 3 deletions e2e/cases/cli/build-watch/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { exec } from 'node:child_process';
import fs from 'node:fs';
import path from 'node:path';
import { awaitFileExists } from '@e2e/helper';
import { expect, test } from '@playwright/test';
import { awaitFileExists, rspackOnlyTest } from '@e2e/helper';
import { expect } from '@playwright/test';
import fse from 'fs-extra';

test('should support watch mode for build command', async () => {
rspackOnlyTest('should support watch mode for build command', async () => {
const indexFile = path.join(__dirname, 'src/index.js');
const distIndexFile = path.join(__dirname, 'dist/static/js/index.js');
fs.rmSync(indexFile, { force: true });
Expand Down
44 changes: 25 additions & 19 deletions e2e/cases/cli/custom-config/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
import { execSync } from 'node:child_process';
import path from 'node:path';
import { globContentJSON } from '@e2e/helper';
import { expect, test } from '@playwright/test';
import { globContentJSON, rspackOnlyTest } from '@e2e/helper';
import { expect } from '@playwright/test';

test('should use custom config when using --config option', async () => {
execSync('npx rsbuild build --config ./custom.config.mjs', {
cwd: __dirname,
});
rspackOnlyTest(
'should use custom config when using --config option',
async () => {
execSync('npx rsbuild build --config ./custom.config.mjs', {
cwd: __dirname,
});

const outputs = await globContentJSON(path.join(__dirname, 'dist-custom'));
const outputFiles = Object.keys(outputs);
const outputs = await globContentJSON(path.join(__dirname, 'dist-custom'));
const outputFiles = Object.keys(outputs);

expect(outputFiles.length > 1).toBeTruthy();
});
expect(outputFiles.length > 1).toBeTruthy();
},
);

test('should support custom config to find absolute path', async () => {
const absPath = path.join(__dirname, 'custom.config.mjs');
execSync(`npx rsbuild build --config ${absPath}`, {
cwd: __dirname,
});
const outputs = await globContentJSON(path.join(__dirname, 'dist-custom'));
const outputFiles = Object.keys(outputs);
rspackOnlyTest(
'should support custom config to find absolute path',
async () => {
const absPath = path.join(__dirname, 'custom.config.mjs');
execSync(`npx rsbuild build --config ${absPath}`, {
cwd: __dirname,
});
const outputs = await globContentJSON(path.join(__dirname, 'dist-custom'));
const outputFiles = Object.keys(outputs);

expect(outputFiles.length > 1).toBeTruthy();
});
expect(outputFiles.length > 1).toBeTruthy();
},
);
5 changes: 3 additions & 2 deletions e2e/cases/cli/custom-env-dir/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { execSync } from 'node:child_process';
import fs from 'node:fs';
import path from 'node:path';
import { expect, test } from '@playwright/test';
import { rspackOnlyTest } from '@e2e/helper';
import { expect } from '@playwright/test';

test('should allow to custom env directory', async () => {
rspackOnlyTest('should allow to custom env directory', async () => {
execSync('npx rsbuild build --env-dir env', {
cwd: __dirname,
});
Expand Down
28 changes: 16 additions & 12 deletions e2e/cases/cli/custom-env-prefix/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import { execSync } from 'node:child_process';
import fs from 'node:fs';
import path from 'node:path';
import { expect, test } from '@playwright/test';
import { rspackOnlyTest } from '@e2e/helper';
import { expect } from '@playwright/test';

test('should allow to custom env prefix via loadEnv method', async () => {
execSync('npx rsbuild build', {
cwd: __dirname,
});
const content = fs.readFileSync(
path.join(__dirname, 'dist/static/js/index.js'),
'utf-8',
);
expect(content).not.toContain('jack');
expect(content).toContain('rose');
});
rspackOnlyTest(
'should allow to custom env prefix via loadEnv method',
async () => {
execSync('npx rsbuild build', {
cwd: __dirname,
});
const content = fs.readFileSync(
path.join(__dirname, 'dist/static/js/index.js'),
'utf-8',
);
expect(content).not.toContain('jack');
expect(content).toContain('rose');
},
);
6 changes: 3 additions & 3 deletions e2e/cases/cli/falsy-plugins/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { execSync } from 'node:child_process';
import path from 'node:path';
import { globContentJSON } from '@e2e/helper';
import { expect, test } from '@playwright/test';
import { globContentJSON, rspackOnlyTest } from '@e2e/helper';
import { expect } from '@playwright/test';

test('should run build command correctly', async () => {
rspackOnlyTest('should run build command correctly', async () => {
execSync('npx rsbuild build', {
cwd: __dirname,
});
Expand Down
6 changes: 3 additions & 3 deletions e2e/cases/cli/function-config/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { execSync } from 'node:child_process';
import fs from 'node:fs';
import path from 'node:path';
import { globContentJSON } from '@e2e/helper';
import { expect, test } from '@playwright/test';
import { globContentJSON, rspackOnlyTest } from '@e2e/helper';
import { expect } from '@playwright/test';

test('should allow to export function in config file', async () => {
rspackOnlyTest('should allow to export function in config file', async () => {
const targetDir = path.join(__dirname, 'dist-production-build');

fs.rmSync(targetDir, { recursive: true, force: true });
Expand Down
74 changes: 40 additions & 34 deletions e2e/cases/cli/inspect/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { execSync } from 'node:child_process';
import path from 'node:path';
import { globContentJSON } from '@e2e/helper';
import { expect, test } from '@playwright/test';
import { globContentJSON, rspackOnlyTest } from '@e2e/helper';
import { expect } from '@playwright/test';
import { removeSync } from 'fs-extra';

const clean = () => {
removeSync(path.join(__dirname, 'dist'));
delete process.env.NODE_ENV;
};

test('should run inspect command correctly', async () => {
rspackOnlyTest('should run inspect command correctly', async () => {
clean();

execSync('npx rsbuild inspect', {
Expand All @@ -34,42 +34,48 @@ test('should run inspect command correctly', async () => {
expect(files[rspackConfig!]).toContain("mode: 'development'");
});

test('should run inspect command with mode option correctly', async () => {
clean();
rspackOnlyTest(
'should run inspect command with mode option correctly',
async () => {
clean();

execSync('npx rsbuild inspect --mode production', {
cwd: __dirname,
});
execSync('npx rsbuild inspect --mode production', {
cwd: __dirname,
});

const files = await globContentJSON(path.join(__dirname, 'dist/.rsbuild'));
const fileNames = Object.keys(files);
const files = await globContentJSON(path.join(__dirname, 'dist/.rsbuild'));
const fileNames = Object.keys(files);

const rsbuildConfig = fileNames.find((item) =>
item.includes('rsbuild.config.mjs'),
);
expect(rsbuildConfig).toBeTruthy();
const rsbuildConfig = fileNames.find((item) =>
item.includes('rsbuild.config.mjs'),
);
expect(rsbuildConfig).toBeTruthy();

const rspackConfig = fileNames.find((item) =>
item.includes('rspack.config.web.mjs'),
);
expect(rspackConfig).toBeTruthy();
expect(files[rspackConfig!]).toContain("mode: 'production'");
});
const rspackConfig = fileNames.find((item) =>
item.includes('rspack.config.web.mjs'),
);
expect(rspackConfig).toBeTruthy();
expect(files[rspackConfig!]).toContain("mode: 'production'");
},
);

test('should run inspect command with output option correctly', async () => {
clean();
rspackOnlyTest(
'should run inspect command with output option correctly',
async () => {
clean();

execSync('npx rsbuild inspect --output foo', {
cwd: __dirname,
});
execSync('npx rsbuild inspect --output foo', {
cwd: __dirname,
});

const outputs = await globContentJSON(path.join(__dirname, 'dist/foo'));
const outputFiles = Object.keys(outputs);
const outputs = await globContentJSON(path.join(__dirname, 'dist/foo'));
const outputFiles = Object.keys(outputs);

expect(
outputFiles.find((item) => item.includes('rsbuild.config.mjs')),
).toBeTruthy();
expect(
outputFiles.find((item) => item.includes('rspack.config.web.mjs')),
).toBeTruthy();
});
expect(
outputFiles.find((item) => item.includes('rsbuild.config.mjs')),
).toBeTruthy();
expect(
outputFiles.find((item) => item.includes('rspack.config.web.mjs')),
).toBeTruthy();
},
);
41 changes: 24 additions & 17 deletions e2e/cases/cli/load-import-meta-env/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { execSync } from 'node:child_process';
import fs from 'node:fs';
import path from 'node:path';
import { rspackOnlyTest } from '@e2e/helper';
import { expect, test } from '@playwright/test';
import fse from 'fs-extra';

Expand All @@ -12,14 +13,17 @@ test.beforeEach(() => {
fs.rmSync(prodLocalFile, { force: true });
});

test('should load .env config and allow rsbuild.config.ts to read env vars', async () => {
execSync('npx rsbuild build', {
cwd: __dirname,
});
expect(fs.existsSync(path.join(__dirname, 'dist/1'))).toBeTruthy();
});

test('should load .env.local with higher priority', async () => {
rspackOnlyTest(
'should load .env config and allow rsbuild.config.ts to read env vars',
async () => {
execSync('npx rsbuild build', {
cwd: __dirname,
});
expect(fs.existsSync(path.join(__dirname, 'dist/1'))).toBeTruthy();
},
);

rspackOnlyTest('should load .env.local with higher priority', async () => {
fse.outputFileSync(localFile, 'FOO=2');

execSync('npx rsbuild build', {
Expand All @@ -28,17 +32,20 @@ test('should load .env.local with higher priority', async () => {
expect(fs.existsSync(path.join(__dirname, 'dist/2'))).toBeTruthy();
});

test('should load .env.production.local with higher priority', async () => {
fse.outputFileSync(localFile, 'FOO=2');
fse.outputFileSync(prodLocalFile, 'FOO=3');
rspackOnlyTest(
'should load .env.production.local with higher priority',
async () => {
fse.outputFileSync(localFile, 'FOO=2');
fse.outputFileSync(prodLocalFile, 'FOO=3');

execSync('npx rsbuild build', {
cwd: __dirname,
});
expect(fs.existsSync(path.join(__dirname, 'dist/3'))).toBeTruthy();
});
execSync('npx rsbuild build', {
cwd: __dirname,
});
expect(fs.existsSync(path.join(__dirname, 'dist/3'))).toBeTruthy();
},
);

test('should allow to specify env mode via --env-mode', async () => {
rspackOnlyTest('should allow to specify env mode via --env-mode', async () => {
execSync('npx rsbuild build --env-mode test', {
cwd: __dirname,
});
Expand Down
20 changes: 13 additions & 7 deletions e2e/cases/cli/load-node-env/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import { execSync } from 'node:child_process';
import fs from 'node:fs';
import path from 'node:path';
import { expect, test } from '@playwright/test';
import { rspackOnlyTest } from '@e2e/helper';
import { expect } from '@playwright/test';

// see: https://github.com/web-infra-dev/rsbuild/issues/2904
test('should load .env config and set NODE_ENV as expected', async () => {
execSync('npx rsbuild build', {
cwd: __dirname,
});
expect(fs.existsSync(path.join(__dirname, 'dist/development'))).toBeTruthy();
});
rspackOnlyTest(
'should load .env config and set NODE_ENV as expected',
async () => {
execSync('npx rsbuild build', {
cwd: __dirname,
});
expect(
fs.existsSync(path.join(__dirname, 'dist/development')),
).toBeTruthy();
},
);
Loading

1 comment on commit 4a7a29e

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Ran ecosystem CI: Open

suite result
modernjs ❌ failure
plugins ✅ success
rspress ✅ success
rslib ✅ success
examples ✅ success

Please sign in to comment.