Skip to content

Commit 53dd6af

Browse files
committed
fix: add tests/rspack
1 parent 0293d7c commit 53dd6af

File tree

14 files changed

+264
-1
lines changed

14 files changed

+264
-1
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
.DS_Store
22
.DS_Store?
33
node_modules
4-
rspack
54
workspace
65
.pnpm-debug.log
76
.idea

tests/rspack/_selftest.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import fs from 'node:fs';
2+
import path from 'node:path';
3+
import type { RunOptions } from '../../types';
4+
import { runInRepo } from '../../utils';
5+
6+
export async function test(options: RunOptions) {
7+
await runInRepo({
8+
...options,
9+
repo: 'web-infra-dev/rspack-ecosystem-ci',
10+
build: async () => {
11+
const dir = path.resolve(options.workspace, 'rspack-ecosystem-ci');
12+
const pkgFile = path.join(dir, 'package.json');
13+
const pkg = JSON.parse(await fs.promises.readFile(pkgFile, 'utf-8'));
14+
if (pkg.name !== 'rspack-ecosystem-ci') {
15+
throw new Error(
16+
`invalid checkout, expected package.json with "name":"rspack-ecosystem-ci" in ${dir}`,
17+
);
18+
}
19+
pkg.scripts.selftestscript =
20+
"[ -d ../../rspack/packages/rspack/dist ] || (echo 'rspack build failed' && exit 1)";
21+
await fs.promises.writeFile(
22+
pkgFile,
23+
JSON.stringify(pkg, null, 2),
24+
'utf-8',
25+
);
26+
},
27+
test: 'pnpm run selftestscript',
28+
verify: false,
29+
});
30+
}

tests/rspack/devserver.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import type { RunOptions } from '../../types';
2+
import { runInRepo } from '../../utils';
3+
4+
export async function test(options: RunOptions) {
5+
await runInRepo({
6+
...options,
7+
repo: 'web-infra-dev/rspack-dev-server',
8+
branch: 'main',
9+
test: ['test'],
10+
});
11+
}

tests/rspack/examples.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import type { RunOptions } from '../../types';
2+
import { runInRepo } from '../../utils';
3+
4+
export async function test(options: RunOptions) {
5+
await runInRepo({
6+
...options,
7+
repo: 'rspack-contrib/rspack-examples',
8+
branch: 'main',
9+
test: [
10+
'build:rspack',
11+
'test:rspack',
12+
'build:rsbuild',
13+
'build:rsdoctor',
14+
'build:rspress',
15+
'build:rslib',
16+
],
17+
});
18+
}

tests/rspack/lynx-stack.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { mkdtemp } from 'node:fs/promises';
2+
import { tmpdir } from 'node:os';
3+
import { join } from 'node:path';
4+
import type { RunOptions } from '../../types';
5+
import { runInRepo } from '../../utils';
6+
7+
export async function test(options: RunOptions) {
8+
const tmp = await mkdtemp(join(tmpdir(), 'lynx-stack-'));
9+
10+
await runInRepo({
11+
...options,
12+
workspace: tmp,
13+
repo: 'lynx-family/lynx-stack',
14+
branch: process.env.LYNX_STACK_REF ?? 'main',
15+
beforeBuild: 'rustup target add wasm32-unknown-unknown',
16+
// TODO(colinaaa): enable Lynx for Web tests
17+
build: 'pnpm turbo build',
18+
test: 'pnpm run test --silent',
19+
});
20+
}

tests/rspack/modernjs.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { join } from 'node:path';
2+
import cache from '@actions/cache';
3+
import type { RunOptions } from '../../types';
4+
import { $, cd, runInRepo } from '../../utils';
5+
6+
const isGitHubActions = !!process.env.GITHUB_ACTIONS;
7+
8+
export async function test(options: RunOptions) {
9+
let nxCachePath: string;
10+
let nxCacheKey: string;
11+
12+
await runInRepo({
13+
...options,
14+
repo: 'web-infra-dev/modern.js',
15+
branch: process.env.MODERN_REF ?? 'v2',
16+
beforeInstall: async () => {
17+
if (isGitHubActions) {
18+
const modernJsDir = join(process.cwd(), 'workspace/modernjs/modern.js');
19+
nxCachePath = join(modernJsDir, '.nx/cache');
20+
const sha = await $`git rev-parse HEAD`;
21+
nxCacheKey = `modernjs-nx-${sha.trim()}`;
22+
const restoreKeys = ['modernjs-nx-'];
23+
const cacheHitKey = await cache.restoreCache(
24+
[nxCachePath],
25+
nxCacheKey,
26+
restoreKeys,
27+
);
28+
if (cacheHitKey) {
29+
console.log(`Cache hit for key: ${cacheHitKey}`);
30+
await $`ls -lah .nx/cache`;
31+
} else {
32+
console.log(
33+
`Cache miss for key: ${nxCacheKey}, proceeding without cache.`,
34+
);
35+
}
36+
}
37+
},
38+
afterInstall: async () => {
39+
if (isGitHubActions) {
40+
console.log('Caching `.nx/cache` directory for future builds.');
41+
await $`ls -lah .nx/cache`;
42+
await cache.saveCache([nxCachePath], nxCacheKey);
43+
}
44+
},
45+
beforeTest: async () => {
46+
cd('tests/e2e/builder');
47+
await $`pnpm playwright install chromium`;
48+
cd('../../../');
49+
},
50+
test: ['test:rspack'],
51+
});
52+
}

tests/rspack/nuxt.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import type { RunOptions } from '../../types';
2+
import { $, execa, runInRepo } from '../../utils';
3+
4+
export async function test(options: RunOptions) {
5+
await runInRepo({
6+
...options,
7+
repo: 'nuxt/nuxt',
8+
branch: 'main',
9+
build: ['dev:prepare', 'build'],
10+
beforeTest: async () => {
11+
await $`pnpm playwright-core install chromium`;
12+
},
13+
test: async () => {
14+
const env = {
15+
...process.env,
16+
TEST_ENV: 'built',
17+
TEST_BUILDER: 'rspack',
18+
TEST_MANIFEST: 'manifest-on',
19+
TEST_CONTEXT: 'async',
20+
TEST_PAYLOAD: 'json',
21+
SKIP_BUNDLE_SIZE: 'true',
22+
};
23+
await execa('echo $TEST_BUILDER && pnpm run test:fixtures', {
24+
env,
25+
shell: true,
26+
});
27+
},
28+
});
29+
}

tests/rspack/nx.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import type { RunOptions } from '../../types';
2+
import { $, runInRepo } from '../../utils';
3+
4+
export async function test(options: RunOptions) {
5+
await runInRepo({
6+
...options,
7+
repo: 'nrwl/nx',
8+
branch: 'master',
9+
beforeTest: async () => {
10+
await $`cargo build`;
11+
await $`pnpm nx reset`;
12+
await $`pnpm nx build rspack --skip-nx-cache --verbose`;
13+
},
14+
test: [
15+
'pnpm nx test rspack --skip-nx-cache --verbose',
16+
// 'pnpm nx run-many -t e2e-local -p e2e-rspack --skip-nx-cache',
17+
],
18+
});
19+
}

tests/rspack/plugin.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import type { RunOptions } from '../../types';
2+
import { runInRepo } from '../../utils';
3+
4+
export async function test(options: RunOptions) {
5+
await runInRepo({
6+
...options,
7+
repo: 'rspack-contrib/rspack-plugin-ci',
8+
branch: 'main',
9+
test: ['test'],
10+
});
11+
}

tests/rspack/rsbuild.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import type { RunOptions } from '../../types';
2+
import { $, cd, runInRepo } from '../../utils';
3+
4+
export async function test(options: RunOptions) {
5+
await runInRepo({
6+
...options,
7+
repo: 'web-infra-dev/rsbuild',
8+
branch: process.env.RSBUILD_REF ?? 'main',
9+
beforeTest: async () => {
10+
cd('./e2e');
11+
await $`pnpm playwright install chromium`;
12+
cd('..');
13+
},
14+
test: ['e2e:rspack'],
15+
});
16+
}

0 commit comments

Comments
 (0)