Skip to content

Commit e933f11

Browse files
committed
refactor(ES6): refactor AmdMainTemplatePlugin.test.js to ES6
1 parent 0b47602 commit e933f11

1 file changed

Lines changed: 55 additions & 53 deletions

File tree

‎test/AmdMainTemplatePlugin.test.js‎

Lines changed: 55 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,30 @@
1-
var should = require("should");
2-
var sinon = require("sinon");
3-
var TemplatePluginEnvironment = require("./helpers/TemplatePluginEnvironment");
4-
var ConcatSource = require("webpack-sources").ConcatSource;
5-
var AmdMainTemplatePlugin = require("../lib/AmdMainTemplatePlugin");
6-
7-
describe("AmdMainTemplatePlugin", function() {
8-
var env;
9-
10-
var applyTemplatePluginWithOptions = function(Plugin, name) {
11-
var plugin = new Plugin(name);
12-
var templatePluginEnvironment = new TemplatePluginEnvironment();
13-
var environment = templatePluginEnvironment.getEnvironmentStub();
1+
"use strict";
2+
3+
const should = require("should");
4+
const sinon = require("sinon");
5+
const TemplatePluginEnvironment = require("./helpers/TemplatePluginEnvironment");
6+
const ConcatSource = require("webpack-sources").ConcatSource;
7+
const AmdMainTemplatePlugin = require("../lib/AmdMainTemplatePlugin");
8+
9+
describe("AmdMainTemplatePlugin", () => {
10+
let env;
11+
12+
const applyTemplatePluginWithOptions = function(Plugin, name) {
13+
const plugin = new Plugin(name);
14+
const templatePluginEnvironment = new TemplatePluginEnvironment();
15+
const environment = templatePluginEnvironment.getEnvironmentStub();
1416
environment.mainTemplate.applyPluginsWaterfall = () => "templateName";
1517
plugin.apply(environment);
16-
return templatePluginEnvironment
18+
return templatePluginEnvironment;
1719
};
1820

19-
var setupPluginAndGetEventBinding = function(name) {
20-
var templatePlugin = applyTemplatePluginWithOptions(AmdMainTemplatePlugin, name);
21-
var eventBindings = templatePlugin.getEventBindings();
21+
const setupPluginAndGetEventBinding = function(name) {
22+
const templatePlugin = applyTemplatePluginWithOptions(AmdMainTemplatePlugin, name);
23+
const eventBindings = templatePlugin.getEventBindings();
2224
return eventBindings[0];
2325
};
2426

25-
beforeEach(function() {
27+
beforeEach(() => {
2628
env = {
2729
modulesListWithExternals: [{
2830
id: "module-1",
@@ -48,118 +50,118 @@ describe("AmdMainTemplatePlugin", function() {
4850
};
4951
});
5052

51-
it("has apply function", function() {
53+
it("has apply function", () => {
5254
(new AmdMainTemplatePlugin()).apply.should.be.a.Function();
5355
});
5456

55-
describe("when applied", function() {
56-
beforeEach(function() {
57+
describe("when applied", () => {
58+
beforeEach(() => {
5759
env.templatePlugin = applyTemplatePluginWithOptions(AmdMainTemplatePlugin, "foo");
5860
});
5961

60-
describe("event handlers", function() {
61-
beforeEach(function() {
62+
describe("event handlers", () => {
63+
beforeEach(() => {
6264
env.eventBindings = env.templatePlugin.getEventBindings();
6365
});
6466

65-
it("binds one handlers", function() {
67+
it("binds one handlers", () => {
6668
env.eventBindings.length.should.be.exactly(1);
6769
});
6870

69-
describe("render-with-entry handler", function() {
70-
beforeEach(function() {
71+
describe("render-with-entry handler", () => {
72+
beforeEach(() => {
7173
env.eventBinding = env.eventBindings[0];
7274
});
7375

74-
it("binds to render-with-entry event", function() {
76+
it("binds to render-with-entry event", () => {
7577
env.eventBinding.name.should.be.exactly("render-with-entry");
7678
});
7779

78-
describe("with name", function() {
79-
beforeEach(function() {
80+
describe("with name", () => {
81+
beforeEach(() => {
8082
env.chunk = {
8183
modules: env.modulesListWithExternals
8284
};
8385
env.eventBinding = setupPluginAndGetEventBinding("foo");
8486
});
8587

86-
it("creates source wrapper with module name and external dependencies", function() {
87-
var source = env.eventBinding.handler("moduleSource()", env.chunk, "bar");
88+
it("creates source wrapper with module name and external dependencies", () => {
89+
const source = env.eventBinding.handler("moduleSource()", env.chunk, "bar");
8890
source.should.be.instanceof(ConcatSource);
8991
source.source().should.be.exactly('define("templateName", ["external-amd-module","external-non-amd-module",null], function(__WEBPACK_EXTERNAL_MODULE_module-1__, __WEBPACK_EXTERNAL_MODULE_module-2__, __WEBPACK_EXTERNAL_MODULE_module-3__) { return moduleSource()});');
9092
});
9193
});
9294

93-
describe("with external dependencies", function() {
94-
beforeEach(function() {
95+
describe("with external dependencies", () => {
96+
beforeEach(() => {
9597
env.chunk = {
9698
modules: env.modulesListWithExternals
9799
};
98100
env.eventBinding = setupPluginAndGetEventBinding();
99101
});
100102

101-
it("creates source wrapper with external dependencies", function() {
102-
var source = env.eventBinding.handler("moduleSource()", env.chunk, "bar");
103+
it("creates source wrapper with external dependencies", () => {
104+
const source = env.eventBinding.handler("moduleSource()", env.chunk, "bar");
103105
source.should.be.instanceof(ConcatSource);
104106
source.source().should.be.exactly('define(["external-amd-module","external-non-amd-module",null], function(__WEBPACK_EXTERNAL_MODULE_module-1__, __WEBPACK_EXTERNAL_MODULE_module-2__, __WEBPACK_EXTERNAL_MODULE_module-3__) { return moduleSource()});');
105107
});
106108
});
107109

108-
describe("with only local dependencies", function() {
109-
beforeEach(function() {
110-
var externalFlag = {
110+
describe("with only local dependencies", () => {
111+
beforeEach(() => {
112+
const externalFlag = {
111113
external: false
112114
};
113-
var noExternals = env.modulesListWithExternals.map((module) => Object.assign(module, externalFlag));
115+
const noExternals = env.modulesListWithExternals.map((module) => Object.assign(module, externalFlag));
114116
env.chunk = {
115117
modules: noExternals
116118
};
117119
env.eventBinding = setupPluginAndGetEventBinding();
118120
});
119121

120-
it("creates source wrapper with callback only", function() {
121-
var source = env.eventBinding.handler("moduleSource()", env.chunk, "bar");
122+
it("creates source wrapper with callback only", () => {
123+
const source = env.eventBinding.handler("moduleSource()", env.chunk, "bar");
122124
source.should.be.instanceof(ConcatSource);
123125
source.source().should.be.exactly('define(function() { return moduleSource()});');
124126
});
125127
});
126128
});
127129
});
128130

129-
describe("main template event handlers", function() {
130-
beforeEach(function() {
131+
describe("main template event handlers", () => {
132+
beforeEach(() => {
131133
env.mainTemplateBindings = env.templatePlugin.getMainTemplateBindings();
132134
});
133135

134-
it("binds two handlers", function() {
136+
it("binds two handlers", () => {
135137
env.mainTemplateBindings.length.should.be.exactly(2);
136138
});
137139

138-
describe("global-hash-paths handler", function() {
139-
beforeEach(function() {
140+
describe("global-hash-paths handler", () => {
141+
beforeEach(() => {
140142
env.mainTemplateBinding = env.mainTemplateBindings[0];
141143
});
142144

143-
it("binds to global-hash-paths event", function() {
145+
it("binds to global-hash-paths event", () => {
144146
env.mainTemplateBinding.name.should.be.exactly("global-hash-paths");
145147
});
146148

147-
it("adds name to path array", function() {
149+
it("adds name to path array", () => {
148150
env.mainTemplateBinding.handler([]).should.deepEqual(["foo"]);
149151
});
150152
});
151153

152-
describe("hash handler", function() {
153-
beforeEach(function() {
154+
describe("hash handler", () => {
155+
beforeEach(() => {
154156
env.mainTemplateBinding = env.mainTemplateBindings[1];
155157
});
156158

157-
it("binds to hash event", function() {
159+
it("binds to hash event", () => {
158160
env.mainTemplateBinding.name.should.be.exactly("hash");
159161
});
160162

161-
it("updates hash", function() {
162-
var hash = {
163+
it("updates hash", () => {
164+
const hash = {
163165
update: sinon.spy()
164166
};
165167
env.mainTemplateBinding.handler(hash);

0 commit comments

Comments
 (0)