Add tests for global shims and module shims in web environments

This commit is contained in:
Johannes Ewald 2015-01-06 18:21:33 +01:00
parent 5a2f35e51a
commit 4127d2ef1e
3 changed files with 104 additions and 1 deletions

View File

@ -53,7 +53,12 @@ describe("ConfigTestCases", function() {
function _require(module) {
if(module.substr(0, 2) === "./") {
var p = path.join(outputDirectory, module);
var fn = vm.runInThisContext("(function(require, module, exports, __dirname, __filename, it) {" + fs.readFileSync(p, "utf-8") + "\n})", p);
var fn;
if (options.target === "web") {
fn = vm.runInNewContext("(function(require, module, exports, __dirname, __filename, it) {" + fs.readFileSync(p, "utf-8") + "\n})", p);
} else {
fn = vm.runInThisContext("(function(require, module, exports, __dirname, __filename, it) {" + fs.readFileSync(p, "utf-8") + "\n})", p);
}
var module = { exports: {} };
fn.call(module.exports, _require, module, module.exports, outputDirectory, p, _it);
return module.exports;

View File

@ -0,0 +1,95 @@
require("should");
// shimming global window object so the http-module is happy.
// window is assigned without var on purpose.
window = {
XMLHttpRequest: function() {}
};
it("should provide a global Buffer constructor", function() {
Buffer.should.be.a.Function;
});
// Webpack is not providing a console shim by default
// @see lib/WebpackOptionsDefaulter.js
// Uncomment this when defaults are changed
//it("should provide a global console shim", function () {
// console.should.be.an.Object;
// console.time.should.be.a.Function;
//});
it("should provide a global process shim", function () {
process.should.be.an.Object;
});
it("should provide a global setImmediate shim", function () {
setImmediate.should.be.a.Function;
});
it("should provide a global clearImmediate shim", function () {
clearImmediate.should.be.a.Function;
});
it("should provide an assert shim", function () {
require("assert").should.be.a.Function;
});
it("should provide a buffer shim", function () {
require("buffer").should.be.an.Object;
});
it("should provide a crypto shim", function () {
require("crypto").should.be.an.Object;
});
it("should provide a domain shim", function () {
require("domain").should.be.an.Object;
});
it("should provide an events shim", function () {
require("events").should.be.a.Function;
});
it("should provide an http shim", function () {
require("http").should.be.an.Object;
});
it("should provide an https shim", function () {
require("https").should.be.an.Object;
});
it("should provide an os shim", function () {
require("os").should.be.an.Object;
});
it("should provide a path shim", function () {
require("path").should.be.an.Object;
});
it("should provide a punycode shim", function () {
require("punycode").should.be.an.Object;
});
it("should provide a stream shim", function () {
require("stream").should.be.a.Function;
});
it("should provide a tty shim", function () {
require("tty").should.be.an.Object;
});
it("should provide a url shim", function () {
require("url").should.be.an.Object;
});
it("should provide a util shim", function () {
require("util").should.be.an.Object;
});
it("should provide a vm shim", function () {
require("vm").should.be.an.Object;
});
it("should provide a zlib shim", function () {
require("zlib").should.be.an.Object;
});

View File

@ -0,0 +1,3 @@
module.exports = {
target: "web"
};