From 7f091c2538a950a7a3aa646311cb0a3d24f6df1c Mon Sep 17 00:00:00 2001 From: alexlamsl Date: Thu, 14 Apr 2016 17:37:01 +0800 Subject: [PATCH] use phantomjs directly --- Gruntfile.js | 33 +++++++++++++-------------------- package.json | 2 +- tests/inject.js | 5 ----- tests/phantom.js | 18 ++++++++++++++++++ 4 files changed, 32 insertions(+), 26 deletions(-) delete mode 100644 tests/inject.js create mode 100644 tests/phantom.js diff --git a/Gruntfile.js b/Gruntfile.js index 9c8c0a9..8637cec 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -90,25 +90,12 @@ module.exports = function(grunt) { return details.failed; } - var phantomjs = require('grunt-lib-phantomjs').init(grunt); - var webErrors; - phantomjs.on('fail.load', function() { - phantomjs.halt(); - webErrors++; - grunt.log.error('page failed to load'); - }).on('fail.timeout', function() { - phantomjs.halt(); - webErrors++; - grunt.log.error('timed out'); - }).on('qunit.done', function(details) { - phantomjs.halt(); - webErrors += report('web', details); - }); + var phantomjs = require('phantomjs-prebuilt').path; var fork = require('child_process').fork; grunt.registerMultiTask('qunit', function() { var done = this.async(); var remaining = 2; - var nodeErrors; + var nodeErrors, webErrors; function completed() { if (!--remaining) { @@ -116,12 +103,18 @@ module.exports = function(grunt) { } } - webErrors = 0; - phantomjs.spawn(this.data[1], { - done: completed, - options: { - inject: 'tests/inject.js' + grunt.util.spawn({ + cmd: phantomjs, + args: ['tests/phantom.js', this.data[1]] + }, function(error, result) { + if (error) { + grunt.log.error('web page failed to load'); + webErrors = -1; } + else { + webErrors = report('web', JSON.parse(result.stdout)); + } + completed(); }); fork('./test', [this.data[0]]).on('message', function(details) { nodeErrors += report('node', details); diff --git a/package.json b/package.json index 4d2812d..c754ad2 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,7 @@ "grunt-browserify": "5.0.x", "grunt-contrib-uglify": "1.0.x", "grunt-eslint": "18.0.x", - "grunt-lib-phantomjs": "1.0.x", + "phantomjs-prebuilt": "2.1.x", "qunitjs": "1.23.0" }, "optionalDependencies": { diff --git a/tests/inject.js b/tests/inject.js deleted file mode 100644 index 54fd80b..0000000 --- a/tests/inject.js +++ /dev/null @@ -1,5 +0,0 @@ -'use strict'; - -QUnit.done(function(details) { - alert(JSON.stringify(['qunit.done', details])); -}); diff --git a/tests/phantom.js b/tests/phantom.js new file mode 100644 index 0000000..b829e3c --- /dev/null +++ b/tests/phantom.js @@ -0,0 +1,18 @@ + /* eslint-env phantomjs */ +'use strict'; + +var page = require('webpage').create(); +page.onAlert = function(details) { + console.log(details); + phantom.exit(); +}; +page.open(require('system').args[1], function(status) { + if (status !== 'success') { + phantom.exit(1); + } + page.evaluate(function() { + QUnit.done(function(details) { + alert(JSON.stringify(details)); + }); + }); +}); -- 2.34.1