Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5849 from cdata/fix-5843
Fixes #5843
- Loading branch information
Showing
2 changed files
with
71 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* global describe, beforeEach, it */ | ||
"use strict"; | ||
|
||
const should = require("should"); | ||
const TemplatePluginEnvironment = require("./helpers/TemplatePluginEnvironment"); | ||
const ConcatSource = require("webpack-sources").ConcatSource; | ||
const UmdMainTemplatePlugin = require("../lib/UmdMainTemplatePlugin"); | ||
|
||
describe("UmdMainTemplatePlugin", () => { | ||
|
||
const setupBasicTemplatePlugin = name => { | ||
const plugin = new UmdMainTemplatePlugin({ | ||
amd: name | ||
}, { | ||
auxiliaryComment: {} | ||
}); | ||
const templatePlugin = new TemplatePluginEnvironment(); | ||
const environment = templatePlugin.getEnvironmentStub(); | ||
environment.mainTemplate.applyPluginsWaterfall = () => []; | ||
plugin.apply(environment); | ||
return templatePlugin; | ||
}; | ||
|
||
let templatePlugin; | ||
|
||
beforeEach(() => { | ||
templatePlugin = setupBasicTemplatePlugin("foo"); | ||
}); | ||
|
||
describe("when applied", () => { | ||
describe("event handlers", () => { | ||
let eventBindings; | ||
|
||
beforeEach(() => { | ||
eventBindings = templatePlugin.getEventBindings(); | ||
}); | ||
|
||
describe("handling render-with-entry", () => { | ||
let eventHandler; | ||
|
||
beforeEach(() => { | ||
eventHandler = eventBindings | ||
.filter(eventBinding => eventBinding.name === 'render-with-entry') | ||
.map(eventBinding => eventBinding.handler) | ||
.pop(); | ||
}); | ||
|
||
it("creates source that safely detects the global object", () => { | ||
const source = eventHandler("{ foo: true }", { | ||
getModules: () => [] | ||
}, "bar"); | ||
|
||
source.should.be.instanceof(ConcatSource); | ||
source.source().should.be.exactly(`(function webpackUniversalModuleDefinition(root, factory) { | ||
if(typeof exports === 'object' && typeof module === 'object') | ||
module.exports = factory(); | ||
else if(typeof define === 'function' && define.amd) | ||
define([], factory); | ||
else { | ||
var a = factory(); | ||
for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i]; | ||
} | ||
})(typeof self !== 'undefined' ? self : this, function() { | ||
return { foo: true }; | ||
})`); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |