Skip to content

Commit

Permalink
chore(infra): integrate with codespeed (#214)
Browse files Browse the repository at this point in the history
Co-authored-by: Wei <[email protected]>
  • Loading branch information
SoonIter and fi3ework authored Sep 30, 2024
1 parent 3f3d2e0 commit 6a36561
Show file tree
Hide file tree
Showing 10 changed files with 147 additions and 12 deletions.
12 changes: 10 additions & 2 deletions .github/workflows/test-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,18 @@ jobs:
if: steps.changes.outputs.changed == 'true'
run: pnpm install && cd ./tests && npx playwright install

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

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

# only run benchmark in Ubuntu
- name: Benchmarks (Vitest)
uses: CodSpeedHQ/action@v3
with:
run: pnpm run test:benchmark
# token retrieved from the CodSpeed app at the previous step
token: ${{ secrets.CODSPEED_TOKEN }}
5 changes: 2 additions & 3 deletions .github/workflows/test-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,14 @@ jobs:
with:
node-version: ${{ matrix.node-version }}
cache: 'pnpm'

- name: Install Dependencies
if: steps.changes.outputs.changed == 'true'
run: pnpm install && cd ./tests && npx playwright install

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

- name: Examples E2E Test (Playwright)
- name: E2E Test (Playwright)
if: steps.changes.outputs.changed == 'true'
run: pnpm run test:e2e
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"prepare": "pnpm run build && simple-git-hooks",
"sort-package-json": "npx sort-package-json \"packages/*/package.json\"",
"test": "pnpm run test:unit && pnpm run test:integration && pnpm run test:e2e",
"test:benchmark": "cd ./tests && pnpm run test:benchmark",
"test:e2e": "pnpm run build:examples && cd tests && pnpm run test:e2e",
"test:integration": "vitest run --project integration",
"test:integration:watch": "vitest --project integration",
Expand Down
80 changes: 80 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions scripts/dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ cjsx
classname
codegen
codesandbox
codspeed
compat
consolas
contentful
Expand Down
21 changes: 21 additions & 0 deletions tests/benchmark/index.bench.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { getCwdByExample, rslibBuild } from 'test-helper';
import { bench, describe } from 'vitest';

describe('run rslib in examples', () => {
bench(
'examples/express-plugin',
async () => {
const cwd = getCwdByExample('express-plugin');
await rslibBuild(cwd);
},
{ time: 5 },
);
bench(
'examples/react-component',
async () => {
const cwd = getCwdByExample('react-component');
await rslibBuild(cwd);
},
{ time: 5 },
);
});
2 changes: 2 additions & 0 deletions tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"private": true,
"type": "module",
"scripts": {
"test:benchmark": "vitest bench",
"test:e2e": "playwright test --pass-with-no-tests"
},
"dependencies": {
Expand All @@ -11,6 +12,7 @@
"react-dom": "^18.3.1"
},
"devDependencies": {
"@codspeed/vitest-plugin": "^3.1.1",
"@playwright/test": "1.47.2",
"@rsbuild/core": "1.0.7",
"@rsbuild/plugin-react": "1.0.2",
Expand Down
25 changes: 19 additions & 6 deletions tests/scripts/shared.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import fs from 'node:fs';
import { join } from 'node:path';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import {
type InspectConfigResult,
mergeRsbuildConfig as mergeConfig,
Expand All @@ -8,6 +9,13 @@ import type { Format, LibConfig, RslibConfig } from '@rslib/core';
import { build, loadConfig } from '@rslib/core';
import { globContentJSON } from './helper';

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

export function getCwdByExample(exampleName: string) {
return join(__dirname, '../../examples', exampleName);
}

export function generateBundleEsmConfig(config: LibConfig = {}): LibConfig {
const esmBasicConfig: LibConfig = {
format: 'esm',
Expand Down Expand Up @@ -136,6 +144,15 @@ export async function getResults(
};
}

export async function rslibBuild(fixturePath: string) {
const rslibConfig = await loadConfig({
cwd: fixturePath,
});
process.chdir(fixturePath);
const rsbuildInstance = await build(rslibConfig);
return { rsbuildInstance, rslibConfig };
}

export async function buildAndGetResults(
fixturePath: string,
type: 'all',
Expand All @@ -152,11 +169,7 @@ export async function buildAndGetResults(
fixturePath: string,
type: 'js' | 'dts' | 'css' | 'all' = 'js',
) {
const rslibConfig = await loadConfig({
cwd: fixturePath,
});
process.chdir(fixturePath);
const rsbuildInstance = await build(rslibConfig);
const { rsbuildInstance, rslibConfig } = await rslibBuild(fixturePath);
const {
origin: { bundlerConfigs, rsbuildConfig },
} = await rsbuildInstance.inspectConfig({ verbose: true });
Expand Down
7 changes: 6 additions & 1 deletion tests/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
"noEmit": true,
"composite": true
},
"include": ["cases/**/*.ts", "playwright.config.ts", "scripts"],
"include": [
"e2e/cases/**/*.ts",
"benchmark/**/*.ts",
"playwright.config.ts",
"scripts"
],
"exclude": ["**/node_modules", "**/.*/"],
"references": [
{
Expand Down
5 changes: 5 additions & 0 deletions tests/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import codspeedPlugin from '@codspeed/vitest-plugin';
import { defineConfig } from 'vitest/config';
import { shared } from '../vitest.workspace';

Expand All @@ -8,5 +9,9 @@ export default defineConfig({
setupFiles: ['./setupVitestTests.ts'],
include: ['./integration/**/*.test.ts'],
exclude: ['**/node_modules/**'],
benchmark: {
include: ['./benchmark/**/*.bench.ts'],
},
},
plugins: [codspeedPlugin()],
});

0 comments on commit 6a36561

Please sign in to comment.