forked from facebook/react
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide
grunt npm:test
for verifying NPM package functionality.
This basically calls `npm pack`, installs the resulting package in a temporary directory, then requires it and attempts to use the .transform method. Closes facebook#12.
- Loading branch information
Showing
4 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
exports.pack = {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
'use strict'; | ||
|
||
var assert = require("assert"); | ||
var path = require("path"); | ||
var fs = require("fs"); | ||
var tmp = require("tmp"); | ||
var grunt = require("grunt"); | ||
var spawn = grunt.util.spawn; | ||
|
||
module.exports = function() { | ||
var config = this.data; | ||
var done = this.async(); | ||
|
||
function run(cmd, args, opts, callback) { | ||
assert.strictEqual(typeof cmd, "string"); | ||
assert.ok(args instanceof Array); | ||
|
||
if (typeof opts === "function" && !callback) { | ||
callback = opts; | ||
opts = {}; | ||
} | ||
|
||
assert.strictEqual(typeof opts, "object"); | ||
assert.strictEqual(typeof callback, "function"); | ||
|
||
grunt.log.writeln("> " + cmd + " " + args.join(" ")); | ||
|
||
var proc = spawn({ | ||
cmd: cmd, | ||
args: args, | ||
opts: opts | ||
}, function(error, result, code) { | ||
if (error) { | ||
grunt.log.error(error); | ||
done(false); | ||
} else { | ||
callback(result, code); | ||
} | ||
}); | ||
|
||
// Uncomment these to see the output of the commands. | ||
// proc.stdout.pipe(process.stdout); | ||
// proc.stderr.pipe(process.stderr); | ||
} | ||
|
||
var pkg = grunt.config.data.pkg; | ||
var tgz = pkg.name + "-" + pkg.version + ".tgz"; | ||
|
||
grunt.log.writeln("Packing " + tgz + " (this could take a while)..."); | ||
|
||
run("npm", ["pack", "--verbose", "."], function() { | ||
tmp.dir(function(err, dir) { | ||
if (err) { | ||
grunt.log.error(err); | ||
done(false); | ||
return; | ||
} | ||
|
||
run("cp", [tgz, dir], function() { | ||
run("npm", [ | ||
"install", | ||
"--production", | ||
tgz | ||
], { cwd: dir }, function() { | ||
var nodePath = path.join(dir, "node_modules"); | ||
var pkgDir = path.join(nodePath, pkg.name); | ||
var doneCount = 2; | ||
|
||
// Make sure that bin/jsx is runnable by echoing main.js. | ||
run("bin/jsx", ["main.js"], { | ||
cwd: pkgDir | ||
}, function(result) { | ||
assert.ok(result.stdout.indexOf("transform") >= 0, result.stdout); | ||
|
||
if (--doneCount === 0) { | ||
done(); | ||
} | ||
}); | ||
|
||
// Make sure the .transform package method works. | ||
run("node", [ | ||
"--print", | ||
'require("react-tools").transform(' + | ||
JSON.stringify( | ||
"/** @jsx React.DOM */ <div>oyez</div>;" | ||
) + ')' | ||
], { | ||
env: { NODE_PATH: nodePath } | ||
}, function(result, code) { | ||
assert.ok(result.stdout.indexOf( | ||
'React.DOM.div(null, "oyez");' | ||
) >= 0, result.stdout); | ||
|
||
if (--doneCount === 0) { | ||
done(); | ||
} | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters