diff --git a/Gruntfile.js b/Gruntfile.js index 81f09ab87c..7357e051aa 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -4,7 +4,6 @@ var exec = require('child_process').exec; var jsxTask = require('./grunt/tasks/jsx'); var browserifyTask = require('./grunt/tasks/browserify'); var populistTask = require('./grunt/tasks/populist'); -var phantomTask = require('./grunt/tasks/phantom'); var webdriverPhantomJSTask = require('./grunt/tasks/webdriver-phantomjs'); var webdriverJasmineTasks = require('./grunt/tasks/webdriver-jasmine'); var npmTask = require('./grunt/tasks/npm'); @@ -18,7 +17,6 @@ module.exports = function(grunt) { jsx: require('./grunt/config/jsx/jsx'), browserify: require('./grunt/config/browserify'), populist: require('./grunt/config/populist'), - phantom: require('./grunt/config/phantom'), connect: require('./grunt/config/server')(grunt), "webdriver-jasmine": require('./grunt/config/webdriver-jasmine.js'), npm: require('./grunt/config/npm'), @@ -44,8 +42,6 @@ module.exports = function(grunt) { grunt.registerMultiTask('populist', populistTask); - grunt.registerMultiTask('phantom', phantomTask); - grunt.registerMultiTask('webdriver-jasmine', webdriverJasmineTasks); grunt.registerMultiTask('npm', npmTask); @@ -79,12 +75,12 @@ module.exports = function(grunt) { grunt.registerTask('webdriver-phantomjs', webdriverPhantomJSTask); - grunt.registerTask('test:webdriver', [ + grunt.registerTask('test:webdriver:phantomjs', [ 'connect', 'webdriver-phantomjs', 'webdriver-jasmine:local' ]); - grunt.registerTask('test', ['build:test', 'build:basic', 'phantom:run']); + grunt.registerTask('test', ['build:test', 'build:basic', 'test:webdriver:phantomjs']); grunt.registerTask('npm:test', ['build', 'npm:pack']); // Optimized build task that does all of our builds. The subtasks will be run diff --git a/grunt/config/phantom.js b/grunt/config/phantom.js deleted file mode 100644 index 36cbc0f3de..0000000000 --- a/grunt/config/phantom.js +++ /dev/null @@ -1,11 +0,0 @@ -var grunt = require("grunt"); - -exports.run = { - port: 8080, - harness: "test/phantom-harness.js", - // Run `grunt test --debug` to enable in-browser testing. - debug: !!grunt.option("debug"), - tests: [ - "**/__tests__/*-test.js" - ] -}; diff --git a/grunt/tasks/phantom.js b/grunt/tasks/phantom.js deleted file mode 100644 index d5c66eb258..0000000000 --- a/grunt/tasks/phantom.js +++ /dev/null @@ -1,68 +0,0 @@ -'use strict'; - -var assert = require("assert"); -var grunt = require("grunt"); -var spawn = grunt.util.spawn; -var semver = require("semver"); -var MIN_VERSION = "1.9.0"; -var phantomjs = require("phantomjs").path; - -function checkVersion(error, result, code) { - if (error) { - throw error; - } - assert.strictEqual(code, 0); - - var version = result.stdout; - - assert.ok( - semver.valid(version), - "Invalid PhantomJS version: " + version - ); - - assert.ok( - semver.gte(version, MIN_VERSION), - "PhantomJS v" + version + " too old; need to install " + - "v" + MIN_VERSION + " or higher." - ); -} - -function run(config, done) { - var args = [ - config.harness, - "--port", config.port - ]; - - if (config.debug) { - args.push("--debug"); - } - - args.push("--tests"); - grunt.file.expand({ - nonull: true, - cwd: "src" - }, config.tests || []).forEach(function(file) { - args.push(file.replace(/\.js$/i, "")); - }); - - var child = spawn({ - cmd: phantomjs, - args: args - }, done); - - child.stdout.pipe(process.stdout); - child.stderr.pipe(process.stderr); -} - -module.exports = function() { - var config = this.data; - var done = this.async(); - - spawn({ - cmd: phantomjs, - args: ["--version"] - }, function(error, result, code) { - checkVersion(error, result, code); - run(config, done); - }); -}; diff --git a/test/index.html b/test/index.html deleted file mode 100644 index 97fbfb0479..0000000000 --- a/test/index.html +++ /dev/null @@ -1,23 +0,0 @@ - - -
- - - - - - - - diff --git a/test/phantom-harness.js b/test/phantom-harness.js deleted file mode 100644 index 66197fa52e..0000000000 --- a/test/phantom-harness.js +++ /dev/null @@ -1,141 +0,0 @@ -var slice = Array.prototype.slice; -var argv = slice.call(require("system").args); - -// Hard to believe PhantomJS has no equivalent of Node's "path" module. -var fs = require("fs"); -var splat = [fs.workingDirectory, argv[0]] - .join(fs.separator) - .split(fs.separator); - -var harness = splat.pop(); -if (harness !== "phantom-harness.js") { - console.error("wrong harness: " + harness); - phantom.exit(-1); -} - -var cwd = splat.join(fs.separator); -fs.changeWorkingDirectory(cwd); - -// Hard to believe PhantomJS has no option parsing module. -var port = 8080; -var debug = false; -var tests = []; -var rest = []; -while (argv.length > 0) { - var arg = argv.pop(); - if (arg === "--port") { - port = +rest.pop(); - } else if (arg === "--debug") { - debug = true; - } else if (arg === "--tests") { - while (rest.length > 0) - tests.push(rest.pop()); - } - rest.push(arg); -} - -// Dynamically enable the individual tests. -var indexHtml = fs.read("index.html").replace( - /^(\s*)ENABLE_TESTS_HERE/m, - function(placeholder, leadingSpace) { - return leadingSpace + tests.map(function(testID) { - return "harness.enableTest(" + JSON.stringify(testID) + ");"; - }).join("\n" + leadingSpace); - } -); - -var server = require("webserver").create(); -server.listen(port, function(req, res) { - var file = req.url.replace(/^\/+/, ""); - file = file.split('?')[0]; - file = file.replace('build/', ''); - file = file.replace('src/test/', ''); - - var content; - - switch (file) { - case "jasmine.js": - case "react.js": - case "react-test.js": - file = "../build/" + file; - break; - - case "phantomjs-shims.js": - case "worker.js": - file = "../src/test/" + file; - break; - - case "jasmine.css": - file = "../vendor/jasmine/" + file; - break; - - case "": - default: - file = "index.html"; - content = indexHtml; // Prevents calling fs.read again. - break; - } - - if (/\.css$/i.test(file)) { - res.setHeader("Content-Type", "text/css"); - } else if (/\.js/i.test(file)) { - res.setHeader("Content-Type", "text/javascript"); - } else { - res.setHeader("Content-Type", "text/html"); - } - - res.statusCode = 200; - res.write(content || fs.read(file)); - res.close(); -}); - -var url = "http://localhost:" + port; -var green = "\033[32m"; -var cyan = "\033[36m"; -var reset = "\033[0m"; - -if (debug) { - console.log(green); - console.log("PhantomJS received the " + cyan + "--debug" + green + " option."); - console.log("Load " + cyan + url + green + " in your browser to execute " + - "the test suite."); - console.log("Type " + cyan + "control-C" + green + " to terminate the " + - "PhantomJS process."); - console.log(reset); - - // Leave PhantomJS running until killed with control-C... - -} else { - var page = require("webpage").create(); - var timeoutSecs = 60; - - page.onCallback = function(data) { - switch (data.type) { - case "console": - console[data.method].apply(console, data.args); - break; - - case "exit": - // PhantomJS crashes sometimes unless we call phantom.exit in its own - // event loop tick. - setTimeout(function() { - phantom.exit(data.code); - }, 10); - break; - } - }; - - page.open(url, function(status) { - if (status !== "success") { - console.error("failed to open " + url); - phantom.exit(-1); - } - - setTimeout(function() { - console.error( - "PhantomJS tests timed out after " + - timeoutSecs + " seconds."); - phantom.exit(-1); - }, timeoutSecs * 1e3); - }); -}