Skip to content

Commit 56924c6

Browse files
authored
feat(test): increase coverage for target: 'webworker' (webpack#3204)
* feat(test): increase coverage for target: 'webworker' * fixed bad test cases, and added generic node shimming for web workers
1 parent 59c2c56 commit 56924c6

5 files changed

Lines changed: 116 additions & 1 deletion

File tree

test/ConfigTestCases.test.js

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

test/configCases/target/webworker/node_modules/process/in.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/configCases/target/webworker/node_modules/process/index.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module.exports = {
2+
target: "webworker",
3+
performance: {
4+
hints: false
5+
},
6+
module: {
7+
loaders: [
8+
{ test: /\.json$/, loader: "json-loader" }
9+
]
10+
},
11+
node: {
12+
__dirname: false,
13+
__filename: false
14+
}
15+
};

0 commit comments

Comments
 (0)