|
1 | | -/* globals describe, it, beforeEach, afterEach */ |
| 1 | +/* globals describe, it, beforeEach */ |
2 | 2 | "use strict"; |
3 | 3 | require("should"); |
4 | 4 | const sinon = require("sinon"); |
5 | 5 | const ExternalModule = require("../lib/ExternalModule"); |
6 | | -const path = require("path"); |
7 | | -const SourceMapSource = require("webpack-sources").SourceMapSource; |
8 | 6 | const OriginalSource = require("webpack-sources").OriginalSource; |
9 | 7 | const RawSource = require("webpack-sources").RawSource; |
10 | 8 |
|
@@ -232,4 +230,85 @@ module.exports = some/request;`; |
232 | 230 | }); |
233 | 231 | }); |
234 | 232 | }); |
| 233 | + |
| 234 | + describe("#getSourceString", function() { |
| 235 | + let globalExternalStub; |
| 236 | + let globalCommonJsStub; |
| 237 | + let globalAmdOrUmdStub; |
| 238 | + let defaultExternalStub; |
| 239 | + beforeEach(function() { |
| 240 | + globalExternalStub = externalModule.getSourceForGlobalVariableExternal = sinon.stub(); |
| 241 | + globalCommonJsStub = externalModule.getSourceForCommonJsExternal = sinon.stub(); |
| 242 | + globalAmdOrUmdStub = externalModule.getSourceForAmdOrUmdExternal = sinon.stub(); |
| 243 | + defaultExternalStub = externalModule.getSourceForDefaultCase = sinon.stub(); |
| 244 | + }); |
| 245 | + describe("with type being 'this', 'window' or 'global'", function() { |
| 246 | + it("deletgates to #getSourceForGlobalVariableExternal", function() { |
| 247 | + ["this", "window", "global"].forEach((type, i) => { |
| 248 | + // set up |
| 249 | + externalModule.type = type; |
| 250 | + |
| 251 | + // invoke |
| 252 | + externalModule.getSourceString(); |
| 253 | + |
| 254 | + // check |
| 255 | + globalExternalStub.callCount.should.eql(i + 1); |
| 256 | + globalCommonJsStub.callCount.should.eql(0); |
| 257 | + globalAmdOrUmdStub.callCount.should.eql(0); |
| 258 | + defaultExternalStub.callCount.should.eql(0); |
| 259 | + }); |
| 260 | + }); |
| 261 | + }); |
| 262 | + describe("with type being 'commonjs' or 'commonjs2'", function() { |
| 263 | + it("deletgates to #getSourceForCommonJsExternal", function() { |
| 264 | + ["commonjs", "commonjs2"].forEach((type, i) => { |
| 265 | + // set up |
| 266 | + externalModule.type = type; |
| 267 | + |
| 268 | + // invoke |
| 269 | + externalModule.getSourceString(); |
| 270 | + |
| 271 | + // check |
| 272 | + globalExternalStub.callCount.should.eql(0); |
| 273 | + globalCommonJsStub.callCount.should.eql(i + 1); |
| 274 | + globalAmdOrUmdStub.callCount.should.eql(0); |
| 275 | + defaultExternalStub.callCount.should.eql(0); |
| 276 | + }); |
| 277 | + }); |
| 278 | + }); |
| 279 | + describe("with type being 'amd', 'umd' or 'umd2'", function() { |
| 280 | + it("deletgates to #getSourceForAmdOrUmdExternal", function() { |
| 281 | + ["amd", "umd", "umd2"].forEach((type, i) => { |
| 282 | + // set up |
| 283 | + externalModule.type = type; |
| 284 | + |
| 285 | + // invoke |
| 286 | + externalModule.getSourceString(); |
| 287 | + |
| 288 | + // check |
| 289 | + globalExternalStub.callCount.should.eql(0); |
| 290 | + globalCommonJsStub.callCount.should.eql(0); |
| 291 | + globalAmdOrUmdStub.callCount.should.eql(i + 1); |
| 292 | + defaultExternalStub.callCount.should.eql(0); |
| 293 | + }); |
| 294 | + }); |
| 295 | + }); |
| 296 | + describe("with type being non of the above", function() { |
| 297 | + it("deletgates to #getSourceForGlobalVariableExternal", function() { |
| 298 | + ["foo", "bar", undefined].forEach((type, i) => { |
| 299 | + // set up |
| 300 | + externalModule.type = type; |
| 301 | + |
| 302 | + // invoke |
| 303 | + externalModule.getSourceString(); |
| 304 | + |
| 305 | + // check |
| 306 | + globalExternalStub.callCount.should.eql(0); |
| 307 | + globalCommonJsStub.callCount.should.eql(0); |
| 308 | + globalAmdOrUmdStub.callCount.should.eql(0); |
| 309 | + defaultExternalStub.callCount.should.eql(i + 1); |
| 310 | + }); |
| 311 | + }); |
| 312 | + }); |
| 313 | + }); |
235 | 314 | }); |
0 commit comments