mirror of https://github.com/webpack/webpack.git
more tests for external modules
This commit is contained in:
parent
b363611750
commit
9a1df0277e
|
|
@ -1,10 +1,8 @@
|
||||||
/* globals describe, it, beforeEach, afterEach */
|
/* globals describe, it, beforeEach */
|
||||||
"use strict";
|
"use strict";
|
||||||
require("should");
|
require("should");
|
||||||
const sinon = require("sinon");
|
const sinon = require("sinon");
|
||||||
const ExternalModule = require("../lib/ExternalModule");
|
const ExternalModule = require("../lib/ExternalModule");
|
||||||
const path = require("path");
|
|
||||||
const SourceMapSource = require("webpack-sources").SourceMapSource;
|
|
||||||
const OriginalSource = require("webpack-sources").OriginalSource;
|
const OriginalSource = require("webpack-sources").OriginalSource;
|
||||||
const RawSource = require("webpack-sources").RawSource;
|
const RawSource = require("webpack-sources").RawSource;
|
||||||
|
|
||||||
|
|
@ -232,4 +230,85 @@ module.exports = some/request;`;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("#getSourceString", function() {
|
||||||
|
let globalExternalStub;
|
||||||
|
let globalCommonJsStub;
|
||||||
|
let globalAmdOrUmdStub;
|
||||||
|
let defaultExternalStub;
|
||||||
|
beforeEach(function() {
|
||||||
|
globalExternalStub = externalModule.getSourceForGlobalVariableExternal = sinon.stub();
|
||||||
|
globalCommonJsStub = externalModule.getSourceForCommonJsExternal = sinon.stub();
|
||||||
|
globalAmdOrUmdStub = externalModule.getSourceForAmdOrUmdExternal = sinon.stub();
|
||||||
|
defaultExternalStub = externalModule.getSourceForDefaultCase = sinon.stub();
|
||||||
|
});
|
||||||
|
describe("with type being 'this', 'window' or 'global'", function() {
|
||||||
|
it("deletgates to #getSourceForGlobalVariableExternal", function() {
|
||||||
|
["this", "window", "global"].forEach((type, i) => {
|
||||||
|
// set up
|
||||||
|
externalModule.type = type;
|
||||||
|
|
||||||
|
// invoke
|
||||||
|
externalModule.getSourceString();
|
||||||
|
|
||||||
|
// check
|
||||||
|
globalExternalStub.callCount.should.eql(i + 1);
|
||||||
|
globalCommonJsStub.callCount.should.eql(0);
|
||||||
|
globalAmdOrUmdStub.callCount.should.eql(0);
|
||||||
|
defaultExternalStub.callCount.should.eql(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe("with type being 'commonjs' or 'commonjs2'", function() {
|
||||||
|
it("deletgates to #getSourceForCommonJsExternal", function() {
|
||||||
|
["commonjs", "commonjs2"].forEach((type, i) => {
|
||||||
|
// set up
|
||||||
|
externalModule.type = type;
|
||||||
|
|
||||||
|
// invoke
|
||||||
|
externalModule.getSourceString();
|
||||||
|
|
||||||
|
// check
|
||||||
|
globalExternalStub.callCount.should.eql(0);
|
||||||
|
globalCommonJsStub.callCount.should.eql(i + 1);
|
||||||
|
globalAmdOrUmdStub.callCount.should.eql(0);
|
||||||
|
defaultExternalStub.callCount.should.eql(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe("with type being 'amd', 'umd' or 'umd2'", function() {
|
||||||
|
it("deletgates to #getSourceForAmdOrUmdExternal", function() {
|
||||||
|
["amd", "umd", "umd2"].forEach((type, i) => {
|
||||||
|
// set up
|
||||||
|
externalModule.type = type;
|
||||||
|
|
||||||
|
// invoke
|
||||||
|
externalModule.getSourceString();
|
||||||
|
|
||||||
|
// check
|
||||||
|
globalExternalStub.callCount.should.eql(0);
|
||||||
|
globalCommonJsStub.callCount.should.eql(0);
|
||||||
|
globalAmdOrUmdStub.callCount.should.eql(i + 1);
|
||||||
|
defaultExternalStub.callCount.should.eql(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe("with type being non of the above", function() {
|
||||||
|
it("deletgates to #getSourceForGlobalVariableExternal", function() {
|
||||||
|
["foo", "bar", undefined].forEach((type, i) => {
|
||||||
|
// set up
|
||||||
|
externalModule.type = type;
|
||||||
|
|
||||||
|
// invoke
|
||||||
|
externalModule.getSourceString();
|
||||||
|
|
||||||
|
// check
|
||||||
|
globalExternalStub.callCount.should.eql(0);
|
||||||
|
globalCommonJsStub.callCount.should.eql(0);
|
||||||
|
globalAmdOrUmdStub.callCount.should.eql(0);
|
||||||
|
defaultExternalStub.callCount.should.eql(i + 1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue