mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 04:18:54 +00:00
test: move playwright test suite to top level (#2113)
This commit is contained in:
16
tests/kit/package.json
Normal file
16
tests/kit/package.json
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "@affine-test/kit",
|
||||
"private": true,
|
||||
"version": "0.5.4-canary.9",
|
||||
"exports": {
|
||||
"./playwright": "./playwright.ts"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@playwright/test": "^1.32.3",
|
||||
"playwright": "^1.32.3"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@playwright/test": "*",
|
||||
"playwright": "*"
|
||||
}
|
||||
}
|
||||
55
tests/kit/playwright.ts
Normal file
55
tests/kit/playwright.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import crypto from 'node:crypto';
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import process from 'node:process';
|
||||
|
||||
import { test as baseTest } from '@playwright/test';
|
||||
|
||||
const istanbulTempDir = process.env.ISTANBUL_TEMP_DIR
|
||||
? path.resolve(process.env.ISTANBUL_TEMP_DIR)
|
||||
: path.join(process.cwd(), '.nyc_output');
|
||||
|
||||
function generateUUID() {
|
||||
return crypto.randomUUID();
|
||||
}
|
||||
|
||||
const enableCoverage = !!process.env.CI || !!process.env.COVERAGE;
|
||||
|
||||
export const test = baseTest.extend({
|
||||
context: async ({ context }, use) => {
|
||||
if (enableCoverage) {
|
||||
await context.addInitScript(() =>
|
||||
window.addEventListener('beforeunload', () =>
|
||||
// @ts-expect-error
|
||||
window.collectIstanbulCoverage(JSON.stringify(window.__coverage__))
|
||||
)
|
||||
);
|
||||
|
||||
await fs.promises.mkdir(istanbulTempDir, { recursive: true });
|
||||
await context.exposeFunction(
|
||||
'collectIstanbulCoverage',
|
||||
(coverageJSON?: string) => {
|
||||
if (coverageJSON)
|
||||
fs.writeFileSync(
|
||||
path.join(
|
||||
istanbulTempDir,
|
||||
`playwright_coverage_${generateUUID()}.json`
|
||||
),
|
||||
coverageJSON
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
await use(context);
|
||||
|
||||
if (enableCoverage) {
|
||||
for (const page of context.pages()) {
|
||||
await page.evaluate(() =>
|
||||
// @ts-expect-error
|
||||
window.collectIstanbulCoverage(JSON.stringify(window.__coverage__))
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
4
tests/kit/tsconfig.json
Normal file
4
tests/kit/tsconfig.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"include": ["./*.ts"]
|
||||
}
|
||||
Reference in New Issue
Block a user