refactor library tests

This commit is contained in:
Tobias Koppers 2017-06-02 14:22:42 +02:00
parent d3a0fc980e
commit c123016b64
13 changed files with 123 additions and 44 deletions

View File

@ -1,3 +1,4 @@
export * from "./a";
export default "default-value";
export var b = "b";
export { default as external } from "external";

View File

@ -0,0 +1 @@
export default "non-external";

View File

@ -1,5 +1,53 @@
module.exports = {
output: {
libraryTarget: "commonjs-module"
module.exports = [
{
output: {
filename: "commonjs.js",
libraryTarget: "commonjs-module"
},
resolve: {
alias: {
external: "./non-external"
}
}
},
{
output: {
filename: "umd.js",
libraryTarget: "umd"
},
resolve: {
alias: {
external: "./non-external"
}
}
},
{
output: {
filename: "this.js",
libraryTarget: "this"
},
resolve: {
alias: {
external: "./non-external"
}
}
},
{
output: {
filename: "global.js",
library: "globalName"
},
resolve: {
alias: {
external: "./non-external"
}
}
},
{
output: {
filename: "commonjs2-external.js",
libraryTarget: "commonjs2"
},
externals: ["external"]
}
};
];

View File

@ -0,0 +1,7 @@
var data = require("library");
it("should be able get items from library (" + NAME + ")", function() {
data.should.have.property("default").be.eql("default-value");
data.should.have.property("a").be.eql("a");
data.should.have.property("b").be.eql("b");
});

View File

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

View File

@ -1,8 +1,55 @@
var webpack = require("../../../../");
var path = require("path");
module.exports = {
resolve: {
alias: {
library: path.resolve(__dirname, "../../../js/config/library/0-create-library/bundle0.js")
}
module.exports = [
{
resolve: {
alias: {
library: path.resolve(__dirname, "../../../js/config/library/0-create-library/commonjs.js")
}
},
plugins: [
new webpack.DefinePlugin({
NAME: JSON.stringify("commonjs")
})
]
},
{
resolve: {
alias: {
library: path.resolve(__dirname, "../../../js/config/library/0-create-library/umd.js")
}
},
plugins: [
new webpack.DefinePlugin({
NAME: JSON.stringify("umd")
})
]
},
{
entry: "./global-test.js",
resolve: {
alias: {
library: path.resolve(__dirname, "../../../js/config/library/0-create-library/this.js")
}
},
plugins: [
new webpack.DefinePlugin({
NAME: JSON.stringify("this")
})
]
},
{
resolve: {
alias: {
library: path.resolve(__dirname, "../../../js/config/library/0-create-library/commonjs2-external.js"),
external: path.resolve(__dirname, "node_modules/external.js")
}
},
plugins: [
new webpack.DefinePlugin({
NAME: JSON.stringify("commonjs2 with external"),
TEST_EXTERNAL: true
})
]
}
};
];

View File

@ -1 +0,0 @@
export var a = "a";

View File

@ -1,4 +0,0 @@
export * from "./a";
export default "default-value";
export var b = "b";
export { default as external } from "external";

View File

@ -1 +0,0 @@
exports.noTests = true;

View File

@ -1,6 +0,0 @@
module.exports = {
output: {
libraryTarget: "commonjs2"
},
externals: ["external"]
};

View File

@ -1,10 +0,0 @@
import d from "library";
import { a, b, external } from "library";
it("should be able to import hamorny exports from library", function() {
d.should.be.eql("default-value");
a.should.be.eql("a");
b.should.be.eql("b");
external.should.be.eql(["external"]);
external.should.be.equal(require("external"));
});

View File

@ -1,9 +0,0 @@
var path = require("path");
module.exports = {
resolve: {
alias: {
library: path.resolve(__dirname, "../../../js/config/library/2-create-library-with-external/bundle0.js"),
external: path.resolve(__dirname, "node_modules/external.js")
}
}
};