Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #212 from stealjs/better-cli
Improvements to the cli
- Loading branch information
Showing
6 changed files
with
202 additions
and
53 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
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,33 @@ | ||
var Browser = require("zombie"); | ||
var connect = require("connect"); | ||
var path = require("path"); | ||
|
||
// Helpers | ||
exports.find = function(browser, property, callback, done){ | ||
var start = new Date(); | ||
var check = function(){ | ||
if(browser.window && browser.window[property]) { | ||
callback(browser.window[property]); | ||
} else if(new Date() - start < 2000){ | ||
setTimeout(check, 20); | ||
} else { | ||
done("failed to find "+property+" in "+browser.window.location.href); | ||
} | ||
}; | ||
check(); | ||
}; | ||
|
||
exports.open = function(url, callback, done){ | ||
var server = connect().use(connect.static(path.join(__dirname,".."))).listen(8081); | ||
var browser = Browser.create(); | ||
browser.visit("http://localhost:8081/"+url) | ||
.then(function(){ | ||
callback(browser, function(err){ | ||
server.close(); | ||
done(err); | ||
}) | ||
}).catch(function(e){ | ||
server.close(); | ||
done(e) | ||
}); | ||
}; |
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,135 @@ | ||
var assert = require("assert"); | ||
var path = require("path"); | ||
var rmdir = require("rimraf"); | ||
var spawn = require("child_process").spawn; | ||
var asap = require("pdenodeify"); | ||
var fs = require("fs-extra"); | ||
require("steal"); | ||
|
||
var find = require("./helpers").find; | ||
var open = require("./helpers").open; | ||
|
||
function stealTools(args){ | ||
return new Promise(function(resolve, reject){ | ||
var cli = path.resolve(__dirname + "/../bin/steal"); | ||
var child = spawn(cli, args || []); | ||
|
||
/*var print = function(d){ console.log(d+""); }; | ||
child.stdout.on("data", print); | ||
child.stderr.on("data", print);*/ | ||
|
||
child.on("close", function(code){ | ||
if(code === 1) { | ||
var error = new Error("Exited with status " + code); | ||
return reject(error); | ||
} | ||
return resolve(); | ||
}); | ||
}); | ||
} | ||
|
||
describe("steal-tools cli", function(){ | ||
describe("build", function(){ | ||
describe("basics", function(){ | ||
beforeEach(function(){ | ||
this.cwd = process.cwd(); | ||
process.chdir(__dirname); | ||
}); | ||
|
||
afterEach(function(){ | ||
process.chdir(this.cwd); | ||
}); | ||
|
||
it("works", function(done){ | ||
stealTools(["build", "--config", "stealconfig.js", "--main", | ||
"basics/basics", "--no-minify"]) | ||
.then(function(){ | ||
done(); | ||
}); | ||
}); | ||
|
||
it("uses build by default", function(done){ | ||
stealTools(["--config", "stealconfig.js", "--main", | ||
"basics/basics", "--no-minify"]) | ||
.then(function(){ | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe("without --config or --main", function(){ | ||
|
||
beforeEach(function(done){ | ||
this.cwd = process.cwd(); | ||
process.chdir(path.resolve(__dirname + "/npm")); | ||
|
||
rmdir = asap(rmdir); | ||
var copy = asap(fs.copy); | ||
|
||
rmdir(path.join(__dirname, "npm", "node_modules")) | ||
.then(function(){ | ||
return rmdir(path.join(__dirname, "npm", "dist")); | ||
}) | ||
.then(function(){ | ||
return copy(path.join(__dirname, "..", "node_modules","jquery"), | ||
path.join(__dirname, "npm", "node_modules", "jquery")); | ||
}).then(function(){ | ||
return copy(path.join(__dirname, "..", "bower_components","steal"), | ||
path.join(__dirname, "npm", "node_modules", "steal")); | ||
}).then(done, done); | ||
}); | ||
|
||
afterEach(function(){ | ||
process.chdir(this.cwd); | ||
}); | ||
|
||
it("uses package.json", function(done){ | ||
this.timeout(5000); | ||
stealTools(["--no-minify"]).then(function(){ | ||
open("test/npm/prod.html", function(browser, close){ | ||
var h1s = browser.window.document.getElementsByTagName('h1'); | ||
assert.equal(h1s.length, 1, "Wrote H!."); | ||
close(); | ||
}, done); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe("transform", function(){ | ||
describe("basics", function(){ | ||
beforeEach(function(done){ | ||
this.cwd = process.cwd(); | ||
process.chdir(__dirname); | ||
|
||
rmdir(__dirname + "/pluginify/out.js", function(error){ | ||
done(error); | ||
}); | ||
}); | ||
|
||
afterEach(function(){ | ||
process.chdir(this.cwd); | ||
}); | ||
|
||
it("works", function(done){ | ||
stealTools(["transform", "-c", "stealconfig.js", "-m", | ||
"pluginify/pluginify", "--out", "pluginify/out.js"]).then(function(){ | ||
|
||
open("test/pluginify/index.html", function(browser, close){ | ||
|
||
find(browser,"RESULT", function(result){ | ||
assert(result.module.es6module, "have dependeny"); | ||
assert(result.cjs(), "cjs"); | ||
assert.equal(result.UMD, "works", "Doesn't mess with UMD modules"); | ||
assert.equal(result.define, undefined, "Not keeping a global.define"); | ||
assert.equal(result.System, undefined, "Not keeping a global.System"); | ||
close(); | ||
}, close); | ||
|
||
}, done); | ||
|
||
}); | ||
}); | ||
}); | ||
}); | ||
}); |