Skip to content

Commit

Permalink
change to node test
Browse files Browse the repository at this point in the history
  • Loading branch information
cenfun committed Jul 27, 2024
1 parent 3baf7ad commit 230478e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 54 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -113,4 +113,4 @@
"vine-ui": "^3.1.16",
"ws": "^8.18.0"
}
}
}
79 changes: 27 additions & 52 deletions test/test-pr.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
const fs = require('fs');
const path = require('path');
const { chromium } = require('playwright');
const MCR = require('../');
const { CDPClient, CoverageReport } = require('../');

Check failure on line 1 in test/test-pr.js

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

test/test-pr.js#L1

Require statement not part of import statement.

const github = require('@actions/github');

Check failure on line 3 in test/test-pr.js

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

test/test-pr.js#L3

Require statement not part of import statement.
const core = require('@actions/core');

Check failure on line 4 in test/test-pr.js

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

test/test-pr.js#L4

Require statement not part of import statement.

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
Expand Down Expand Up @@ -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']
}]
],
Expand All @@ -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();
};

Expand Down

0 comments on commit 230478e

Please sign in to comment.