Skip to content

Commit 20854fb

Browse files
committed
refactor(ES6): JsonpExportMainTemplatePlugin.test.js
1 parent d9ac043 commit 20854fb

1 file changed

Lines changed: 42 additions & 68 deletions

File tree

Lines changed: 42 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,68 @@
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 JsonpExportMainTemplatePlugin = require("../lib/JsonpExportMainTemplatePlugin");
6-
7-
describe("JsonpExportMainTemplatePlugin", 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+
const should = require("should");
2+
const sinon = require("sinon");
3+
const TemplatePluginEnvironment = require("./helpers/TemplatePluginEnvironment");
4+
const ConcatSource = require("webpack-sources").ConcatSource;
5+
const JsonpExportMainTemplatePlugin = require("../lib/JsonpExportMainTemplatePlugin");
6+
7+
describe("JsonpExportMainTemplatePlugin", () => {
8+
let env;
9+
10+
const applyTemplatePluginWithOptions = function(Plugin, name) {
11+
const plugin = new Plugin(name);
12+
const templatePluginEnvironment = new TemplatePluginEnvironment();
13+
const environment = templatePluginEnvironment.getEnvironmentStub();
1414
environment.mainTemplate.applyPluginsWaterfall = () => "templateName";
1515
plugin.apply(environment);
16-
return templatePluginEnvironment
16+
return templatePluginEnvironment;
1717
};
1818

19-
beforeEach(function() {
20-
env = {}
21-
});
19+
beforeEach(() => env = {});
2220

23-
it("has apply function", function() {
24-
(new JsonpExportMainTemplatePlugin()).apply.should.be.a.Function();
25-
});
21+
it("has apply function", () => (new JsonpExportMainTemplatePlugin()).apply.should.be.a.Function());
2622

27-
describe("when applied", function() {
28-
beforeEach(function() {
29-
env.templatePlugin = applyTemplatePluginWithOptions(JsonpExportMainTemplatePlugin, "foo");
30-
});
23+
describe("when applied", () => {
24+
beforeEach(() =>
25+
env.templatePlugin = applyTemplatePluginWithOptions(JsonpExportMainTemplatePlugin, "foo"));
3126

32-
describe("event handlers", function() {
33-
beforeEach(function() {
34-
env.eventBindings = env.templatePlugin.getEventBindings();
35-
});
27+
describe("event handlers", () => {
28+
beforeEach(() => env.eventBindings = env.templatePlugin.getEventBindings());
3629

37-
it("binds one handlers", function() {
38-
env.eventBindings.length.should.be.exactly(1);
39-
});
30+
it("binds one handlers", () => env.eventBindings.length.should.be.exactly(1));
4031

41-
describe("render-with-entry handler", function() {
42-
beforeEach(function() {
43-
env.eventBinding = env.eventBindings[0];
44-
});
32+
describe("render-with-entry handler", () => {
33+
beforeEach(() => env.eventBinding = env.eventBindings[0]);
4534

46-
it("binds to render-with-entry event", function() {
47-
env.eventBinding.name.should.be.exactly("render-with-entry");
48-
});
35+
it("binds to render-with-entry event", () =>
36+
env.eventBinding.name.should.be.exactly("render-with-entry"));
4937

50-
it("creates source wrapper calling JSONP global callback", function() {
51-
var source = env.eventBinding.handler("moduleSource()", env.chunk, "bar");
38+
it("creates source wrapper calling JSONP global callback", () => {
39+
const source = env.eventBinding.handler("moduleSource()", env.chunk, "bar");
5240
source.should.be.instanceof(ConcatSource);
53-
source.source().should.be.exactly('templateName(moduleSource());');
41+
source.source().should.be.exactly("templateName(moduleSource());");
5442
});
5543
});
5644
});
5745

58-
describe("main template event handlers", function() {
59-
beforeEach(function() {
60-
env.mainTemplateBindings = env.templatePlugin.getMainTemplateBindings();
61-
});
46+
describe("main template event handlers", () => {
47+
beforeEach(() => env.mainTemplateBindings = env.templatePlugin.getMainTemplateBindings());
6248

63-
it("binds two handlers", function() {
64-
env.mainTemplateBindings.length.should.be.exactly(2);
65-
});
49+
it("binds two handlers", () => env.mainTemplateBindings.length.should.be.exactly(2));
6650

67-
describe("global-hash-paths handler", function() {
68-
beforeEach(function() {
69-
env.mainTemplateBinding = env.mainTemplateBindings[0];
70-
});
51+
describe("global-hash-paths handler", () => {
52+
beforeEach(() => env.mainTemplateBinding = env.mainTemplateBindings[0]);
7153

72-
it("binds to global-hash-paths event", function() {
73-
env.mainTemplateBinding.name.should.be.exactly("global-hash-paths");
74-
});
54+
it("binds to global-hash-paths event", () => env.mainTemplateBinding.name.should.be.exactly("global-hash-paths"));
7555

76-
it("adds name to path array", function() {
77-
env.mainTemplateBinding.handler([]).should.deepEqual(["foo"]);
78-
});
56+
it("adds name to path array", () => env.mainTemplateBinding.handler([]).should.deepEqual(["foo"]));
7957
});
8058

81-
describe("hash handler", function() {
82-
beforeEach(function() {
83-
env.mainTemplateBinding = env.mainTemplateBindings[1];
84-
});
59+
describe("hash handler", () => {
60+
beforeEach(() => env.mainTemplateBinding = env.mainTemplateBindings[1]);
8561

86-
it("binds to hash event", function() {
87-
env.mainTemplateBinding.name.should.be.exactly("hash");
88-
});
62+
it("binds to hash event", () => env.mainTemplateBinding.name.should.be.exactly("hash"));
8963

90-
it("updates hash", function() {
91-
var hash = {
64+
it("updates hash", () => {
65+
const hash = {
9266
update: sinon.spy()
9367
};
9468
env.mainTemplateBinding.handler(hash);
@@ -98,6 +72,6 @@ describe("JsonpExportMainTemplatePlugin", function() {
9872
hash.update.secondCall.args[0].should.be.exactly("foo");
9973
});
10074
});
101-
})
75+
});
10276
});
10377
});

0 commit comments

Comments
 (0)