Fix phantom tests after version bump

It turned out that PhantomShim used puppeteer's version to report
in tests. This caused one of phantomJS tests to fail when the puppeteer
version got bumped.

This patch grants PhantomShim its own version, independent from
puppeteer's. This would make it easier to roll puppeteer.
This commit is contained in:
Andrey Lushnikov 2017-07-28 01:51:05 -07:00
parent 245391cb54
commit 02d4c8819d
2 changed files with 33 additions and 31 deletions

View File

@ -19,6 +19,10 @@ let path = require('path');
let vm = require('vm'); let vm = require('vm');
let url = require('url'); let url = require('url');
const VERSION = [0, 0, 1];
module.exports.version = VERSION;
/** /**
* @param {!Object} context * @param {!Object} context
* @param {string} scriptPath * @param {string} scriptPath
@ -30,18 +34,18 @@ module.exports.create = function(context, scriptPath) {
}, },
/** /**
* @param {string} relative * @param {string} relative
* @param {string} base * @param {string} base
* @return {string} * @return {string}
*/ */
resolveRelativeUrl: function(relative, base) { resolveRelativeUrl: function(relative, base) {
return url.resolve(base, relative); return url.resolve(base, relative);
}, },
/** /**
* @param {string} url * @param {string} url
* @return {string} * @return {string}
*/ */
fullyDecodeUrl: function(url) { fullyDecodeUrl: function(url) {
return decodeURI(url); return decodeURI(url);
}, },
@ -51,56 +55,55 @@ module.exports.create = function(context, scriptPath) {
onError: null, onError: null,
/** /**
* @return {string} * @return {string}
*/ */
get outputEncoding() { get outputEncoding() {
return 'UTF-8'; return 'UTF-8';
}, },
/** /**
* @param {string} value * @param {string} value
*/ */
set outputEncoding(value) { set outputEncoding(value) {
throw new Error('Phantom.outputEncoding setter is not implemented'); throw new Error('Phantom.outputEncoding setter is not implemented');
}, },
/** /**
* @return {boolean} * @return {boolean}
*/ */
get cookiesEnabled() { get cookiesEnabled() {
return true; return true;
}, },
/** /**
* @param {boolean} value * @param {boolean} value
*/ */
set cookiesEnabled(value) { set cookiesEnabled(value) {
throw new Error('Phantom.cookiesEnabled setter is not implemented'); throw new Error('Phantom.cookiesEnabled setter is not implemented');
}, },
/** /**
* @return {!{major: number, minor: number, patch: number}} * @return {!{major: number, minor: number, patch: number}}
*/ */
get version() { get version() {
let versionParts = require('../package.json').version.split('.');
return { return {
major: parseInt(versionParts[0], 10), major: VERSION[0],
minor: parseInt(versionParts[1], 10), minor: VERSION[1],
patch: parseInt(versionParts[2], 10), patch: VERSION[2],
}; };
}, },
/** /**
* @param {number=} code * @param {number=} code
*/ */
exit: function(code) { exit: function(code) {
process.exit(code); process.exit(code);
}, },
/** /**
* @param {string} filePath * @param {string} filePath
* @return {boolean} * @return {boolean}
*/ */
injectJs: function(filePath) { injectJs: function(filePath) {
filePath = path.resolve(phantom.libraryPath, filePath); filePath = path.resolve(phantom.libraryPath, filePath);
if (!fs.existsSync(filePath)) if (!fs.existsSync(filePath))
@ -116,9 +119,9 @@ module.exports.create = function(context, scriptPath) {
}, },
/** /**
* @param {string} moduleSource * @param {string} moduleSource
* @param {string} filename * @param {string} filename
*/ */
loadModule: function(moduleSource, filename) { loadModule: function(moduleSource, filename) {
let code = [ let code = [
'(function(require, exports, module) {\n', '(function(require, exports, module) {\n',

View File

@ -25,7 +25,6 @@ let WebPage = require('./WebPage');
let WebServer = require('./WebServer'); let WebServer = require('./WebServer');
let child_process = require('child_process'); let child_process = require('child_process');
let Browser = require('..').Browser; let Browser = require('..').Browser;
let version = require('../package.json').version;
let argv = require('minimist')(process.argv.slice(2), { let argv = require('minimist')(process.argv.slice(2), {
alias: { v: 'version' }, alias: { v: 'version' },
boolean: ['headless'], boolean: ['headless'],
@ -33,7 +32,7 @@ let argv = require('minimist')(process.argv.slice(2), {
}); });
if (argv.version) { if (argv.version) {
console.log('Puppeteer v' + version); console.log('PhantomShim v' + Phantom.version.join('.'));
return; return;
} }