diff --git a/package.json b/package.json index 5bf185c2..0bda2a72 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "test-merge-istanbul": "node ./test/test-merge-istanbul.js", "test-client": "node ./test/test-client.js", "test-all": "node ./test/test.js && node ./scripts/docs.js", - "test-pr": "node ./test/test-pr.js", + "test-pr": "node --inspect=9230 ./test/test-pr.js", "test": "npm run test-unit && npx mcr npm run test-all -c test/mcr.config.mcr.js", "test:snap": "cross-env TEST_SNAPSHOT=true npm run test", "dev": "npx sf d app", @@ -113,4 +113,4 @@ "vine-ui": "^3.1.16", "ws": "^8.18.0" } -} +} \ No newline at end of file diff --git a/test/test-pr.js b/test/test-pr.js index 27e0cc04..902e95c1 100644 --- a/test/test-pr.js +++ b/test/test-pr.js @@ -1,20 +1,16 @@ -const fs = require('fs'); -const path = require('path'); -const { chromium } = require('playwright'); -const MCR = require('../'); +const { CDPClient, CoverageReport } = require('../'); const github = require('@actions/github'); const core = require('@actions/core'); const getPullRequestChanges = async () => { - const payload = github.context.payload; - - if (!payload || !payload.pull_request) { + if (!github.context.payload.pull_request) { + // console.log(Object.keys(github.context)); return []; } - console.log(payload.pull_request); + console.log('pull_request', github.context.payload.pull_request); // This should be a token with access to your repository scoped in as a secret. // The YML workflow will need to set myToken with the GitHub Secret Token @@ -66,7 +62,7 @@ const test = async () => { }], ['markdown-details', { // color: 'Tex', - baseUrl: 'https://cenfun.github.io/monocart-coverage-reports/v8/#page=', + baseUrl: 'https://cenfun.github.io/monocart-coverage-reports/pr/#page=', metrics: ['bytes', 'lines'] }] ], @@ -85,55 +81,34 @@ const test = async () => { } }; - const mcr = await MCR(coverageOptions); - - const browser = await chromium.launch(); - const page = await browser.newPage(); - - await Promise.all([ - page.coverage.startJSCoverage({ - resetOnNavigation: false - }), - page.coverage.startCSSCoverage({ - resetOnNavigation: false - }) - ]); - - const fileList = [ - './test/mock/v8/index.html', - './test/mock/v8/dist/coverage-v8.js', - './test/mock/css/style.css' - ]; - for (const filePath of fileList) { - const content = fs.readFileSync(filePath).toString('utf-8'); - const extname = path.extname(filePath); - if (extname === '.html') { - await page.setContent(content); - } else if (extname === '.css') { - await page.addStyleTag({ - content: `${content}\n/*# sourceURL=${filePath} */` - }); - } else { - await page.addScriptTag({ - content: `${content}\n//# sourceURL=${filePath}` - }); - } - } + const mcr = new CoverageReport(coverageOptions); - await new Promise((resolve) => { - setTimeout(resolve, 500); + const client = await CDPClient({ + port: 9230 }); - const [jsCoverage, cssCoverage] = await Promise.all([ - page.coverage.stopJSCoverage(), - page.coverage.stopCSSCoverage() - ]); + await client.startJSCoverage(); + + // ===================================================== + require('./specs/node.test.js'); + // ===================================================== - await browser.close(); + const coverageData = await client.stopJSCoverage(); + // console.log('check source', coverageList.filter((it) => !it.source).map((it) => [it.scriptId, it.url])); + // console.log(coverageList.map((it) => it.url)); - const coverageList = [... jsCoverage, ... cssCoverage]; + await client.close(); + + if (coverageData) { + // filter node internal files + let coverageList = coverageData.filter((entry) => entry.url && entry.url.startsWith('file:')); + + // console.log(coverageList); + coverageList = coverageList.filter((entry) => entry.url.includes('test/mock/node')); + + await mcr.add(coverageList); + } - await mcr.add(coverageList); await mcr.generate(); };