From cb622df9ef147a7825eb14d69b654c993ef27870 Mon Sep 17 00:00:00 2001 From: cenfun Date: Sat, 27 Jul 2024 09:43:17 +0800 Subject: [PATCH 1/3] add test-pr --- package.json | 3 +- test/test-pr.js | 130 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 132 insertions(+), 1 deletion(-) create mode 100644 test/test-pr.js diff --git a/package.json b/package.json index c403a457..57400eb2 100644 --- a/package.json +++ b/package.json @@ -54,6 +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": "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", @@ -112,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 new file mode 100644 index 00000000..d40717f5 --- /dev/null +++ b/test/test-pr.js @@ -0,0 +1,130 @@ +const fs = require('fs'); +const path = require('path'); +const { chromium } = require('playwright'); +const MCR = require('../'); + +const github = require('@actions/github'); +const core = require('@actions/core'); + +const getPR = async () => { + // 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 + // myToken: ${{ secrets.GITHUB_TOKEN }} + // https://help.github.com/en/actions/automating-your-workflow-with-github-actions/authenticating-with-the-github_token#about-the-github_token-secret + const myToken = core.getInput('myToken'); + + const octokit = github.getOctokit(myToken); + + // You can also pass in additional options as a second parameter to getOctokit + // const octokit = github.getOctokit(myToken, {userAgent: "MyActionVersion1"}); + + const { data } = await octokit.rest.pulls.get({ + owner: 'octokit', + repo: 'rest.js', + pull_number: 123, + mediaType: { + format: 'diff' + } + }); + + return data; +}; + + +const test = async () => { + + const pr = await getPR(); + console.log(pr); + + const coverageOptions = { + // logging: 'debug', + cleanCache: true, + reports: [ + ['console-summary', { + // metrics: ['bytes', 'functions', 'lines'] + }], + ['console-details', { + // skipPercent: 100, + metrics: ['bytes', 'lines'], + maxCols: 30 + }], + ['v8', { + // metrics: ['bytes', 'functions', 'lines'] + }], + ['markdown-summary', { + // color: 'html' + }], + ['markdown-details', { + // color: 'Tex', + baseUrl: 'https://cenfun.github.io/monocart-coverage-reports/v8/#page=', + metrics: ['bytes', 'lines'] + }] + ], + + name: 'My PR Coverage Report', + assetsPath: '../assets', + + outputDir: './docs/pr', + + sourceFilter: { + '**/src/**': true + }, + + onEnd: (coverageResults) => { + + } + }; + + 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}` + }); + } + } + + await new Promise((resolve) => { + setTimeout(resolve, 500); + }); + + const [jsCoverage, cssCoverage] = await Promise.all([ + page.coverage.stopJSCoverage(), + page.coverage.stopCSSCoverage() + ]); + + await browser.close(); + + const coverageList = [... jsCoverage, ... cssCoverage]; + + await mcr.add(coverageList); + await mcr.generate(); +}; + +test(); From 218e1d299dd728da759ec833b9c2262644c5f9db Mon Sep 17 00:00:00 2001 From: cenfun Date: Sat, 27 Jul 2024 11:16:10 +0800 Subject: [PATCH 2/3] add pull_request --- .github/workflows/test-pr.yml | 37 ++++ package-lock.json | 339 +++++++++++++++++++++++++++++----- package.json | 4 +- test/package.json | 2 + test/test-pr.js | 111 +++++------ 5 files changed, 386 insertions(+), 107 deletions(-) create mode 100644 .github/workflows/test-pr.yml diff --git a/.github/workflows/test-pr.yml b/.github/workflows/test-pr.yml new file mode 100644 index 00000000..7a7d502e --- /dev/null +++ b/.github/workflows/test-pr.yml @@ -0,0 +1,37 @@ +name: Test PR + +on: + + pull_request: + types: [opened, reopened, edited, review_requested] + branches: + - 'test-pr' + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +permissions: + contents: read + +jobs: + + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Use Node.js version + uses: actions/setup-node@v4 + with: + node-version: 20 + cache: '' + + - run: npm install + - run: npm run build + - run: npm run test-pr + env: + myToken: ${{ secrets.GITHUB_TOKEN }} + FORCE_COLOR: true + diff --git a/package-lock.json b/package-lock.json index daacb9da..bba8169c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -25,7 +25,7 @@ "istanbul-lib-coverage": "^3.2.2", "istanbul-lib-report": "^3.0.1", "istanbul-reports": "^3.1.7", - "lz-utils": "^2.0.2", + "lz-utils": "^2.1.0", "minimatch": "9.0.5", "monocart-locator": "^1.0.2" }, @@ -36,7 +36,7 @@ "async-tick": "^1.0.0", "convert-source-map": "^2.0.0", "esbuild": "^0.23.0", - "eslint": "~9.7.0", + "eslint": "~9.8.0", "eslint-config-plus": "^2.0.2", "eslint-plugin-html": "^8.1.1", "eslint-plugin-vue": "^9.27.0", @@ -54,6 +54,38 @@ "ws": "^8.18.0" } }, + "node_modules/@actions/core": { + "version": "1.10.1", + "resolved": "https://registry.npmjs.org/@actions/core/-/core-1.10.1.tgz", + "integrity": "sha512-3lBR9EDAY+iYIpTnTIXmWcNbX3T2kCkAEQGIQx4NVQ0575nk2k3GRZDTPQG+vVtS2izSLmINlxXf0uLtnrTP+g==", + "dev": true, + "dependencies": { + "@actions/http-client": "^2.0.1", + "uuid": "^8.3.2" + } + }, + "node_modules/@actions/github": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/@actions/github/-/github-6.0.0.tgz", + "integrity": "sha512-alScpSVnYmjNEXboZjarjukQEzgCRmjMv6Xj47fsdnqGS73bjJNDpiiXmp8jr0UZLdUB6d9jW63IcmddUP+l0g==", + "dev": true, + "dependencies": { + "@actions/http-client": "^2.2.0", + "@octokit/core": "^5.0.1", + "@octokit/plugin-paginate-rest": "^9.0.0", + "@octokit/plugin-rest-endpoint-methods": "^10.0.0" + } + }, + "node_modules/@actions/http-client": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-2.2.1.tgz", + "integrity": "sha512-KhC/cZsq7f8I4LfZSJKgCvEwfkE8o1538VoBeoGzokVLLnbFDEAdFD3UhoMklxo2un9NJVBdANOresx7vTHlHw==", + "dev": true, + "dependencies": { + "tunnel": "^0.0.6", + "undici": "^5.25.4" + } + }, "node_modules/@ampproject/remapping": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/@ampproject/remapping/-/remapping-2.3.0.tgz", @@ -2563,9 +2595,9 @@ } }, "node_modules/@eslint/config-array": { - "version": "0.17.0", - "resolved": "https://registry.npmjs.org/@eslint/config-array/-/config-array-0.17.0.tgz", - "integrity": "sha512-A68TBu6/1mHHuc5YJL0U0VVeGNiklLAL6rRmhTCP2B5XjWLMnrX+HkO+IAXyHvks5cyyY1jjK5ITPQ1HGS2EVA==", + "version": "0.17.1", + "resolved": "https://registry.npmjs.org/@eslint/config-array/-/config-array-0.17.1.tgz", + "integrity": "sha512-BlYOpej8AQ8Ev9xVqroV7a02JK3SkBAaN9GfMMH9W6Ch8FlQlkjGw4Ir7+FgYwfirivAf4t+GtzuAxqfukmISA==", "dev": true, "dependencies": { "@eslint/object-schema": "^2.1.4", @@ -2644,9 +2676,9 @@ } }, "node_modules/@eslint/js": { - "version": "9.7.0", - "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.7.0.tgz", - "integrity": "sha512-ChuWDQenef8OSFnvuxv0TCVxEwmu3+hPNKvM9B34qpM0rDRbjL8t5QkQeHHeAfsKQjuH9wS82WeCi1J/owatng==", + "version": "9.8.0", + "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.8.0.tgz", + "integrity": "sha512-MfluB7EUfxXtv3i/++oh89uzAr4PDI4nn201hsp+qaXqsjAWzinlZEHEfPgAX4doIlKvPG/i0A9dpKxOLII8yA==", "dev": true, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -2661,6 +2693,15 @@ "node": "^18.18.0 || ^20.9.0 || >=21.1.0" } }, + "node_modules/@fastify/busboy": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/@fastify/busboy/-/busboy-2.1.1.tgz", + "integrity": "sha512-vBZP4NlzfOlerQTnba4aqZoMhE/a9HY7HRqoOPaETQcSQuWEIyZMHGfVu6w9wGtGK5fED5qRs2DteVCjOH60sA==", + "dev": true, + "engines": { + "node": ">=14" + } + }, "node_modules/@hapi/bourne": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/@hapi/bourne/-/bourne-3.0.0.tgz", @@ -3113,6 +3154,164 @@ "node": ">= 8" } }, + "node_modules/@octokit/auth-token": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/@octokit/auth-token/-/auth-token-4.0.0.tgz", + "integrity": "sha512-tY/msAuJo6ARbK6SPIxZrPBms3xPbfwBrulZe0Wtr/DIY9lje2HeV1uoebShn6mx7SjCHif6EjMvoREj+gZ+SA==", + "dev": true, + "engines": { + "node": ">= 18" + } + }, + "node_modules/@octokit/core": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/@octokit/core/-/core-5.2.0.tgz", + "integrity": "sha512-1LFfa/qnMQvEOAdzlQymH0ulepxbxnCYAKJZfMci/5XJyIHWgEYnDmgnKakbTh7CH2tFQ5O60oYDvns4i9RAIg==", + "dev": true, + "dependencies": { + "@octokit/auth-token": "^4.0.0", + "@octokit/graphql": "^7.1.0", + "@octokit/request": "^8.3.1", + "@octokit/request-error": "^5.1.0", + "@octokit/types": "^13.0.0", + "before-after-hook": "^2.2.0", + "universal-user-agent": "^6.0.0" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/@octokit/endpoint": { + "version": "9.0.5", + "resolved": "https://registry.npmjs.org/@octokit/endpoint/-/endpoint-9.0.5.tgz", + "integrity": "sha512-ekqR4/+PCLkEBF6qgj8WqJfvDq65RH85OAgrtnVp1mSxaXF03u2xW/hUdweGS5654IlC0wkNYC18Z50tSYTAFw==", + "dev": true, + "dependencies": { + "@octokit/types": "^13.1.0", + "universal-user-agent": "^6.0.0" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/@octokit/graphql": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/@octokit/graphql/-/graphql-7.1.0.tgz", + "integrity": "sha512-r+oZUH7aMFui1ypZnAvZmn0KSqAUgE1/tUXIWaqUCa1758ts/Jio84GZuzsvUkme98kv0WFY8//n0J1Z+vsIsQ==", + "dev": true, + "dependencies": { + "@octokit/request": "^8.3.0", + "@octokit/types": "^13.0.0", + "universal-user-agent": "^6.0.0" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/@octokit/openapi-types": { + "version": "22.2.0", + "resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-22.2.0.tgz", + "integrity": "sha512-QBhVjcUa9W7Wwhm6DBFu6ZZ+1/t/oYxqc2tp81Pi41YNuJinbFRx8B133qVOrAaBbF7D/m0Et6f9/pZt9Rc+tg==", + "dev": true + }, + "node_modules/@octokit/plugin-paginate-rest": { + "version": "9.2.1", + "resolved": "https://registry.npmjs.org/@octokit/plugin-paginate-rest/-/plugin-paginate-rest-9.2.1.tgz", + "integrity": "sha512-wfGhE/TAkXZRLjksFXuDZdmGnJQHvtU/joFQdweXUgzo1XwvBCD4o4+75NtFfjfLK5IwLf9vHTfSiU3sLRYpRw==", + "dev": true, + "dependencies": { + "@octokit/types": "^12.6.0" + }, + "engines": { + "node": ">= 18" + }, + "peerDependencies": { + "@octokit/core": "5" + } + }, + "node_modules/@octokit/plugin-paginate-rest/node_modules/@octokit/openapi-types": { + "version": "20.0.0", + "resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-20.0.0.tgz", + "integrity": "sha512-EtqRBEjp1dL/15V7WiX5LJMIxxkdiGJnabzYx5Apx4FkQIFgAfKumXeYAqqJCj1s+BMX4cPFIFC4OLCR6stlnA==", + "dev": true + }, + "node_modules/@octokit/plugin-paginate-rest/node_modules/@octokit/types": { + "version": "12.6.0", + "resolved": "https://registry.npmjs.org/@octokit/types/-/types-12.6.0.tgz", + "integrity": "sha512-1rhSOfRa6H9w4YwK0yrf5faDaDTb+yLyBUKOCV4xtCDB5VmIPqd/v9yr9o6SAzOAlRxMiRiCic6JVM1/kunVkw==", + "dev": true, + "dependencies": { + "@octokit/openapi-types": "^20.0.0" + } + }, + "node_modules/@octokit/plugin-rest-endpoint-methods": { + "version": "10.4.1", + "resolved": "https://registry.npmjs.org/@octokit/plugin-rest-endpoint-methods/-/plugin-rest-endpoint-methods-10.4.1.tgz", + "integrity": "sha512-xV1b+ceKV9KytQe3zCVqjg+8GTGfDYwaT1ATU5isiUyVtlVAO3HNdzpS4sr4GBx4hxQ46s7ITtZrAsxG22+rVg==", + "dev": true, + "dependencies": { + "@octokit/types": "^12.6.0" + }, + "engines": { + "node": ">= 18" + }, + "peerDependencies": { + "@octokit/core": "5" + } + }, + "node_modules/@octokit/plugin-rest-endpoint-methods/node_modules/@octokit/openapi-types": { + "version": "20.0.0", + "resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-20.0.0.tgz", + "integrity": "sha512-EtqRBEjp1dL/15V7WiX5LJMIxxkdiGJnabzYx5Apx4FkQIFgAfKumXeYAqqJCj1s+BMX4cPFIFC4OLCR6stlnA==", + "dev": true + }, + "node_modules/@octokit/plugin-rest-endpoint-methods/node_modules/@octokit/types": { + "version": "12.6.0", + "resolved": "https://registry.npmjs.org/@octokit/types/-/types-12.6.0.tgz", + "integrity": "sha512-1rhSOfRa6H9w4YwK0yrf5faDaDTb+yLyBUKOCV4xtCDB5VmIPqd/v9yr9o6SAzOAlRxMiRiCic6JVM1/kunVkw==", + "dev": true, + "dependencies": { + "@octokit/openapi-types": "^20.0.0" + } + }, + "node_modules/@octokit/request": { + "version": "8.4.0", + "resolved": "https://registry.npmjs.org/@octokit/request/-/request-8.4.0.tgz", + "integrity": "sha512-9Bb014e+m2TgBeEJGEbdplMVWwPmL1FPtggHQRkV+WVsMggPtEkLKPlcVYm/o8xKLkpJ7B+6N8WfQMtDLX2Dpw==", + "dev": true, + "dependencies": { + "@octokit/endpoint": "^9.0.1", + "@octokit/request-error": "^5.1.0", + "@octokit/types": "^13.1.0", + "universal-user-agent": "^6.0.0" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/@octokit/request-error": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/@octokit/request-error/-/request-error-5.1.0.tgz", + "integrity": "sha512-GETXfE05J0+7H2STzekpKObFe765O5dlAKUTLNGeH+x47z7JjXHfsHKo5z21D/o/IOZTUEI6nyWyR+bZVP/n5Q==", + "dev": true, + "dependencies": { + "@octokit/types": "^13.1.0", + "deprecation": "^2.0.0", + "once": "^1.4.0" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/@octokit/types": { + "version": "13.5.0", + "resolved": "https://registry.npmjs.org/@octokit/types/-/types-13.5.0.tgz", + "integrity": "sha512-HdqWTf5Z3qwDVlzCrP8UJquMwunpDiMPt5er+QjGzL4hqr/vBVY/MauQgS1xWxCDT1oMx1EULyqxncdCY/NVSQ==", + "dev": true, + "dependencies": { + "@octokit/openapi-types": "^22.2.0" + } + }, "node_modules/@pkgjs/parseargs": { "version": "0.11.0", "resolved": "https://registry.npmjs.org/@pkgjs/parseargs/-/parseargs-0.11.0.tgz", @@ -3124,16 +3323,16 @@ } }, "node_modules/@puppeteer/browsers": { - "version": "2.2.4", - "resolved": "https://registry.npmjs.org/@puppeteer/browsers/-/browsers-2.2.4.tgz", - "integrity": "sha512-BdG2qiI1dn89OTUUsx2GZSpUzW+DRffR1wlMJyKxVHYrhnKoELSDxDd+2XImUkuWPEKk76H5FcM/gPFrEK1Tfw==", + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/@puppeteer/browsers/-/browsers-2.3.0.tgz", + "integrity": "sha512-ioXoq9gPxkss4MYhD+SFaU9p1IHFUX0ILAWFPyjGaBdjLsYAlZw6j1iLA0N/m12uVHLFDfSYNF7EQccjinIMDA==", "dev": true, "dependencies": { "debug": "^4.3.5", "extract-zip": "^2.0.1", "progress": "^2.0.3", "proxy-agent": "^6.4.0", - "semver": "^7.6.2", + "semver": "^7.6.3", "tar-fs": "^3.0.6", "unbzip2-stream": "^1.4.3", "yargs": "^17.7.2" @@ -4698,6 +4897,12 @@ "node": ">=10.0.0" } }, + "node_modules/before-after-hook": { + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/before-after-hook/-/before-after-hook-2.2.3.tgz", + "integrity": "sha512-NzUnlZexiaH/46WDhANlyR2bXRopNg4F/zuSA3OpZnllCUgRaOF2znDioDWrmbNVsuZk6l9pMquQB38cfBZwkQ==", + "dev": true + }, "node_modules/big.js": { "version": "5.2.2", "resolved": "https://registry.npmjs.org/big.js/-/big.js-5.2.2.tgz", @@ -5033,9 +5238,9 @@ } }, "node_modules/chromium-bidi": { - "version": "0.6.1", - "resolved": "https://registry.npmjs.org/chromium-bidi/-/chromium-bidi-0.6.1.tgz", - "integrity": "sha512-kSxJRj0VgtUKz6nmzc2JPfyfJGzwzt65u7PqhPHtgGQUZLF5oG+ST6l6e5ONfStUMAlhSutFCjaGKllXZa16jA==", + "version": "0.6.2", + "resolved": "https://registry.npmjs.org/chromium-bidi/-/chromium-bidi-0.6.2.tgz", + "integrity": "sha512-4WVBa6ijmUTVr9cZD4eicQD8Mdy/HCX3bzEIYYpmk0glqYLoWH+LqQEvV9RpDRzoQSbY1KJHloYXbDMXMbDPhg==", "dev": true, "dependencies": { "mitt": "3.0.1", @@ -5917,6 +6122,12 @@ "node": ">= 0.8" } }, + "node_modules/deprecation": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/deprecation/-/deprecation-2.3.1.tgz", + "integrity": "sha512-xmHIy4F3scKVwMsQ4WnVaS8bHOx0DmVwRywosKhaILI0ywMDWPtBSku2HNxRvF7jtwDRsoEwYQSfbxj8b7RlJQ==", + "dev": true + }, "node_modules/destroy": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.2.0.tgz", @@ -5940,9 +6151,9 @@ } }, "node_modules/devtools-protocol": { - "version": "0.0.1299070", - "resolved": "https://registry.npmjs.org/devtools-protocol/-/devtools-protocol-0.0.1299070.tgz", - "integrity": "sha512-+qtL3eX50qsJ7c+qVyagqi7AWMoQCBGNfoyJZMwm/NSXVqLYbuitrWEEIzxfUmTNy7//Xe8yhMmQ+elj3uAqSg==", + "version": "0.0.1312386", + "resolved": "https://registry.npmjs.org/devtools-protocol/-/devtools-protocol-0.0.1312386.tgz", + "integrity": "sha512-DPnhUXvmvKT2dFA/j7B+riVLUt9Q6RKJlcppojL5CoRywJJKLDYnRlw0gTFKfgDPHP5E04UoB71SxoJlVZy8FA==", "dev": true }, "node_modules/diff": { @@ -6276,6 +6487,12 @@ "integrity": "sha512-cWYq3U9uRlXGnPB5nUazQUIKLxthxfjzav2esBB0RqmgWhu6H5kNTiMzpt3UL1rCiTrJTRCiiib8iS881mzzlg==", "dev": true }, + "node_modules/esbuild-metadata-report/node_modules/lz-utils": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/lz-utils/-/lz-utils-2.0.2.tgz", + "integrity": "sha512-i1PJN4hNEevkrvLMqNWCCac1BcB5SRaghywG7HVzWOyVkFOasLCG19ND1sY1F/ZEsM6SnGtoXyBWnmfqOM5r6g==", + "dev": true + }, "node_modules/escalade": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.2.tgz", @@ -6325,16 +6542,16 @@ } }, "node_modules/eslint": { - "version": "9.7.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-9.7.0.tgz", - "integrity": "sha512-FzJ9D/0nGiCGBf8UXO/IGLTgLVzIxze1zpfA8Ton2mjLovXdAPlYDv+MQDcqj3TmrhAGYfOpz9RfR+ent0AgAw==", + "version": "9.8.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-9.8.0.tgz", + "integrity": "sha512-K8qnZ/QJzT2dLKdZJVX6W4XOwBzutMYmt0lqUS+JdXgd+HTYFlonFgkJ8s44d/zMPPCnOOk0kMWCApCPhiOy9A==", "dev": true, "dependencies": { "@eslint-community/eslint-utils": "^4.2.0", "@eslint-community/regexpp": "^4.11.0", - "@eslint/config-array": "^0.17.0", + "@eslint/config-array": "^0.17.1", "@eslint/eslintrc": "^3.1.0", - "@eslint/js": "9.7.0", + "@eslint/js": "9.8.0", "@humanwhocodes/module-importer": "^1.0.1", "@humanwhocodes/retry": "^0.3.0", "@nodelib/fs.walk": "^1.2.8", @@ -8769,9 +8986,9 @@ } }, "node_modules/lz-utils": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/lz-utils/-/lz-utils-2.0.2.tgz", - "integrity": "sha512-i1PJN4hNEevkrvLMqNWCCac1BcB5SRaghywG7HVzWOyVkFOasLCG19ND1sY1F/ZEsM6SnGtoXyBWnmfqOM5r6g==" + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/lz-utils/-/lz-utils-2.1.0.tgz", + "integrity": "sha512-CMkfimAypidTtWjNDxY8a1bc1mJdyEh04V2FfEQ5Zh8Nx4v7k850EYa+dOWGn9hKG5xOyHP5MkuduAZCTHRvJw==" }, "node_modules/magic-string": { "version": "0.30.10", @@ -10531,16 +10748,16 @@ } }, "node_modules/puppeteer": { - "version": "22.13.1", - "resolved": "https://registry.npmjs.org/puppeteer/-/puppeteer-22.13.1.tgz", - "integrity": "sha512-PwXLDQK5u83Fm5A7TGMq+9BR7iHDJ8a3h21PSsh/E6VfhxiKYkU7+tvGZNSCap6k3pCNDd9oNteVBEctcBalmQ==", + "version": "22.14.0", + "resolved": "https://registry.npmjs.org/puppeteer/-/puppeteer-22.14.0.tgz", + "integrity": "sha512-MGTR6/pM8zmWbTdazb6FKnwIihzsSEXBPH49mFFU96DNZpQOevCAZMnjBZGlZRGRzRK6aADCavR6SQtrbv5dQw==", "dev": true, "hasInstallScript": true, "dependencies": { - "@puppeteer/browsers": "2.2.4", + "@puppeteer/browsers": "2.3.0", "cosmiconfig": "^9.0.0", - "devtools-protocol": "0.0.1299070", - "puppeteer-core": "22.13.1" + "devtools-protocol": "0.0.1312386", + "puppeteer-core": "22.14.0" }, "bin": { "puppeteer": "lib/esm/puppeteer/node/cli.js" @@ -10550,15 +10767,15 @@ } }, "node_modules/puppeteer-core": { - "version": "22.13.1", - "resolved": "https://registry.npmjs.org/puppeteer-core/-/puppeteer-core-22.13.1.tgz", - "integrity": "sha512-NmhnASYp51QPRCAf9n0OPxuPMmzkKd8+2sB9Q+BjwwCG25gz6iuNc3LQDWa+cH2tyivmJppLhNNFt6Q3HmoOpw==", + "version": "22.14.0", + "resolved": "https://registry.npmjs.org/puppeteer-core/-/puppeteer-core-22.14.0.tgz", + "integrity": "sha512-rl4tOY5LcA3e374GAlsGGHc05HL3eGNf5rZ+uxkl6id9zVZKcwcp1Z+Nd6byb6WPiPeecT/dwz8f/iUm+AZQSw==", "dev": true, "dependencies": { - "@puppeteer/browsers": "2.2.4", - "chromium-bidi": "0.6.1", + "@puppeteer/browsers": "2.3.0", + "chromium-bidi": "0.6.2", "debug": "^4.3.5", - "devtools-protocol": "0.0.1299070", + "devtools-protocol": "0.0.1312386", "ws": "^8.18.0" }, "engines": { @@ -11144,9 +11361,9 @@ "dev": true }, "node_modules/semver": { - "version": "7.6.2", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.2.tgz", - "integrity": "sha512-FNAIBWCx9qcRhoHcgcJ0gvU7SN1lYU2ZXuSfl04bSC5OpvDHFyJCjdNHomPXxjQlCBU67YW64PzY7/VIEH7F2w==", + "version": "7.6.3", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.3.tgz", + "integrity": "sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A==", "bin": { "semver": "bin/semver.js" }, @@ -12723,6 +12940,15 @@ "@esbuild/win32-x64": "0.21.5" } }, + "node_modules/tunnel": { + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz", + "integrity": "sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg==", + "dev": true, + "engines": { + "node": ">=0.6.11 <=0.7.0 || >=0.7.3" + } + }, "node_modules/turbogrid": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/turbogrid/-/turbogrid-3.2.0.tgz", @@ -12789,6 +13015,18 @@ "through": "^2.3.8" } }, + "node_modules/undici": { + "version": "5.28.4", + "resolved": "https://registry.npmjs.org/undici/-/undici-5.28.4.tgz", + "integrity": "sha512-72RFADWFqKmUb2hmmvNODKL3p9hcB6Gt2DOQMis1SEBaV6a4MH8soBvzg+95CYhCKPFedut2JY9bMfrDl9D23g==", + "dev": true, + "dependencies": { + "@fastify/busboy": "^2.0.0" + }, + "engines": { + "node": ">=14.0" + } + }, "node_modules/undici-types": { "version": "5.26.5", "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", @@ -12847,6 +13085,12 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/universal-user-agent": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/universal-user-agent/-/universal-user-agent-6.0.1.tgz", + "integrity": "sha512-yCzhz6FN2wU1NiiQRogkTQszlQSlpWaw8SvVegAc+bDxbzHgh1vX8uIe8OYyMH6DwH+sdTJsgMl36+mSMdRJIQ==", + "dev": true + }, "node_modules/universalify": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz", @@ -12929,6 +13173,15 @@ "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==", "dev": true }, + "node_modules/uuid": { + "version": "8.3.2", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", + "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", + "dev": true, + "bin": { + "uuid": "dist/bin/uuid" + } + }, "node_modules/vary": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", @@ -13604,6 +13857,8 @@ "version": "1.0.0", "license": "MIT", "devDependencies": { + "@actions/core": "^1.10.1", + "@actions/github": "^6.0.0", "@jsdevtools/coverage-istanbul-loader": "^3.0.5", "@rollup/plugin-commonjs": "^26.0.1", "@rollup/plugin-typescript": "^11.1.6", @@ -13616,7 +13871,7 @@ "mocha": "^10.7.0", "open": "^10.1.0", "playwright": "^1.45.3", - "puppeteer": "^22.13.1", + "puppeteer": "^22.14.0", "rollup": "^4.19.0", "swc-loader": "^0.2.6", "ts-loader": "^9.5.1", diff --git a/package.json b/package.json index 57400eb2..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", @@ -96,7 +96,7 @@ "async-tick": "^1.0.0", "convert-source-map": "^2.0.0", "esbuild": "^0.23.0", - "eslint": "~9.7.0", + "eslint": "~9.8.0", "eslint-config-plus": "^2.0.2", "eslint-plugin-html": "^8.1.1", "eslint-plugin-vue": "^9.27.0", diff --git a/test/package.json b/test/package.json index 7ab13104..e3844461 100644 --- a/test/package.json +++ b/test/package.json @@ -7,6 +7,8 @@ "license": "MIT", "dependencies": {}, "devDependencies": { + "@actions/core": "^1.10.1", + "@actions/github": "^6.0.0", "@jsdevtools/coverage-istanbul-loader": "^3.0.5", "@rollup/plugin-commonjs": "^26.0.1", "@rollup/plugin-typescript": "^11.1.6", diff --git a/test/test-pr.js b/test/test-pr.js index d40717f5..902e95c1 100644 --- a/test/test-pr.js +++ b/test/test-pr.js @@ -1,40 +1,46 @@ -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 getPR = async () => { +const getPullRequestChanges = async () => { + + if (!github.context.payload.pull_request) { + // console.log(Object.keys(github.context)); + return []; + } + + 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 // myToken: ${{ secrets.GITHUB_TOKEN }} // https://help.github.com/en/actions/automating-your-workflow-with-github-actions/authenticating-with-the-github_token#about-the-github_token-secret const myToken = core.getInput('myToken'); + console.log('myToken', `${myToken}`.length); - const octokit = github.getOctokit(myToken); + // const octokit = github.getOctokit(myToken); - // You can also pass in additional options as a second parameter to getOctokit - // const octokit = github.getOctokit(myToken, {userAgent: "MyActionVersion1"}); + // // You can also pass in additional options as a second parameter to getOctokit + // // const octokit = github.getOctokit(myToken, {userAgent: "MyActionVersion1"}); - const { data } = await octokit.rest.pulls.get({ - owner: 'octokit', - repo: 'rest.js', - pull_number: 123, - mediaType: { - format: 'diff' - } - }); + // const { data } = await octokit.rest.pulls.get({ + // owner: 'octokit', + // repo: 'rest.js', + // pull_number: 123, + // mediaType: { + // format: 'diff' + // } + // }); - return data; + // return data; }; const test = async () => { - const pr = await getPR(); - console.log(pr); + const prChanges = await getPullRequestChanges(); + console.log('prChanges', prChanges); const coverageOptions = { // logging: 'debug', @@ -56,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'] }] ], @@ -75,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'); + // ===================================================== + + 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)); - await browser.close(); + await client.close(); - const coverageList = [... jsCoverage, ... cssCoverage]; + 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(); }; From ba1038a3a6cf49701156328396e74af393ef53c5 Mon Sep 17 00:00:00 2001 From: cenfun Date: Sat, 27 Jul 2024 11:17:17 +0800 Subject: [PATCH 3/3] add pull_request --- .github/workflows/test-pr.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/test-pr.yml b/.github/workflows/test-pr.yml index 7a7d502e..c6ead28d 100644 --- a/.github/workflows/test-pr.yml +++ b/.github/workflows/test-pr.yml @@ -4,8 +4,6 @@ on: pull_request: types: [opened, reopened, edited, review_requested] - branches: - - 'test-pr' # Allows you to run this workflow manually from the Actions tab workflow_dispatch: