Skip to content

Commit

Permalink
[[FEAT]] Replacing PhantomJS with Puppeteer
Browse files Browse the repository at this point in the history
Signed-off-by: ossdev07 <ossdev@puresoftware.com>
  • Loading branch information
ossdev07 committed Dec 13, 2019
1 parent 69767ed commit 51963a3
Show file tree
Hide file tree
Showing 15 changed files with 55 additions and 128 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -5,7 +5,7 @@ before_install:
# they are only needed to verify correctness in a browser-like environment,
# they can be removed (and the tests skipped) without effecting coverage.
- if [[ $(node --version) != v10* ]] ; then
node scripts/remove-dev-dependencies.js phantom phantomjs-prebuilt;
node scripts/remove-dev-dependencies.js puppeteer;
fi
script:
- npm run pretest
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Expand Up @@ -17,7 +17,7 @@ install:
# These packages cannot be installed in legacy versions of Node.js. Because
# they are only needed to verify correctness in a browser-like environment,
# they can be removed (and the tests skipped) without effecting coverage.
- if NOT "%nodejs_version%" == "10" node scripts/remove-dev-dependencies.js phantom phantomjs-prebuilt
- if NOT "%nodejs_version%" == "10" node scripts/remove-dev-dependencies.js puppeteer
- npm install

build: off
Expand Down
16 changes: 8 additions & 8 deletions dist/jshint-rhino.js
Expand Up @@ -21946,12 +21946,12 @@ exports.bool = {

/**
* This option defines globals available when your core is running inside
* of the PhantomJS runtime environment. [PhantomJS](http://phantomjs.org/)
* of the Chrome runtime environment. [chrome](http://chromium.org/)
* is a headless WebKit scriptable with a JavaScript API. It has fast and
* native support for various web standards: DOM handling, CSS selector,
* JSON, Canvas, and SVG.
*/
phantom : true
chrome : true
},

// Obsolete options
Expand Down Expand Up @@ -23480,7 +23480,7 @@ var state = {
* @returns {boolean}
*/
impliedClosure: function() {
return this.option.node || this.option.phantom || this.option.browserify;
return this.option.node || this.option.chrome || this.option.browserify;
},

// Assumption: chronologically ES3 < ES5 < ES6 < Moz
Expand Down Expand Up @@ -24287,8 +24287,8 @@ exports.browserify = {
process : true
};

exports.phantom = {
phantom : true,
exports.chrome = {
chrome : true,
require : true,
WebPage : true,
console : true, // in examples, but undocumented
Expand Down Expand Up @@ -24847,8 +24847,8 @@ var JSHINT = (function() {
combine(predefined, vars.typed);
}

if (state.option.phantom) {
combine(predefined, vars.phantom);
if (state.option.chrome) {
combine(predefined, vars.chrome);
}

if (state.option.prototypejs) {
Expand Down Expand Up @@ -31163,4 +31163,4 @@ if (typeof exports === "object" && exports) {

JSHINT = require('jshint').JSHINT;
if (typeof exports === 'object' && exports) exports.JSHINT = JSHINT;
}());
}());
16 changes: 8 additions & 8 deletions dist/jshint.js
Expand Up @@ -21944,12 +21944,12 @@ exports.bool = {

/**
* This option defines globals available when your core is running inside
* of the PhantomJS runtime environment. [PhantomJS](http://phantomjs.org/)
* of the Chrome runtime environment. [Chrome](http://chromium.org/)
* is a headless WebKit scriptable with a JavaScript API. It has fast and
* native support for various web standards: DOM handling, CSS selector,
* JSON, Canvas, and SVG.
*/
phantom : true
chrome : true
},

// Obsolete options
Expand Down Expand Up @@ -23478,7 +23478,7 @@ var state = {
* @returns {boolean}
*/
impliedClosure: function() {
return this.option.node || this.option.phantom || this.option.browserify;
return this.option.node || this.option.chrome || this.option.browserify;
},

// Assumption: chronologically ES3 < ES5 < ES6 < Moz
Expand Down Expand Up @@ -24285,8 +24285,8 @@ exports.browserify = {
process : true
};

exports.phantom = {
phantom : true,
exports.chrome = {
chrome : true,
require : true,
WebPage : true,
console : true, // in examples, but undocumented
Expand Down Expand Up @@ -24845,8 +24845,8 @@ var JSHINT = (function() {
combine(predefined, vars.typed);
}

if (state.option.phantom) {
combine(predefined, vars.phantom);
if (state.option.chrome) {
combine(predefined, vars.chrome);
}

if (state.option.prototypejs) {
Expand Down Expand Up @@ -31161,4 +31161,4 @@ if (typeof exports === "object" && exports) {

JSHINT = require('jshint').JSHINT;
if (typeof exports === 'object' && exports) exports.JSHINT = JSHINT;
}());
}());
2 changes: 1 addition & 1 deletion examples/.jshintrc
Expand Up @@ -76,7 +76,7 @@
"mootools" : false, // MooTools
"node" : false, // Node.js
"nonstandard" : false, // Widely adopted globals (escape, unescape, etc)
"phantom" : false, // PhantomJS
"chrome" : false, // Chrome
"prototypejs" : false, // Prototype and Scriptaculous
"qunit" : false, // QUnit
"rhino" : false, // Rhino
Expand Down
3 changes: 1 addition & 2 deletions package.json
Expand Up @@ -58,8 +58,7 @@
"jscs": "1.11.x",
"mock-stdin": "0.3.x",
"nodeunit": "0.9.x",
"phantom": "~4.0.1",
"phantomjs-prebuilt": "~2.1.7",
"puppeteer": "1.20.0",
"regenerate": "1.2.x",
"results-interpreter": "~1.0.0",
"sinon": "1.12.x",
Expand Down
4 changes: 2 additions & 2 deletions src/jshint.js
Expand Up @@ -285,8 +285,8 @@ var JSHINT = (function() {
combine(predefined, vars.typed);
}

if (state.option.phantom) {
combine(predefined, vars.phantom);
if (state.option.chrome) {
combine(predefined, vars.chrome);
}

if (state.option.prototypejs) {
Expand Down
4 changes: 2 additions & 2 deletions src/options.js
Expand Up @@ -780,12 +780,12 @@ exports.bool = {

/**
* This option defines globals available when your core is running inside
* of the PhantomJS runtime environment. [PhantomJS](http://phantomjs.org/)
* of the Chrome runtime environment. [Chrome](http://chromium.org/)
* is a headless WebKit scriptable with a JavaScript API. It has fast and
* native support for various web standards: DOM handling, CSS selector,
* JSON, Canvas, and SVG.
*/
phantom : true
chrome : true
},

// Obsolete options
Expand Down
2 changes: 1 addition & 1 deletion src/state.js
Expand Up @@ -56,7 +56,7 @@ var state = {
* @returns {boolean}
*/
impliedClosure: function() {
return this.option.node || this.option.phantom || this.option.browserify;
return this.option.node || this.option.chrome || this.option.browserify;
},

// Assumption: chronologically ES3 < ES5 < ES6 < Moz
Expand Down
4 changes: 2 additions & 2 deletions src/vars.js
Expand Up @@ -532,8 +532,8 @@ exports.browserify = {
process : true
};

exports.phantom = {
phantom : true,
exports.chrome = {
chrome : true,
require : true,
WebPage : true,
console : true, // in examples, but undocumented
Expand Down
59 changes: 13 additions & 46 deletions tests/browser.js
@@ -1,57 +1,24 @@
"use strict";

var phantom, phantomJsPrebuilt;
try {
phantom = require("phantom");
phantomJsPrebuilt = require("phantomjs-prebuilt");
} catch (err) {
throw new Error(
"Unable to run tests in PhantomJS because the required dependencies are " +
"not available. Please note that JSHint does not support development " +
"using versions of Node.js which are no longer maintained."
);
}

const puppeteer = require('puppeteer');
var createTestServer = require("./helpers/browser/server");
var options = {
/**
* The `phantom` module provides a Node.js API for the PhantomJS binary,
* while the `phantomjs` module includes the binary itself.
*/
phantomPath: phantomJsPrebuilt.path
};
var port = process.env.NODE_PORT || 8045;
var ph;

phantom.create([], options)
.then(function(_ph) {
ph = _ph;
return ph.createPage();
})
.then(function(page) {
createTestServer(port, function(server) {
page.on("onConsoleMessage", function(str) {
console.log(str);
});

page.on("onCallback", function(err) {
ph.exit();
server.close();
if (err) {
process.exit(1);
}
const browser = puppeteer.launch({ headless: true, args: ['--no-sandbox', '--disable-setuid-sandbox'] }).then(async browser => {
const page = await browser.newPage();
createTestServer(port, function(server) {
page.on('console', msg => console.log("", msg.text()));
page.exposeFunction('callChrome', text=> {
browser.close();
process.exit();
});

page.on("onError", function(msg, trace) {
console.error(msg);
console.error(trace);
process.exit(1);
process.exit();
});
return page.goto("http://localhost:" + port, {
waitUntil: 'load'
});

return page.open("http://localhost:" + port);
});
})
.then(null, function(err) {
console.error(err);
process.exit(1);
});
});
32 changes: 0 additions & 32 deletions tests/helpers/browser/index.html
Expand Up @@ -5,38 +5,6 @@
<title>JSHint Browser Build Testing Server</title>
</head>
<body>
<script>
/**
* PhantomJS does not define a `Function.prototype.bind` implementation, so
* a polyfill is necessary.
* Source:
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind
*/
if (!Function.prototype.bind) {
Function.prototype.bind = function(oThis) {
if (typeof this !== "function") {
// closest thing possible to the ECMAScript 5
// internal IsCallable function
throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");
}

var aArgs = Array.prototype.slice.call(arguments, 1),
fToBind = this,
fNOP = function() {},
fBound = function() {
return fToBind.apply(this instanceof fNOP && oThis
? this
: oThis,
aArgs.concat(Array.prototype.slice.call(arguments)));
};

fNOP.prototype = this.prototype;
fBound.prototype = new fNOP();

return fBound;
};
}
</script>
<script src="jshint.js"></script>
<script src="tests.js"></script>
</body>
Expand Down
15 changes: 4 additions & 11 deletions tests/helpers/browser/run-all.js.tmpl
@@ -1,20 +1,13 @@
(function() {
"use strict";
var nodeunit = require("nodeunit");
var callPhantom = window.callPhantom;
var callChrome = window.callChrome;
var tests;

/**
* `window.callPhantom` is used as the control flow communication channel
* between the document and the PhantomJS context (where available). Because
* of this, it should not be available to other scripts on the page.
*/
window.callPhantom = null;

/**
* Nodeunit's "browser" reporter expects Nodeunit to be available on the
* global scope. Expose it in all cases to promote consistency between the
* PhantomJS and "true" browser execution contexts.
* Chrome and "true" browser execution contexts.
*/
window.nodeunit = nodeunit;

Expand All @@ -38,7 +31,7 @@
assertion_suffix: "\u001B[39m"
};
nodeunit.reporters.default.run(tests, colors, function(err) {
callPhantom(err ? err : null);
callChrome();
});
}

Expand All @@ -48,7 +41,7 @@
reporter.run(tests);
}

if (/PhantomJS/.test(navigator.userAgent)) {
if (/Chrome/.test(navigator.userAgent)) {
runHeadless();
} else {
runHeadful();
Expand Down
14 changes: 7 additions & 7 deletions tests/unit/envs.js
Expand Up @@ -198,7 +198,7 @@ exports.es5 = function (test) {
test.done();
};

exports.phantom = function (test) {
exports.chrome = function (test) {
// Phantom environment assumes `globalstrict`
var globalStrict = [
'"use strict";',
Expand All @@ -210,7 +210,7 @@ exports.phantom = function (test) {
.test(globalStrict, { es3: true, strict: true });

TestRun(test)
.test(globalStrict, { es3: true, phantom: true, strict: true });
.test(globalStrict, { es3: true, chrome: true, strict: true });


test.done();
Expand All @@ -230,7 +230,7 @@ exports.globals = function (test) {
TestRun(test)
.test(src, { node: true });
TestRun(test)
.test(src, { phantom: true });
.test(src, { chrome: true });

TestRun(test, "Late configuration of `browserify`")
.test([
Expand Down Expand Up @@ -276,25 +276,25 @@ exports.globals = function (test) {
"var first;"
]);

TestRun(test, "Late configuration of `phantom`")
TestRun(test, "Late configuration of `chrome`")
.test([
"/* global first */",
"void 0;",
"// jshint phantom: true",
"// jshint chrome: true",
"var first;"
]);

TestRun(test)
.test([
"// jshint phantom: true",
"// jshint chrome: true",
"/* global first */",
"var first;"
]);

TestRun(test)
.test([
"/* global first */",
"// jshint phantom: true",
"// jshint chrome: true",
"var first;"
]);

Expand Down

0 comments on commit 51963a3

Please sign in to comment.