feat: basic test coverage

This commit is contained in:
DarkSky
2023-02-05 18:41:18 +08:00
parent dd9d30de37
commit c4d34ddfea
28 changed files with 323 additions and 1081 deletions
+2 -1
View File
@@ -1,4 +1,5 @@
import { test, expect } from '@playwright/test';
import { expect } from '@playwright/test';
import { test } from './libs/playwright.js';
import { loadPage } from './libs/load-page.js';
import { clickPageMoreActions } from './libs/page-logic.js';
loadPage();
+2 -1
View File
@@ -1,4 +1,5 @@
import { test, expect } from '@playwright/test';
import { expect } from '@playwright/test';
import { test } from './libs/playwright.js';
import { loadPage } from './libs/load-page.js';
loadPage();
+2 -1
View File
@@ -1,4 +1,5 @@
import { test, expect } from '@playwright/test';
import { expect } from '@playwright/test';
import { test } from './libs/playwright.js';
import { loadPage } from './libs/load-page.js';
loadPage();
+2 -1
View File
@@ -1,4 +1,5 @@
import { test, expect } from '@playwright/test';
import { expect } from '@playwright/test';
import { test } from './libs/playwright.js';
import { loadPage } from './libs/load-page.js';
loadPage();
+2 -1
View File
@@ -1,4 +1,5 @@
import { test, expect } from '@playwright/test';
import { expect } from '@playwright/test';
import { test } from './libs/playwright.js';
import { loadPage } from './libs/load-page.js';
loadPage();
+2 -1
View File
@@ -1,4 +1,5 @@
import { test, expect } from '@playwright/test';
import { expect } from '@playwright/test';
import { test } from './libs/playwright.js';
import { loadPage } from './libs/load-page.js';
loadPage();
+52
View File
@@ -0,0 +1,52 @@
import { test as baseTest } from '@playwright/test';
import fs from 'node:fs';
import path from 'node:path';
import process from 'node:process';
import crypto from 'node:crypto';
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__))
);
}
}
},
});
+2 -1
View File
@@ -1,4 +1,5 @@
import { test, expect } from '@playwright/test';
import { expect } from '@playwright/test';
import { test } from './libs/playwright.js';
import { loadPage } from './libs/load-page.js';
import { newPage } from './libs/page-logic.js';
+2 -1
View File
@@ -1,4 +1,5 @@
import { test, expect } from '@playwright/test';
import { expect } from '@playwright/test';
import { test } from './libs/playwright.js';
import { loadPage } from './libs/load-page.js';
import { newPage, clickPageMoreActions } from './libs/page-logic.js';
loadPage();
+2 -1
View File
@@ -1,4 +1,5 @@
import { test, expect } from '@playwright/test';
import { expect } from '@playwright/test';
import { test } from './libs/playwright.js';
import { loadPage } from './libs/load-page.js';
import { newPage, clickPageMoreActions } from './libs/page-logic.js';
loadPage();
+2 -1
View File
@@ -1,4 +1,5 @@
import { test, expect } from '@playwright/test';
import { expect } from '@playwright/test';
import { test } from './libs/playwright.js';
import { loadPage } from './libs/load-page.js';
import { newPage, clickPageMoreActions } from './libs/page-logic.js';
loadPage();
+2 -1
View File
@@ -1,4 +1,5 @@
import { test, expect } from '@playwright/test';
import { expect } from '@playwright/test';
import { test } from './libs/playwright.js';
import { loadPage } from './libs/load-page.js';
import { newPage } from './libs/page-logic.js';
loadPage();
+2 -1
View File
@@ -1,4 +1,5 @@
import { test, expect } from '@playwright/test';
import { expect } from '@playwright/test';
import { test } from './libs/playwright.js';
import { loadPage } from './libs/load-page.js';
import { newPage } from './libs/page-logic.js';
loadPage();
+2 -1
View File
@@ -1,4 +1,5 @@
import { test, expect } from '@playwright/test';
import { expect } from '@playwright/test';
import { test } from './libs/playwright.js';
import { loadPage } from './libs/load-page.js';
import { newPage } from './libs/page-logic.js';
loadPage();
+2 -1
View File
@@ -1,4 +1,5 @@
import { test, expect } from '@playwright/test';
import { expect } from '@playwright/test';
import { test } from './libs/playwright.js';
import { loadPage } from './libs/load-page.js';
import { newPage, clickPageMoreActions } from './libs/page-logic.js';
loadPage();
+2 -1
View File
@@ -1,4 +1,5 @@
import { test, expect } from '@playwright/test';
import { expect } from '@playwright/test';
import { test } from './libs/playwright.js';
import { loadPage } from './libs/load-page.js';
import { newPage } from './libs/page-logic.js';
loadPage();
+2 -1
View File
@@ -1,4 +1,5 @@
import { test, expect } from '@playwright/test';
import { expect } from '@playwright/test';
import { test } from './libs/playwright.js';
import { loadPage } from './libs/load-page.js';
loadPage();
+1 -1
View File
@@ -1,4 +1,4 @@
import { test, expect } from '@playwright/test';
import { test } from './libs/playwright.js';
import { loadPage } from './libs/load-page.js';
loadPage();
+2 -1
View File
@@ -1,4 +1,5 @@
import { test, expect, type Page } from '@playwright/test';
import { expect, type Page } from '@playwright/test';
import { test } from './libs/playwright.js';
import { loadPage } from './libs/load-page.js';
import { withCtrlOrMeta } from './libs/keyboard.js';
import { newPage } from './libs/page-logic.js';
+2 -1
View File
@@ -1,4 +1,5 @@
import { test, expect } from '@playwright/test';
import { expect } from '@playwright/test';
import { test } from './libs/playwright.js';
import { loadPage } from './libs/load-page.js';
loadPage();
+2 -1
View File
@@ -1,4 +1,5 @@
import { test, expect } from '@playwright/test';
import { expect } from '@playwright/test';
import { test } from './libs/playwright.js';
import { loadPage } from './libs/load-page.js';
loadPage();