Skip to content

Commit c123016

Browse files
committed
refactor library tests
1 parent d3a0fc9 commit c123016

13 files changed

Lines changed: 123 additions & 44 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export * from "./a";
22
export default "default-value";
33
export var b = "b";
4+
export { default as external } from "external";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default "non-external";
Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,53 @@
1-
module.exports = {
2-
output: {
3-
libraryTarget: "commonjs-module"
1+
module.exports = [
2+
{
3+
output: {
4+
filename: "commonjs.js",
5+
libraryTarget: "commonjs-module"
6+
},
7+
resolve: {
8+
alias: {
9+
external: "./non-external"
10+
}
11+
}
12+
},
13+
{
14+
output: {
15+
filename: "umd.js",
16+
libraryTarget: "umd"
17+
},
18+
resolve: {
19+
alias: {
20+
external: "./non-external"
21+
}
22+
}
23+
},
24+
{
25+
output: {
26+
filename: "this.js",
27+
libraryTarget: "this"
28+
},
29+
resolve: {
30+
alias: {
31+
external: "./non-external"
32+
}
33+
}
34+
},
35+
{
36+
output: {
37+
filename: "global.js",
38+
library: "globalName"
39+
},
40+
resolve: {
41+
alias: {
42+
external: "./non-external"
43+
}
44+
}
45+
},
46+
{
47+
output: {
48+
filename: "commonjs2-external.js",
49+
libraryTarget: "commonjs2"
50+
},
51+
externals: ["external"]
452
}
5-
};
53+
];
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
var data = require("library");
2+
3+
it("should be able get items from library (" + NAME + ")", function() {
4+
data.should.have.property("default").be.eql("default-value");
5+
data.should.have.property("a").be.eql("a");
6+
data.should.have.property("b").be.eql("b");
7+
});
Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
import d from "library";
2-
import { a, b } from "library";
2+
import { a, b, external } from "library";
33

4-
it("should be able to import hamorny exports from library", function() {
4+
it("should be able to import hamorny exports from library (" + NAME + ")", function() {
55
d.should.be.eql("default-value");
66
a.should.be.eql("a");
77
b.should.be.eql("b");
8-
});
8+
if(typeof TEST_EXTERNAL !== "undefined" && TEST_EXTERNAL) {
9+
external.should.be.eql(["external"]);
10+
external.should.be.equal(require("external"));
11+
} else {
12+
external.should.be.eql("non-external");
13+
}
14+
});

test/configCases/library/3-use-library-with-external/node_modules/external.js renamed to test/configCases/library/1-use-library/node_modules/external.js

File renamed without changes.
Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,55 @@
1+
var webpack = require("../../../../");
12
var path = require("path");
2-
module.exports = {
3-
resolve: {
4-
alias: {
5-
library: path.resolve(__dirname, "../../../js/config/library/0-create-library/bundle0.js")
6-
}
3+
module.exports = [
4+
{
5+
resolve: {
6+
alias: {
7+
library: path.resolve(__dirname, "../../../js/config/library/0-create-library/commonjs.js")
8+
}
9+
},
10+
plugins: [
11+
new webpack.DefinePlugin({
12+
NAME: JSON.stringify("commonjs")
13+
})
14+
]
15+
},
16+
{
17+
resolve: {
18+
alias: {
19+
library: path.resolve(__dirname, "../../../js/config/library/0-create-library/umd.js")
20+
}
21+
},
22+
plugins: [
23+
new webpack.DefinePlugin({
24+
NAME: JSON.stringify("umd")
25+
})
26+
]
27+
},
28+
{
29+
entry: "./global-test.js",
30+
resolve: {
31+
alias: {
32+
library: path.resolve(__dirname, "../../../js/config/library/0-create-library/this.js")
33+
}
34+
},
35+
plugins: [
36+
new webpack.DefinePlugin({
37+
NAME: JSON.stringify("this")
38+
})
39+
]
40+
},
41+
{
42+
resolve: {
43+
alias: {
44+
library: path.resolve(__dirname, "../../../js/config/library/0-create-library/commonjs2-external.js"),
45+
external: path.resolve(__dirname, "node_modules/external.js")
46+
}
47+
},
48+
plugins: [
49+
new webpack.DefinePlugin({
50+
NAME: JSON.stringify("commonjs2 with external"),
51+
TEST_EXTERNAL: true
52+
})
53+
]
754
}
8-
};
55+
];

‎test/configCases/library/2-create-library-with-external/a.js‎

Lines changed: 0 additions & 1 deletion
This file was deleted.

‎test/configCases/library/2-create-library-with-external/index.js‎

Lines changed: 0 additions & 4 deletions
This file was deleted.

‎test/configCases/library/2-create-library-with-external/test.config.js‎

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)