this package will run dynamic browser tests with coverage (via istanbul and electron)
| git-branch : | master | beta | alpha |
|---|---|---|---|
| test-server 1 : | ![]() | ![]() | ![]() |
| test-server 2 : | ![]() | ![]() | ![]() |
| test-report : | |||
| coverage : | |||
| build-artifacts : |
# example.sh
# this shell script will
# npm install utility2
# serve a webpage that will interactively run browser tests with coverage
# instruction
# 1. copy and paste this entire shell script into a console and press enter
# 2. open a browser to http://localhost:8081
# 3. edit or paste script in browser to cover and test
shExampleSh() {(set -e
# npm install utility2
npm install utility2
# serve a webpage that will interactively run browser tests with coverage
cd node_modules/utility2 && export PORT=8081 && npm start
)}
shExampleSh


/*
example.js
this shared browser / node script will run browser tests with coverage
(via istanbul and electron)
instruction
1. save this script as example.js
2. run the shell command:
$ npm install electron-lite utility2 && \
export PATH="$(pwd)/node_modules/.bin:$PATH" && \
export PORT=8081 && \
export npm_config_mode_coverage=utility2 && \
node_modules/.bin/utility2 test example.js
3. view test-report in ./tmp/build/test-report.html
4. view coverage in ./tmp/build/coverage.html/index.html
*/
/* istanbul instrument in package utility2 */
/*jslint
bitwise: true,
browser: true,
maxerr: 8,
maxlen: 96,
node: true,
nomen: true,
regexp: true,
stupid: true
*/
(function () {
'use strict';
var local;
// run shared js-env code - pre-init
(function () {
// init local
local = {};
// init modeJs
local.modeJs = (function () {
try {
return typeof navigator.userAgent === 'string' &&
typeof document.querySelector('body') === 'object' &&
typeof XMLHttpRequest.prototype.open === 'function' &&
'browser';
} catch (errorCaughtBrowser) {
return module.exports &&
typeof process.versions.node === 'string' &&
typeof require('http').createServer === 'function' &&
'node';
}
}());
/* istanbul ignore next */
// re-init local
local = local.modeJs === 'browser'
? window.utility2.local
: module.isRollup
? module
: require('utility2').local;
// export local
local.global.local = local;
// init envDict
local.utility2.objectSetDefault(local.utility2.envDict, {
npm_package_description: 'undefined module',
npm_package_name: 'undefined',
npm_package_version: '0.0.1'
});
// run test-server
local.utility2.testRunServer(local);
// init assets
local.utility2.assetsDict['/assets.hello'] = 'hello';
}());
switch (local.modeJs) {
// run browser js-env code - post-init
case 'browser':
// init tests
local.testCase_ajax_200 = function (options, onError) {
/*
* this function will test ajax's "200 ok" handling-behavior
*/
options = {};
// test ajax-path 'assets.hello'
local.utility2.ajax({
url: 'assets.hello'
}, function (error, xhr) {
local.utility2.tryCatchOnError(function () {
// validate no error occurred
local.utility2.assert(!error, error);
// validate data
options.data = xhr.responseText;
local.utility2.assert(options.data === 'hello', options.data);
onError();
}, onError);
});
};
local.testCase_ajax_404 = function (options, onError) {
/*
* this function will test ajax's "404 not found" handling-behavior
*/
options = {};
// test ajax-path '/undefined'
local.utility2.ajax({ url: '/undefined' }, function (error) {
local.utility2.tryCatchOnError(function () {
// validate error occurred
local.utility2.assert(error, error);
options.statusCode = error.statusCode;
// validate 404 http statusCode
local.utility2.assert(options.statusCode === 404, options.statusCode);
onError();
}, onError);
});
};
/* istanbul ignore next */
local.testRun = function (event) {
if (local.utility2.modeTest) {
return;
}
switch (event && event.currentTarget.id) {
case 'testRunButton1':
local.modeTest = true;
local.utility2.testRun(local);
break;
default:
// try to JSON.stringify #inputTextarea1
try {
document.querySelector('#outputPreJsonStringify1').textContent =
local.utility2.jsonStringifyOrdered(
JSON.parse(document.querySelector('#inputTextarea1').value),
null,
4
);
} catch (ignore) {
}
// jslint #inputTextarea1
local.utility2.jslint.jslintAndPrint(
document.querySelector('#inputTextarea1').value,
'inputTextarea1.js'
);
document.querySelector('#outputPreJslint1').textContent =
local.utility2.jslint.errorText
.replace((/\u001b\[\d+m/g), '')
.trim();
// try to cleanup __coverage__
try {
delete local.global.__coverage__['/inputTextarea1.js'];
} catch (ignore) {
}
// try to eval input-code
try {
/*jslint evil: true*/
eval(local.utility2.istanbul.instrumentSync(
document.querySelector('#inputTextarea1').value,
'/inputTextarea1.js'
));
local.utility2.istanbul.coverageReportCreate({
coverage: window.__coverage__
});
} catch (errorCaught) {
document.querySelector('.istanbulCoverageDiv').innerHTML =
'<pre>' + errorCaught.stack.replace((/</g), '<') + '</pre>';
}
}
};
// init event-handling
[
'#inputTextarea1',
'#testRunButton1'
].forEach(function (element) {
if (element.indexOf('#inputTextarea') === 0) {
document.querySelector(element).addEventListener('keyup', local.testRun);
return;
}
document.querySelector(element).addEventListener('click', local.testRun);
});
// run tests
local.testRun();
break;
// run node js-env code - post-init
case 'node':
// init tests
local.testCase_webpage_default = function (options, onError) {
/*
* this function will test the webpage's default handling-behavior
*/
options = {
modeCoverageMerge: true,
url: local.utility2.serverLocalHost + '?modeTest=1'
};
local.utility2.browserTest(options, onError);
};
// export local
module.exports = local;
// init assets
local.utility2.tryCatchOnError(function () {
local.utility2.assetsDict['/assets.example.js'] =
local.fs.readFileSync(__filename, 'utf8');
}, local.utility2.nop);
/* jslint-ignore-begin */
local.templateIndexHtml = '\
<!doctype html>\n\
<html lang="en">\n\
<head>\n\
<meta charset="UTF-8">\n\
<title>\n\
{{envDict.npm_package_name}} v{{envDict.npm_package_version}}\n\
</title>\n\
<link href="assets.utility2.css" rel="stylesheet">\n\
<style>\n\
/*csslint\n\
box-sizing: false,\n\
ids: false,\n\
universal-selector: false\n\
*/\n\
* {\n\
box-sizing: border-box;\n\
}\n\
body {\n\
background-color: #fff;\n\
font-family: Helvetica Neue, Helvetica, Arial, sans-serif;\n\
}\n\
body > * {\n\
margin-bottom: 1rem;\n\
}\n\
#outputPreJslint1 {\n\
color: #f00;\n\
}\n\
textarea {\n\
font-family: monospace;\n\
height: 32rem;\n\
width: 100%;\n\
}\n\
</style>\n\
</head>\n\
<body>\n\
<div class="ajaxProgressDiv" style="display: block;">\n\
<div class="ajaxProgressBarDiv ajaxProgressBarDivLoading">loading</div>\n\
</div>\n\
<h1>\n\
<a\n\
{{#if envDict.npm_package_homepage}}\n\
href="{{envDict.npm_package_homepage}}"\n\
{{/if envDict.npm_package_homepage}}\n\
target="_blank"\n\
>{{envDict.npm_package_name}} v{{envDict.npm_package_version}}</a>\n\
{{#if envDict.NODE_ENV}}\n\
(NODE_ENV={{envDict.NODE_ENV}})\n\
{{/if envDict.NODE_ENV}}\n\
</h1>\n\
<h3>{{envDict.npm_package_description}}</h3>\n\
<h4><a download href="assets.app.js">download standalone app</a></h4>\n\
<button id="testRunButton1">run internal test</button><br>\n\
<div>edit or paste script below to cover and test</div>\n\
<textarea id="inputTextarea1">\n\
/*jslint\n\
browser: true\n\
*/\n\
(function () {\n\
"use strict";\n\
var testCaseDict;\n\
testCaseDict = {};\n\
testCaseDict.modeTest = true;\n\
\n\
// comment this testCase to disable the failed assertion demo\n\
testCaseDict.testCase_failed_assertion_demo = function (\n\
options,\n\
onError\n\
) {\n\
/*\n\
* this function will demo a failed assertion test\n\
*/\n\
// jslint-hack\n\
window.utility2.nop(options);\n\
window.utility2.assert(false, "this is a failed assertion demo");\n\
onError();\n\
};\n\
\n\
testCaseDict.testCase_passed_ajax_demo = function (options, onError) {\n\
/*\n\
* this function will demo a passed ajax test\n\
*/\n\
var data;\n\
options = { url: "/" };\n\
// test ajax request for main-page "/"\n\
window.utility2.ajax(options, function (error, xhr) {\n\
try {\n\
// validate no error occurred\n\
window.utility2.assert(!error, error);\n\
// validate non-empty data\n\
data = xhr.responseText;\n\
window.utility2.assert(data && data.length > 0, data);\n\
// validate "200 ok" status\n\
if (xhr.statusCode === 200) {\n\
window.utility2.assert(data, data);\n\
}\n\
onError();\n\
} catch (errorCaught) {\n\
onError(errorCaught);\n\
}\n\
});\n\
};\n\
\n\
if (!window.utility2.modeTest) {\n\
window.utility2.testRun(testCaseDict);\n\
}\n\
}());\n\
</textarea>\n\
<pre id="outputPreJsonStringify1"></pre>\n\
<pre id="outputPreJslint1"></pre>\n\
<div class="testReportDiv" style="display: none;"></div>\n\
<div class="istanbulCoverageDiv"></div>\n\
{{#if isRollup}}\n\
<script src="assets.app.min.js"></script>\n\
{{#unless isRollup}}\n\
<script src="assets.utility2.lib.istanbul.js"></script>\n\
<script src="assets.utility2.lib.jslint.js"></script>\n\
<script src="assets.utility2.lib.nedb.js"></script>\n\
<script src="assets.utility2.lib.sjcl.js"></script>\n\
<script src="assets.utility2.lib.uglifyjs.js"></script>\n\
<script src="assets.utility2.js"></script>\n\
<script src="jsonp.utility2.stateInit?callback=window.utility2.stateInit"></script>\n\
<script >window.utility2.onReadyBefore.counter += 1;</script>\n\
<script src="assets.example.js"></script>\n\
<script src="assets.test.js"></script>\n\
<script >window.utility2.onReadyBefore();</script>\n\
{{/if isRollup}}\n\
</body>\n\
</html>\n\
';
/* jslint-ignore-end */
local.utility2.assetsDict['/'] = local.utility2.templateRender(
local.templateIndexHtml,
{ envDict: local.utility2.envDict }
);
break;
}
}());


{
"package.json": true,
"author": "kai zhu <[email protected]>",
"bin": {
"utility2": "index.sh",
"utility2-istanbul": "lib.istanbul.js",
"utility2-jslint": "lib.jslint.js",
"utility2-uglifyjs": "lib.uglifyjs.js"
},
"description": "{{packageJson.description}}",
"devDependencies": {
"electron-lite": "kaizhu256/node-electron-lite#alpha"
},
"engines": { "node": ">=4.0" },
"homepage": "https://github.com/kaizhu256/node-utility2",
"keywords": [
"atom", "atom-shell",
"browser", "build",
"ci", "code", "continuous-integration", "cover", "coverage",
"electron",
"headless", "headless-browser",
"instrument", "istanbul",
"jscover", "jscoverage",
"phantom", "phantomjs",
"slimer", "slimerjs",
"test", "travis", "travis-ci",
"web"
],
"license": "MIT",
"name": "utility2",
"os": ["darwin", "linux"],
"repository": {
"type": "git",
"url": "https://github.com/kaizhu256/node-utility2.git"
},
"scripts": {
"build-app": "npm test --mode-test-case=testCase_build_app",
"build-ci": "./index.sh shRun shReadmeBuild",
"build-doc": "npm test --mode-test-case=testCase_build_doc",
"env": "env",
"example.js": "\
. ./index.sh && \
shInit && \
shFileTrimLeft tmp/README.example.js && \
shRunScreenCapture shReadmeTestJs example.js",
"example.sh": "./index.sh shRunScreenCapture shReadmeTestSh example.sh",
"start": "\
export PORT=${PORT:-8080} && \
if [ -f assets.app.js ]; then node assets.app.js; return; fi && \
export npm_config_mode_auto_restart=1 && \
./index.sh shRun shIstanbulCover test.js",
"start-example": "\
./index.sh shRun && \
cp tmp/README.example.js example.js && \
export PORT=8081 && \
node example.js \
",
"start-heroku": "\
export npm_config_mode_backend=1 && \
node assets.app.js \
",
"start-standalone": "\
npm run build-app && \
node tmp/build/app/assets.app.js \
",
"test": "\
export PORT=$(./index.sh shServerPortRandom) && \
export PORT_REPL=$(./index.sh shServerPortRandom) && \
export npm_config_mode_auto_restart=1 && \
./index.sh test test.js",
"test-all": "npm test --mode-coverage=all",
"test-published": "./index.sh shRun shNpmTestPublished"
},
"version": "2016.7.5"
}
# Dockerfile.emscripten
# docker build -f tmp/README.Dockerfile.emscripten -t emscripten .
FROM kaizhu256/node-utility2:latest
MAINTAINER kai zhu <[email protected]>
# https://kripken.github.io/emscripten-site/docs
# /building_from_source/building_emscripten_from_source_using_the_sdk.html
# build emscripten v1.36.0
RUN cd / && \
git clone https://github.com/juj/emsdk.git --branch=master --single-branch && \
cd /emsdk && \
./emsdk install -j2 --shallow sdk-master-64bit && \
./emsdk activate && \
find . -name ".git" -print0 | xargs -0 rm -fr && \
find . -name "src" -print0 | xargs -0 rm -fr
# Dockerfile.latest
# https://hub.docker.com/_/node/
FROM node:latest
MAINTAINER kai zhu <[email protected]>
VOLUME [ \
"/mnt", \
"/root", \
"/tmp", \
"/var/cache", \
"/var/lib/apt/lists", \
"/var/log", \
"/var/tmp" \
]
WORKDIR /tmp
# cache apt-get
RUN apt-get update && \
apt-get install -y \
busybox \
chromium \
cmake \
default-jre \
gconf2 \
less \
libnotify4 \
vim \
xvfb
# cache electron-lite
RUN npm install electron-lite && \
cp /tmp/electron-*.zip /
Content type
Image
Digest
Size
372.4 MB
Last updated
almost 6 years ago
docker pull kaizhu256/node-utility2