Skip to content

Commit 4127d2e

Browse files
committed
Add tests for global shims and module shims in web environments
1 parent 5a2f35e commit 4127d2e

3 files changed

Lines changed: 104 additions & 1 deletion

File tree

test/ConfigTestCases.test.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,12 @@ describe("ConfigTestCases", function() {
5353
function _require(module) {
5454
if(module.substr(0, 2) === "./") {
5555
var p = path.join(outputDirectory, module);
56-
var fn = vm.runInThisContext("(function(require, module, exports, __dirname, __filename, it) {" + fs.readFileSync(p, "utf-8") + "\n})", p);
56+
var fn;
57+
if (options.target === "web") {
58+
fn = vm.runInNewContext("(function(require, module, exports, __dirname, __filename, it) {" + fs.readFileSync(p, "utf-8") + "\n})", p);
59+
} else {
60+
fn = vm.runInThisContext("(function(require, module, exports, __dirname, __filename, it) {" + fs.readFileSync(p, "utf-8") + "\n})", p);
61+
}
5762
var module = { exports: {} };
5863
fn.call(module.exports, _require, module, module.exports, outputDirectory, p, _it);
5964
return module.exports;
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
require("should");
2+
3+
// shimming global window object so the http-module is happy.
4+
// window is assigned without var on purpose.
5+
window = {
6+
XMLHttpRequest: function() {}
7+
};
8+
9+
it("should provide a global Buffer constructor", function() {
10+
Buffer.should.be.a.Function;
11+
});
12+
13+
// Webpack is not providing a console shim by default
14+
// @see lib/WebpackOptionsDefaulter.js
15+
// Uncomment this when defaults are changed
16+
//it("should provide a global console shim", function () {
17+
// console.should.be.an.Object;
18+
// console.time.should.be.a.Function;
19+
//});
20+
21+
it("should provide a global process shim", function () {
22+
process.should.be.an.Object;
23+
});
24+
25+
it("should provide a global setImmediate shim", function () {
26+
setImmediate.should.be.a.Function;
27+
});
28+
29+
it("should provide a global clearImmediate shim", function () {
30+
clearImmediate.should.be.a.Function;
31+
});
32+
33+
it("should provide an assert shim", function () {
34+
require("assert").should.be.a.Function;
35+
});
36+
37+
it("should provide a buffer shim", function () {
38+
require("buffer").should.be.an.Object;
39+
});
40+
41+
it("should provide a crypto shim", function () {
42+
require("crypto").should.be.an.Object;
43+
});
44+
45+
it("should provide a domain shim", function () {
46+
require("domain").should.be.an.Object;
47+
});
48+
49+
it("should provide an events shim", function () {
50+
require("events").should.be.a.Function;
51+
});
52+
53+
it("should provide an http shim", function () {
54+
require("http").should.be.an.Object;
55+
});
56+
57+
it("should provide an https shim", function () {
58+
require("https").should.be.an.Object;
59+
});
60+
61+
it("should provide an os shim", function () {
62+
require("os").should.be.an.Object;
63+
});
64+
65+
it("should provide a path shim", function () {
66+
require("path").should.be.an.Object;
67+
});
68+
69+
it("should provide a punycode shim", function () {
70+
require("punycode").should.be.an.Object;
71+
});
72+
73+
it("should provide a stream shim", function () {
74+
require("stream").should.be.a.Function;
75+
});
76+
77+
it("should provide a tty shim", function () {
78+
require("tty").should.be.an.Object;
79+
});
80+
81+
it("should provide a url shim", function () {
82+
require("url").should.be.an.Object;
83+
});
84+
85+
it("should provide a util shim", function () {
86+
require("util").should.be.an.Object;
87+
});
88+
89+
it("should provide a vm shim", function () {
90+
require("vm").should.be.an.Object;
91+
});
92+
93+
it("should provide a zlib shim", function () {
94+
require("zlib").should.be.an.Object;
95+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
target: "web"
3+
};

0 commit comments

Comments
 (0)