From c6c4657f83264525ee4f510c2417ae58a7e72a4e Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Mon, 15 Jul 2013 11:34:47 -0400 Subject: [PATCH] Use populist v0.1.2 to bundle test modules instead of browserify. This will allow full support for mocking, dumpCache, and correct line numbers in error messages. --- Gruntfile.js | 6 +++++- grunt/config/populist.js | 13 +++++++++++++ grunt/tasks/populist.js | 28 ++++++++++++++++++++++++++++ package.json | 1 + src/test/all.js | 3 +++ 5 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 grunt/config/populist.js create mode 100644 grunt/tasks/populist.js diff --git a/Gruntfile.js b/Gruntfile.js index dd04aa2d13..fad8b47971 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -4,6 +4,7 @@ var exec = require('child_process').exec; var jsxTask = require('./grunt/tasks/jsx'); var browserifyTask = require('./grunt/tasks/browserify'); var wrapupTask = require('./grunt/tasks/wrapup'); +var populistTask = require('./grunt/tasks/populist'); var phantomTask = require('./grunt/tasks/phantom'); var npmTask = require('./grunt/tasks/npm'); var releaseTasks = require('./grunt/tasks/release'); @@ -16,6 +17,7 @@ module.exports = function(grunt) { jsx: require('./grunt/config/jsx/jsx'), browserify: require('./grunt/config/browserify'), wrapup: require('./grunt/config/wrapup'), + populist: require('./grunt/config/populist'), phantom: require('./grunt/config/phantom'), npm: require('./grunt/config/npm'), clean: ['./build', './*.gem', './docs/_site', './examples/shared/*.js'], @@ -44,6 +46,8 @@ module.exports = function(grunt) { // defines global variables instead of using require. grunt.registerMultiTask('wrapup', wrapupTask); + grunt.registerMultiTask('populist', populistTask); + grunt.registerMultiTask('phantom', phantomTask); grunt.registerMultiTask('npm', npmTask); @@ -56,7 +60,7 @@ module.exports = function(grunt) { 'jsx:jasmine', 'jsx:test', 'browserify:jasmine', - 'browserify:test' + 'populist:test' ]); grunt.registerTask('test', ['build:test', 'phantom:run']); diff --git a/grunt/config/populist.js b/grunt/config/populist.js new file mode 100644 index 0000000000..2f353ac3d1 --- /dev/null +++ b/grunt/config/populist.js @@ -0,0 +1,13 @@ +'use strict'; + +var test = { + args: ["test/all:"], + requires: [ + "**/__tests__/*-test.js" + ], + outfile: './build/react-test.js' +}; + +module.exports = { + test: test +}; diff --git a/grunt/tasks/populist.js b/grunt/tasks/populist.js new file mode 100644 index 0000000000..f89f45ccef --- /dev/null +++ b/grunt/tasks/populist.js @@ -0,0 +1,28 @@ +'use strict'; + +var grunt = require('grunt'); + +module.exports = function() { + var config = this.data; + var done = this.async(); + + // create the bundle we'll work with + var args = config.args; + + // Make sure the things that need to be exposed are. + var requires = config.requires || {}; + grunt.file.expand({ + nonull: true, // Keep IDs that don't expand to anything. + cwd: "src" + }, requires).forEach(function(name) { + args.push(name.replace(/\.js$/i, "")); + }); + + require("populist").buildP({ + rootDirectory: "build/modules", + args: args + }).then(function(output) { + grunt.file.write(config.outfile, output); + done(); + }); +}; diff --git a/package.json b/package.json index 802e3e8268..d35a9af1b8 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,7 @@ "devDependencies": { "browserify": "~2.24.1", "wrapup": "~0.12.0", + "populist": "~0.1.2", "grunt-cli": "~0.1.9", "grunt": "~0.4.1", "grunt-contrib-copy": "~0.4.1", diff --git a/src/test/all.js b/src/test/all.js index b370c31b62..3b3a3639a9 100644 --- a/src/test/all.js +++ b/src/test/all.js @@ -6,6 +6,9 @@ var Ap = Array.prototype; var slice = Ap.slice; var Fp = Function.prototype; +var global = Function("return this")(); +global.require = require; + if (!Fp.bind) { // PhantomJS doesn't support Function.prototype.bind natively, so // polyfill it whenever this module is required.