1
0
mirror of https://github.com/morris/vanilla-todo.git synced 2025-08-20 12:51:43 +02:00

set type module, simplify tests, update deps

This commit is contained in:
Morris Brodersen
2024-01-29 23:13:55 +01:00
parent a01590af93
commit 75ecd1d902
13 changed files with 113 additions and 120 deletions

36
test/coverage.js Normal file
View File

@@ -0,0 +1,36 @@
import { randomUUID } from 'crypto';
import { promises as fs } from 'fs';
import * as path from 'path';
import { test } from 'playwright/test';
// See also https://playwright.dev/docs/api/class-coverage
if (process.env.COVERAGE) {
test.beforeEach(async ({ page }) => {
await page.coverage.startJSCoverage();
});
test.afterEach(async ({ page }) => {
const coverage = await page.coverage.stopJSCoverage();
const output = {
result: coverage.map((entry) => ({
...entry,
url: resolveFileUrl(entry.url),
})),
};
await fs.mkdir('coverage/tmp', { recursive: true });
await fs.writeFile(
`coverage/tmp/coverage-${randomUUID()}.json`,
JSON.stringify(output),
);
});
}
function resolveFileUrl(url) {
return url.replace(
'http://localhost:8080',
`file://${path.resolve('public')}`,
);
}