Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace v8 with monocart for coverage #3598

Merged
merged 2 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/test-all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ jobs:
- run: npm run test-integration
if: success() || failure()

render-tests-ubuntu:
render-tests:
name: Render tests
env:
SPLIT_COUNT: 3
Expand Down Expand Up @@ -106,7 +106,7 @@ jobs:
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
with:
files: ${{ github.workspace }}/coverage/coverage-render.json
files: ${{ github.workspace }}/coverage/render/codecov.json
verbose: true
- name: Upload render test failure
if: failure()
Expand Down
65 changes: 61 additions & 4 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
"json-stringify-pretty-compact": "^4.0.0",
"minimist": "^1.2.8",
"mock-geolocation": "^1.0.11",
"monocart-coverage-reports": "^2.2.2",
"nise": "^5.1.7",
"npm-font-open-sans": "^1.1.0",
"npm-run-all": "^4.1.5",
Expand Down Expand Up @@ -128,8 +129,7 @@
"typedoc": "^0.25.7",
"typedoc-plugin-markdown": "^3.17.1",
"typedoc-plugin-missing-exports": "^2.2.0",
"typescript": "^5.3.3",
"v8-to-istanbul": "^9.2.0"
"typescript": "^5.3.3"
},
"overrides": {
"postcss-inline-svg": {
Expand Down
34 changes: 25 additions & 9 deletions test/integration/render/run_render_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {fileURLToPath} from 'url';
import {globSync} from 'glob';
import http from 'http';
import puppeteer, {Page, Browser} from 'puppeteer';
import v8toIstanbul from 'v8-to-istanbul';
import {CoverageReport} from 'monocart-coverage-reports';
import {localizeURLs} from '../lib/localize-urls';
import type {default as MapLibreGL, Map, CanvasSource, PointLike, StyleSpecification} from '../../../dist/maplibre-gl';

Expand Down Expand Up @@ -776,7 +776,7 @@ async function runTests(page: Page, testStyles: StyleWithTestData[], directory:

async function createPageAndStart(browser: Browser, testStyles: StyleWithTestData[], directory: string, options: RenderOptions) {
const page = await browser.newPage();
page.coverage.startJSCoverage({includeRawScriptCoverage: true});
await page.coverage.startJSCoverage({includeRawScriptCoverage: true});
applyDebugParameter(options, page);
await page.addScriptTag({path: 'dist/maplibre-gl-dev.js'});
await runTests(page, testStyles, directory);
Expand All @@ -789,13 +789,29 @@ async function closePageAndFinish(page: Page, reportCoverage: boolean) {
if (!reportCoverage) {
return;
}
const converter = v8toIstanbul('./dist/maplibre-gl-dev.js');
await converter.load();
converter.applyCoverage(coverage.map(c => c.rawScriptCoverage!.functions).flat());
const coverageReport = converter.toIstanbul();
const report = JSON.stringify(coverageReport);
fs.mkdirSync('./coverage', {recursive: true});
fs.writeFileSync('./coverage/coverage-render.json', report);

const rawV8CoverageData = coverage.map((it) => {
// Convert to raw v8 coverage format
const entry: any = {
source: it.text,
...it.rawScriptCoverage
};
if (entry.url.endsWith('maplibre-gl-dev.js')) {
entry.sourceMap = JSON.parse(fs.readFileSync('dist/maplibre-gl-dev.js.map').toString('utf-8'));
}
return entry;
});

const coverageReport = new CoverageReport({
name: 'MapLibre Coverage Report',
outputDir: './coverage/render',
reports: [['v8'], ['codecov']]
});
coverageReport.cleanCache();

await coverageReport.add(rawV8CoverageData);

await coverageReport.generate();
}

/**
Expand Down