diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 844e7a109b..7cb1db3e2a 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -1,3 +1,5 @@ +# derived from +# https://github.com/actions/starter-workflows/blob/main/ci/node.js.yml # This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node # For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions name: Node.js CI @@ -25,6 +27,7 @@ jobs: uses: actions/setup-node@v1 with: node-version: ${{ matrix.node-version }} - - run: npm ci - - run: npm run build --if-present - - run: npm test + # - run: npm ci + # - run: npm run build --if-present + # - run: npm test + # - run: npm run ci-github diff --git a/.travis.yml b/.travis.yml index 6414919a2c..1ca7c593a1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,7 +30,7 @@ script: - npm run build-ci services: - docker - - xvfb + # - xvfb # http://docs.travis-ci.com/user/workers/container-based-infrastructure sudo: false diff --git a/.vimrc b/.vimrc index d8761748e1..f7df832935 100644 --- a/.vimrc +++ b/.vimrc @@ -49,7 +49,7 @@ function! MyCommentRegion(...) " this function will comment selected-region " un-comment if a:1 == 'u' - '<,'>s/^\(\s*\)\(""\|#\|%%\|--\|\/\/\)!! /\1/e + '<,'>s/^\(\s*\)\(""\|#\|%%\|--\|\/\/\|::\)!! /\1/e '<,'>s/^\(\s*\)/\1\2/e '<,'>s/^\(\s*\)\/\*!! \(.*\) \*\//\1\2/e " comment \"\" @@ -70,6 +70,9 @@ function! MyCommentRegion(...) " comment // elseif a:1 == '/' '<,'>s/^\(\s*\)\(\S\)/\1\/\/!! \2/e + " comment :: + elseif a:1 == ':' + '<,'>s/^\(\s*\)\(\S\)/\1::!! \2/e " comment elseif a:1 == '<' '<,'>s/^\(\s*\)\(\S.*\)/\1/e @@ -160,9 +163,10 @@ nnoremap "\ :call MyStringifyRegion('\') nnoremap "u :call MyStringifyRegion('u') nnoremap #" :call MyCommentRegion('"') nnoremap #% :call MyCommentRegion('%') -nnoremap #- :call MyCommentRegion('-') nnoremap #* :call MyCommentRegion('*') +nnoremap #- :call MyCommentRegion('-') nnoremap #/ :call MyCommentRegion('/') +nnoremap #: :call MyCommentRegion(':') nnoremap # :call MyCommentRegion('#') nnoremap #u :call MyCommentRegion('u') " visual-mode remap @@ -171,9 +175,10 @@ vnoremap "\ :call MyStringifyRegion('\') vnoremap "u :call MyStringifyRegion('u') vnoremap #" :call MyCommentRegion('"') vnoremap #% :call MyCommentRegion('%') -vnoremap #- :call MyCommentRegion('-') vnoremap #* :call MyCommentRegion('*') +vnoremap #- :call MyCommentRegion('-') vnoremap #/ :call MyCommentRegion('/') +vnoremap #: :call MyCommentRegion(':') vnoremap #< :call MyCommentRegion('<') vnoremap # :call MyCommentRegion('#') vnoremap #u :call MyCommentRegion('u') diff --git a/README.md b/README.md index 10dbf8f268..50d9ca8be3 100644 --- a/README.md +++ b/README.md @@ -51,8 +51,8 @@ this zero-dependency package will provide high-level functions to to build, test #### cli help ![screenshot](https://kaizhu256.github.io/node-utility2/build/screenshot.npmPackageCliHelp.svg) -#### changelog 2020.11.3 -- update jslint to v2020.11.6 +#### changelog 2020.11.12 +- jslint - update to v2020.11.6 - update function chromeDevtoolsClient with timeout - remove file lib.puppeteer.js and replace with function chromeDevtoolsClientCreate - remove dependency on env-var \$CHROME_BIN @@ -63,6 +63,7 @@ this zero-dependency package will provide high-level functions to to build, test - none #### todo +- fix test-report bug with duplicate github and heroku tests - migrate from travis to github-actions - update function fsWriteFileWithMkdirp to write to tmpfile first - jslint - unmangle function jslintAutofixLocalFunction @@ -1177,7 +1178,7 @@ require("http").createServer(function (req, res) { "engines": { "node": ">=12.0" }, - "fileCount": 28, + "fileCount": 27, "homepage": "https://github.com/kaizhu256/node-utility2", "keywords": [ "continuous-integration", @@ -1209,12 +1210,12 @@ require("http").createServer(function (req, res) { "utility2Dependents": [ "2020.06.08 apidoc-lite", "2020.06.12 bootstrap-lite", - "2020.08.01 istanbul-lite", "2020.08.19 sqlite3-lite", "2020.10.27 jslint-lite", - "2020.10.27 utility2" + "2020.11.12 istanbul-lite", + "2020.11.12 utility2" ], - "version": "2020.11.3" + "version": "2020.11.12" } ``` @@ -1258,9 +1259,9 @@ RUN (set -e; \ gnupg; \ (busybox --list | xargs -n1 /bin/sh -c \ 'ln -s /bin/busybox /bin/$0 2>/dev/null' || true); \ - curl -Lf https://deb.nodesource.com/setup_12.x | /bin/bash -; \ + curl -Lf https://deb.nodesource.com/setup_14.x | /bin/bash -; \ apt-get install -y nodejs; \ - (cd /usr/lib && npm install sqlite3@4); \ + (cd /usr/lib && npm install sqlite3@5); \ ) # install google-chrome-stable RUN (set -e; \ @@ -1299,7 +1300,7 @@ MAINTAINER kai zhu # install utility2 RUN (set -e; \ export DEBIAN_FRONTEND=noninteractive; \ - npm install -g eslint puppeteer \ + npm install -g eslint \ rm -f /tmp/.X99-lock && export DISPLAY=:99.0 && (Xvfb "$DISPLAY" &); \ npm install kaizhu256/node-utility2#alpha; \ cp -a node_modules /; \ diff --git a/lib.istanbul.js b/lib.istanbul.js index 3468bc22d1..e612cddb5d 100755 --- a/lib.istanbul.js +++ b/lib.istanbul.js @@ -1,6 +1,6 @@ #!/usr/bin/env node /* - * lib.istanbul.js (2020.8.1) + * lib.istanbul.js (2020.11.12) * https://github.com/kaizhu256/node-istanbul-lite * this zero-dependency package will provide browser-compatible version of istanbul coverage-tool (v0.4.5), with working web-demo * @@ -11367,17 +11367,19 @@ local.coverageMerge = function (coverage1 = {}, coverage2 = {}) { return coverage1; }; -local.coverageReportCreate = function (opt) { +local.coverageReportCreate = function ({ + coverage, + coverageInclude +}) { /* * this function will - // 1. merge previous /coverage.json into .coverage - // 2. convert .coverage to + // 1. merge previous /coverage.json into + // 2. convert to // 3. convert to // 4. convert to text-report /coverage.txt // 5. convert to html-report /\* // 6. return coverage-report in html-format as single document */ - let coverageInclude; let dirCoverage; let filePrefix; let htmlAll; @@ -11388,9 +11390,6 @@ local.coverageReportCreate = function (opt) { let nodeRoot; let summaryDict; let tmp; - if (!(opt && opt.coverage)) { - return ""; - } // init function nodeChildAdd = function (node, child) { /* @@ -11516,15 +11515,15 @@ local.coverageReportCreate = function (opt) { ); }); }; - // 1. merge previous /coverage.json into .coverage + // 1. merge previous /coverage.json into dirCoverage = path.resolve(".tmp/build/coverage"); - coverageInclude = opt.coverageInclude || globalThis.__coverageInclude__; + coverageInclude = coverageInclude || globalThis.__coverageInclude__; if (!local.isBrowser && process.env.npm_config_mode_coverage_merge) { console.error( "istanbul - merging file " + dirCoverage + "/coverage.json to coverage" ); - local.coverageMerge(opt.coverage, local.fsReadFileOrDefaultSync( + local.coverageMerge(coverage, local.fsReadFileOrDefaultSync( dirCoverage + "/coverage.json", "json", {} @@ -11537,9 +11536,9 @@ local.coverageReportCreate = function (opt) { coverageInclude[file] = 1; }); } - // 2. convert .coverage to + // 2. convert to summaryDict = {}; - Object.entries(opt.coverage).forEach(function ([ + Object.entries(coverage).forEach(function ([ file, fileCoverage ]) { @@ -11549,7 +11548,7 @@ local.coverageReportCreate = function (opt) { let summary; if (fileCoverage && coverageInclude.hasOwnProperty(file)) { // reset line-cnt - delete opt.coverage[file].l; + delete coverage[file].l; // init summary summary = { branches: { @@ -11690,11 +11689,11 @@ local.coverageReportCreate = function (opt) { // 4. convert to text-report /coverage.txt reportTextWrite(nodeRoot, dirCoverage); // 5. convert to html-report /\* - htmlAll = reportHtmlWrite(nodeRoot, dirCoverage, opt.coverage); - // save opt.coverage to dirCoverage/coverage.json + htmlAll = reportHtmlWrite(nodeRoot, dirCoverage, coverage); + // save coverage to dirCoverage/coverage.json fileWrite( dirCoverage + "/coverage.json", - JSON.stringify(opt.coverage, undefined, 4) + JSON.stringify(coverage, undefined, 4) ); // save coverageInclude to dirCoverage/coverage.include.json fileWrite( diff --git a/lib.jslint.js b/lib.jslint.js index e696cc795a..2bf399061c 100755 --- a/lib.jslint.js +++ b/lib.jslint.js @@ -16319,8 +16319,8 @@ local.jslint0 = Object.freeze(function ( // expected_a_before_b: "Expected '{a}' before '{b}'.", case "expected_a_before_b": bb = ( - aa.slice(0, warning.column) + warning.a - + aa.slice(warning.column) + aa.slice(0, warning.column - 1) + warning.a + + aa.slice(warning.column - 1) ); break; // expected_identifier_a: diff --git a/lib.utility2.js b/lib.utility2.js index 2de3446732..b6e0d5f988 100755 --- a/lib.utility2.js +++ b/lib.utility2.js @@ -1,6 +1,6 @@ #!/usr/bin/env node /* - * lib.utility2.js (2020.11.3) + * lib.utility2.js (2020.11.12) * https://github.com/kaizhu256/node-utility2 * this zero-dependency package will provide high-level functions to to build, test, and deploy webapps * @@ -2228,7 +2228,7 @@ local.browserTest = function ({ url }, onError) { /* - * this function will spawn google-puppeteer-process to test + * this function will spawn google-chrome-process to test */ let chromeClient; let fileScreenshot; @@ -2282,6 +2282,9 @@ local.browserTest = function ({ }); }).then(function (data) { chromeClient = data; + return chromeClient.navigate({ + url + }); }).then(function () { promiseList = []; promiseList.push(chromeClient.screenshot({ @@ -2297,8 +2300,10 @@ local.browserTest = function ({ + "}\n" ); return new Promise(function (resolve) { - chromeClient.on("Performance.metrics", function (evt) { - if (isDone || evt.title !== testId) { + chromeClient.on("Performance.metrics", function ({ + title + }) { + if (isDone || title !== testId) { return; } isDone = true; @@ -2311,8 +2316,6 @@ local.browserTest = function ({ }); }); }).then(function (data) { - // cleanup chromeClient - chromeClient.destroy(); data = JSON.parse(data); // merge browser-screenshot data.testPlatformList[0].screenshot = fileScreenshot.replace(( @@ -2342,6 +2345,8 @@ local.browserTest = function ({ })); return Promise.all(promiseList); }).then(function () { + // cleanup chromeClient + chromeClient.destroy(); onError2(); }); }; @@ -3061,8 +3066,7 @@ local.chromeDevtoolsClientCreate = function ({ modeMockProcessPlatform, modeSilent, processPlatform, - timeout, - url + timeout }) { /* * this function with create chrome-devtools-client from @@ -3106,7 +3110,9 @@ local.chromeDevtoolsClientCreate = function ({ } } catch (ignore) {} // rm -rf - local.fsRmrfSync(chromeUserDataDir); + require("fs").rmdirSync(chromeUserDataDir, { + recursive: true + }); // destroy , , chromeClient.destroy(); try { @@ -3143,10 +3149,10 @@ local.chromeDevtoolsClientCreate = function ({ /* * this function will implement stream.Duplex.prototype._write */ + // console.error("SEND \u25ba " + payload.slice(0, 256).toString()); let header; let maskKey; let result; - // console.error("SEND \u25ba " + payload.slice(0, 256).toString()); // init header header = Buffer.alloc(2 + 8 + 4); // init fin = true @@ -3208,35 +3214,72 @@ local.chromeDevtoolsClientCreate = function ({ return result.value; }); }; - chromeClient.on("data", function (evt) { + chromeClient.on("data", function (payload) { /* - * this function will handle callback for + * this function will handle callback for * received from chrome-browser using chrome-devtools-protocol */ - // console.error("\u25c0 RECV " + evt.slice(0, 256).toString()); + // console.error("\u25c0 RECV " + payload.slice(0, 256).toString()); let callback; - // init evt - evt = JSON.parse(evt); - local.assertOrThrow(!evt.method || ( + let { + method, + id, + error, + params, + result + } = JSON.parse(payload); + local.assertOrThrow(!method || ( /^[A-Z]\w*?\.[a-z]\w*?$/ - ).test(evt.method), new Error( - "chrome-devtools - invalid evt.method " + evt.method + ).test(method), new Error( + "chrome-devtools - invalid method " + method )); // init callback - callback = callbackDict[evt.id]; - delete callbackDict[evt.id]; + callback = callbackDict[id]; + delete callbackDict[id]; // callback.resolve if (callback) { // preserve stack-trace callback.err.message = "chrome-devtools - " - + JSON.stringify(evt.error); - local.assertOrThrow(!evt.error, callback.err); - callback.resolve(evt.result); + + JSON.stringify(error); + local.assertOrThrow(!error, callback.err); + callback.resolve(result); return; } - local.assertOrThrow(!evt.error, "chrome-devtools - " + evt.error); - chromeClient.emit(evt.method, evt.params); + local.assertOrThrow(!error, "chrome-devtools - " + error); + chromeClient.emit(method, params); }); + chromeClient.navigate = function ({ + url + }) { + /* + * this function will navigate to webpage + */ + let chromeFrameId; + console.error("chrome-devtools - Page.navigate " + url); + chromeClient.rpc("Page.navigate", { + url + }); + // wait for page to load + chromeClient.rpc("Page.getFrameTree").then(function ({ + frameTree + }) { + chromeFrameId = frameTree.frame.id; + }); + return new Promise(function (resolve) { + chromeClient.on("Page.lifecycleEvent", function onLoad({ + frameId, + name + }) { + if (frameId === chromeFrameId && name === "load") { + chromeClient.removeListener( + "Page.lifecycleEvent", + onLoad + ); + resolve(); + } + }); + }); + }; chromeClient.rpc = function (method, params) { /* * this function will message-pass @@ -3501,20 +3544,26 @@ Application data: y bytes require("os").tmpdir(), "puppeteer_dev_profile-" )); + chromeBin = chromeBin || ( + processPlatform === "darwin" + ? "/Applications/Google Chrome.app/Contents/MacOS/" + + "Google Chrome" + : processPlatform === "win32" + ? "C:\\Program Files (x86)\\Google\\Chrome\\Application\\" + + "chrome.exe" + : "/usr/bin/google-chrome-stable" + ); + console.error("chrome-devtools - spawn " + chromeBin); chromeProcess = require("child_process").spawn(( - chromeBin || ( - processPlatform === "darwin" - ? "/Applications/Google Chrome.app/Contents/MacOS/" - + "Google Chrome" - : processPlatform === "win32" - ? "C:\\Program Files (x86)\\Google\\Chrome\\Application\\" - + "chrome.exe" - : "/usr/bin/google-chrome-stable" - ) + chromeBin ), [ "--headless", "--incognito", - "--no-sandbox", + ( + processPlatform === "linux" + ? "--no-sandbox" + : "" + ), "--remote-debugging-port=0", "--user-data-dir=" + chromeUserDataDir ], { @@ -3570,6 +3619,9 @@ Application data: y bytes * this function will init */ let secWebsocketKey; + console.error( + "chrome-devtools - connect websocket " + websocketUrl + ); secWebsocketKey = require("crypto").randomBytes(16).toString("base64"); return new Promise(function (resolve) { require("http").get(Object.assign(require("url").parse( @@ -3614,6 +3666,7 @@ Application data: y bytes /* * this function will init */ + console.error("chrome-devtools - Target.createTarget about:blank"); return chromeClient.rpc("Target.createTarget", { url: "about:blank" }).then(function (data) { @@ -3630,7 +3683,6 @@ Application data: y bytes /* * this function will navigate chrome to */ - let frameId; // init screensize chromeClient.rpc("Emulation.setDeviceMetricsOverride", { deviceScaleFactor: 1, @@ -3648,27 +3700,6 @@ Application data: y bytes enabled: true }); chromeClient.rpc("Performance.enable", undefined); - // navigate page to url - chromeClient.rpc("Page.navigate", { - url - }); - // wait for page to load - chromeClient.rpc("Page.getFrameTree").then(function ({ - frameTree - }) { - frameId = frameTree.frame.id; - }); - return new Promise(function (resolve) { - chromeClient.on("Page.lifecycleEvent", function onLoad(evt) { - if (evt.frameId === frameId && evt.name === "load") { - chromeClient.removeListener( - "Page.lifecycleEvent", - onLoad - ); - resolve(); - } - }); - }); }).then(function () { /* * this function will resolve diff --git a/lib.utility2.sh b/lib.utility2.sh index 150be69b2f..5776e4966b 100755 --- a/lib.utility2.sh +++ b/lib.utility2.sh @@ -296,7 +296,7 @@ shBrowserScreenshot () {(set -e )} shBrowserTest () {(set -e -# this function will spawn google-puppeteer-process to test url $1, +# this function will spawn google-chrome-process to test url $1, # and merge test-report into existing test-report shBuildInit export MODE_BUILD="${MODE_BUILD:-browserTest}" @@ -1923,10 +1923,6 @@ shGitSquashPop () {(set -e # reset git to previous $COMMIT git reset "$COMMIT" git add . - if [ -f lib.utility2.sh ] - then - git add -f package-lock.json - fi # commit HEAD immediately after previous $COMMIT git commit -am "$MESSAGE" || true )} @@ -3449,32 +3445,32 @@ shTravisRepoCreate () {(set -e url }).then(function (opt) { require("fs").promises.writeFile(( - "/tmp/githubRepo/" + process.env.GITHUB_REPO + "/" - + require("path").basename(url) + require("os").tmpdir() + "/githubRepo/" + + process.env.GITHUB_REPO + "/" + require("path").basename(url) ), opt.responseText); }); }); - require("fs").promises.writeFile( - "/tmp/githubRepo/" + process.env.GITHUB_REPO + "/package.json", - JSON.stringify({ - devDependencies: { - utility2: "kaizhu256/node-utility2#alpha" - }, - homepage: "https://github.com/" + process.env.GITHUB_REPO, - name: process.env.GITHUB_REPO.replace(( - /.+?\/node-|.+?\// - ), ""), - repository: { - type: "git", - url: "https://github.com/" + process.env.GITHUB_REPO + ".git" - }, - scripts: { - "build-ci": "utility2 shBuildCi", - "test": "./npm_scripts.sh" - }, - version: "0.0.1" - }, undefined, 4) - ); + require("fs").promises.writeFile(( + require("os").tmpdir() + "/githubRepo/" + + process.env.GITHUB_REPO + "/package.json" + ), JSON.stringify({ + devDependencies: { + utility2: "kaizhu256/node-utility2#alpha" + }, + homepage: "https://github.com/" + process.env.GITHUB_REPO, + name: process.env.GITHUB_REPO.replace(( + /.+?\/node-|.+?\// + ), ""), + repository: { + type: "git", + url: "https://github.com/" + process.env.GITHUB_REPO + ".git" + }, + scripts: { + "build-ci": "utility2 shBuildCi", + "test": "./npm_scripts.sh" + }, + version: "0.0.1" + }, undefined, 4)); await sleep(5000); // request travis-userid tmp = await httpRequest({ diff --git a/package-lock.json b/package-lock.json deleted file mode 100644 index 2801113196..0000000000 --- a/package-lock.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "utility2", - "version": "0.0.1", - "lockfileVersion": 1 -} diff --git a/package.json b/package.json index 4116687a14..b775bd85cc 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "engines": { "node": ">=12.0" }, - "fileCount": 28, + "fileCount": 27, "homepage": "https://github.com/kaizhu256/node-utility2", "keywords": [ "continuous-integration", @@ -44,10 +44,10 @@ "utility2Dependents": [ "2020.06.08 apidoc-lite", "2020.06.12 bootstrap-lite", - "2020.08.01 istanbul-lite", "2020.08.19 sqlite3-lite", "2020.10.27 jslint-lite", - "2020.10.27 utility2" + "2020.11.12 istanbul-lite", + "2020.11.12 utility2" ], - "version": "2020.11.3" + "version": "2020.11.12" }