Skip to content

Commit 6a36561

Browse files
SoonIterfi3ework
andauthored
chore(infra): integrate with codespeed (#214)
Co-authored-by: Wei <[email protected]>
1 parent 3f3d2e0 commit 6a36561

File tree

10 files changed

+147
-12
lines changed

10 files changed

+147
-12
lines changed

.github/workflows/test-ubuntu.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,18 @@ jobs:
9898
if: steps.changes.outputs.changed == 'true'
9999
run: pnpm install && cd ./tests && npx playwright install
100100

101-
- name: Features Integration Test (Vitest)
101+
- name: Integration Test (Vitest)
102102
if: steps.changes.outputs.changed == 'true'
103103
run: pnpm run test:integration
104104

105-
- name: Examples E2E Test (Playwright)
105+
- name: E2E Test (Playwright)
106106
if: steps.changes.outputs.changed == 'true'
107107
run: pnpm run test:e2e
108+
109+
# only run benchmark in Ubuntu
110+
- name: Benchmarks (Vitest)
111+
uses: CodSpeedHQ/action@v3
112+
with:
113+
run: pnpm run test:benchmark
114+
# token retrieved from the CodSpeed app at the previous step
115+
token: ${{ secrets.CODSPEED_TOKEN }}

.github/workflows/test-windows.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,14 @@ jobs:
103103
with:
104104
node-version: ${{ matrix.node-version }}
105105
cache: 'pnpm'
106-
107106
- name: Install Dependencies
108107
if: steps.changes.outputs.changed == 'true'
109108
run: pnpm install && cd ./tests && npx playwright install
110109

111-
- name: Features Integration Test (Vitest)
110+
- name: Integration Test (Vitest)
112111
if: steps.changes.outputs.changed == 'true'
113112
run: pnpm run test:integration
114113

115-
- name: Examples E2E Test (Playwright)
114+
- name: E2E Test (Playwright)
116115
if: steps.changes.outputs.changed == 'true'
117116
run: pnpm run test:e2e

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"prepare": "pnpm run build && simple-git-hooks",
1919
"sort-package-json": "npx sort-package-json \"packages/*/package.json\"",
2020
"test": "pnpm run test:unit && pnpm run test:integration && pnpm run test:e2e",
21+
"test:benchmark": "cd ./tests && pnpm run test:benchmark",
2122
"test:e2e": "pnpm run build:examples && cd tests && pnpm run test:e2e",
2223
"test:integration": "vitest run --project integration",
2324
"test:integration:watch": "vitest --project integration",

pnpm-lock.yaml

Lines changed: 80 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/dictionary.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ cjsx
1414
classname
1515
codegen
1616
codesandbox
17+
codspeed
1718
compat
1819
consolas
1920
contentful

tests/benchmark/index.bench.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { getCwdByExample, rslibBuild } from 'test-helper';
2+
import { bench, describe } from 'vitest';
3+
4+
describe('run rslib in examples', () => {
5+
bench(
6+
'examples/express-plugin',
7+
async () => {
8+
const cwd = getCwdByExample('express-plugin');
9+
await rslibBuild(cwd);
10+
},
11+
{ time: 5 },
12+
);
13+
bench(
14+
'examples/react-component',
15+
async () => {
16+
const cwd = getCwdByExample('react-component');
17+
await rslibBuild(cwd);
18+
},
19+
{ time: 5 },
20+
);
21+
});

tests/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"private": true,
44
"type": "module",
55
"scripts": {
6+
"test:benchmark": "vitest bench",
67
"test:e2e": "playwright test --pass-with-no-tests"
78
},
89
"dependencies": {
@@ -11,6 +12,7 @@
1112
"react-dom": "^18.3.1"
1213
},
1314
"devDependencies": {
15+
"@codspeed/vitest-plugin": "^3.1.1",
1416
"@playwright/test": "1.47.2",
1517
"@rsbuild/core": "1.0.7",
1618
"@rsbuild/plugin-react": "1.0.2",

tests/scripts/shared.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import fs from 'node:fs';
2-
import { join } from 'node:path';
2+
import { dirname, join } from 'node:path';
3+
import { fileURLToPath } from 'node:url';
34
import {
45
type InspectConfigResult,
56
mergeRsbuildConfig as mergeConfig,
@@ -8,6 +9,13 @@ import type { Format, LibConfig, RslibConfig } from '@rslib/core';
89
import { build, loadConfig } from '@rslib/core';
910
import { globContentJSON } from './helper';
1011

12+
const __filename = fileURLToPath(import.meta.url);
13+
const __dirname = dirname(__filename);
14+
15+
export function getCwdByExample(exampleName: string) {
16+
return join(__dirname, '../../examples', exampleName);
17+
}
18+
1119
export function generateBundleEsmConfig(config: LibConfig = {}): LibConfig {
1220
const esmBasicConfig: LibConfig = {
1321
format: 'esm',
@@ -136,6 +144,15 @@ export async function getResults(
136144
};
137145
}
138146

147+
export async function rslibBuild(fixturePath: string) {
148+
const rslibConfig = await loadConfig({
149+
cwd: fixturePath,
150+
});
151+
process.chdir(fixturePath);
152+
const rsbuildInstance = await build(rslibConfig);
153+
return { rsbuildInstance, rslibConfig };
154+
}
155+
139156
export async function buildAndGetResults(
140157
fixturePath: string,
141158
type: 'all',
@@ -152,11 +169,7 @@ export async function buildAndGetResults(
152169
fixturePath: string,
153170
type: 'js' | 'dts' | 'css' | 'all' = 'js',
154171
) {
155-
const rslibConfig = await loadConfig({
156-
cwd: fixturePath,
157-
});
158-
process.chdir(fixturePath);
159-
const rsbuildInstance = await build(rslibConfig);
172+
const { rsbuildInstance, rslibConfig } = await rslibBuild(fixturePath);
160173
const {
161174
origin: { bundlerConfigs, rsbuildConfig },
162175
} = await rsbuildInstance.inspectConfig({ verbose: true });

tests/tsconfig.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44
"noEmit": true,
55
"composite": true
66
},
7-
"include": ["cases/**/*.ts", "playwright.config.ts", "scripts"],
7+
"include": [
8+
"e2e/cases/**/*.ts",
9+
"benchmark/**/*.ts",
10+
"playwright.config.ts",
11+
"scripts"
12+
],
813
"exclude": ["**/node_modules", "**/.*/"],
914
"references": [
1015
{

tests/vitest.config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import codspeedPlugin from '@codspeed/vitest-plugin';
12
import { defineConfig } from 'vitest/config';
23
import { shared } from '../vitest.workspace';
34

@@ -8,5 +9,9 @@ export default defineConfig({
89
setupFiles: ['./setupVitestTests.ts'],
910
include: ['./integration/**/*.test.ts'],
1011
exclude: ['**/node_modules/**'],
12+
benchmark: {
13+
include: ['./benchmark/**/*.bench.ts'],
14+
},
1115
},
16+
plugins: [codspeedPlugin()],
1217
});

0 commit comments

Comments
 (0)