Skip to content

Commit

Permalink
chore: repo overall update
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangtao25 committed Nov 18, 2024
1 parent bb6c026 commit 8d452cc
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 7 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/upload-canyon-report-coverage-map.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,26 @@ jobs:
- name: Upload coverage report
run: cd packages/canyon-report && npm install canyon-uploader -g && canyon-uploader map --dsn=https://collect.canyonjs.org/coverage/map/client

- name: Start Vite Server
run: cd packages/canyon-report && npm run dev &
shell: bash
continue-on-error: true

- name: Wait for Vite Server to Start
run: |
while :; do
if nc -z localhost 3000; then
break
fi
sleep 1
end
shell: bash

- name: Run Playwright Tests
run: cd packages/canyon-report && npx playwright test



# 保存构建结果到工作空间
# - name: Upload build artifact
# uses: actions/upload-artifact@v3
Expand Down
6 changes: 4 additions & 2 deletions packages/canyon-report/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"scripts": {
"dev": "rsbuild dev --open",
"build:report": "rsbuild build",
"build": "rslib build"
"build": "rslib build",
"playwright": "playwright test"
},
"exports": {
".": {
Expand Down Expand Up @@ -45,6 +46,7 @@
"postcss": "^8.4.47",
"swc-plugin-coverage-instrument": "^0.0.25",
"tailwindcss": "^3.4.14",
"typescript": "^5.6.3"
"typescript": "^5.6.3",
"@playwright/test": "^1.48.2"
}
}
30 changes: 30 additions & 0 deletions packages/canyon-report/tests/baseFixtures.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import * as fs from 'fs';
import * as path from 'path';
import {test as baseTest} from '@playwright/test';

const canyonOutputDirPath = path.join(process.cwd(), '.canyon_output');

export const test = baseTest.extend({
context: async ({context}, use) => {
await context.addInitScript(() =>
window.addEventListener('beforeunload', () =>
(window as any).collectIstanbulCoverage((window as any).__coverage__, (window as any).__canyon__)
),
);
await fs.promises.mkdir(canyonOutputDirPath, {recursive: true});
await context.exposeFunction('collectIstanbulCoverage', (coverageJSON, canyonJSON) => {
if (coverageJSON) {
fs.writeFileSync(path.join(canyonOutputDirPath, `${new Date().valueOf()}.json`), JSON.stringify({
...(canyonJSON||{}),
coverage: coverageJSON
}));
}
});
await use(context);
for (const page of context.pages()) {
await page.evaluate(() => (window as any).collectIstanbulCoverage((window as any).__coverage__, (window as any).__canyon__))
}
}
});

export const expect = test.expect;
6 changes: 6 additions & 0 deletions packages/canyon-report/tests/example.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { test, expect } from './baseFixtures';

test('has title', async ({ page }) => {
await page.goto('http://localhost:3000/login');
expect(await page.title()).toBe('Rsbuild App');
});
49 changes: 44 additions & 5 deletions pnpm-lock.yaml

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

0 comments on commit 8d452cc

Please sign in to comment.