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

View File

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