Skip to content

Commit fda7e64

Browse files
committed
refactor(ES6): RequireJsStuffPlugin.test.js
1 parent d9ac043 commit fda7e64

1 file changed

Lines changed: 59 additions & 94 deletions

File tree

‎test/RequireJsStuffPlugin.test.js‎

Lines changed: 59 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,33 @@
11
"use strict";
2+
23
const should = require("should");
34
const sinon = require("sinon");
45
const RequireJsStuffPlugin = require("../lib/RequireJsStuffPlugin");
56
const applyPluginWithOptions = require("./helpers/applyPluginWithOptions");
67
const PluginEnvironment = require("./helpers/PluginEnvironment");
78

8-
describe("RequireJsStuffPlugin", function() {
9-
it("has apply function", function() {
10-
(new RequireJsStuffPlugin()).apply.should.be.a.Function();
11-
});
9+
describe("RequireJsStuffPlugin", () => {
10+
it("has apply function", () => (new RequireJsStuffPlugin()).apply.should.be.a.Function());
1211

13-
describe("when applied", function() {
12+
describe("when applied", () => {
1413
let eventBindings;
1514
let eventBinding;
1615

17-
beforeEach(function() {
18-
eventBindings = applyPluginWithOptions(RequireJsStuffPlugin);
19-
});
16+
beforeEach(() => eventBindings = applyPluginWithOptions(RequireJsStuffPlugin));
2017

21-
it("binds one event handler", function() {
22-
eventBindings.length.should.be.exactly(1);
23-
});
18+
it("binds one event handler", () => eventBindings.length.should.be.exactly(1));
2419

25-
describe("compilation handler", function() {
26-
beforeEach(function() {
27-
eventBinding = eventBindings[0];
28-
});
20+
describe("compilation handler", () => {
21+
beforeEach(() => eventBinding = eventBindings[0]);
2922

30-
it("binds to compilation event", function() {
31-
eventBinding.name.should.be.exactly("compilation");
32-
});
23+
it("binds to compilation event", () => eventBinding.name.should.be.exactly("compilation"));
3324

34-
describe('when called', function() {
25+
describe("when called", () => {
3526
let pluginEnvironment;
3627
let compilationEventBindings;
3728
let compilation;
3829

39-
beforeEach(function() {
30+
beforeEach(() => {
4031
pluginEnvironment = new PluginEnvironment();
4132
compilation = {
4233
dependencyFactories: {
@@ -53,52 +44,44 @@ describe("RequireJsStuffPlugin", function() {
5344
compilationEventBindings = pluginEnvironment.getEventBindings();
5445
});
5546

56-
it('sets the dependency factory', function() {
57-
compilation.dependencyFactories.set.callCount.should.be.exactly(1);
58-
});
47+
it("sets the dependency factory", () =>
48+
compilation.dependencyFactories.set.callCount.should.be.exactly(1));
5949

60-
it('sets the dependency template', function() {
61-
compilation.dependencyTemplates.set.callCount.should.be.exactly(1);
62-
});
50+
it("sets the dependency template", () =>
51+
compilation.dependencyTemplates.set.callCount.should.be.exactly(1));
6352

64-
it("binds one event handler", function() {
65-
compilationEventBindings.length.should.be.exactly(1);
66-
});
53+
it("binds one event handler", () => compilationEventBindings.length.should.be.exactly(1));
6754

68-
describe("parser handler", function() {
55+
describe("parser handler", () => {
6956
let parser;
7057
let parserEventBindings;
7158
let compilationEventBinding;
7259

73-
beforeEach(function() {
60+
beforeEach(() => {
7461
compilationEventBinding = compilationEventBindings[0];
7562
pluginEnvironment = new PluginEnvironment();
7663
parser = pluginEnvironment.getEnvironmentStub();
7764
});
7865

79-
it("binds to parser event", function() {
80-
compilationEventBinding.name.should.be.exactly("parser");
81-
});
66+
it("binds to parser event", () => compilationEventBinding.name.should.be.exactly("parser"));
8267

83-
describe('when called with parser options of requirejs as false', function() {
84-
beforeEach(function() {
68+
describe("when called with parser options of requirejs as false", () => {
69+
beforeEach(() => {
8570
compilationEventBinding.handler(parser, {
8671
requireJs: false
8772
});
8873
parserEventBindings = pluginEnvironment.getEventBindings();
8974
});
9075

91-
it("binds no event handlers", function() {
92-
parserEventBindings.length.should.be.exactly(0);
93-
});
76+
it("binds no event handlers", () => parserEventBindings.length.should.be.exactly(0));
9477
});
9578

96-
describe('when called with empty parser options', function() {
79+
describe("when called with empty parser options", () => {
9780
let parserEventBinding;
9881
let parserEventContext;
9982
let expressionMock;
10083

101-
beforeEach(function() {
84+
beforeEach(() => {
10285
parserEventContext = {
10386
state: {
10487
current: {
@@ -114,48 +97,38 @@ describe("RequireJsStuffPlugin", function() {
11497
parserEventBindings = pluginEnvironment.getEventBindings();
11598
});
11699

117-
it("binds four event handlers", function() {
118-
parserEventBindings.length.should.be.exactly(4);
119-
});
100+
it("binds four event handlers", () => parserEventBindings.length.should.be.exactly(4));
120101

121-
describe("'call require.config' handler", function() {
122-
beforeEach(function() {
123-
parserEventBinding = parserEventBindings[0];
124-
});
102+
describe("'call require.config' handler", () => {
103+
beforeEach(() => parserEventBinding = parserEventBindings[0]);
125104

126-
it("binds to 'call require.config' event", function() {
127-
parserEventBinding.name.should.be.exactly("call require.config");
128-
});
105+
it("binds to 'call require.config' event", () =>
106+
parserEventBinding.name.should.be.exactly("call require.config"));
129107

130-
describe('when called', function() {
131-
beforeEach(function() {
132-
parserEventBinding.handler.call(parserEventContext, expressionMock);
133-
});
108+
describe("when called", () => {
109+
beforeEach(() =>
110+
parserEventBinding.handler.call(parserEventContext, expressionMock));
134111

135-
it('adds dependency to current state', function() {
136-
var addDependencySpy = parserEventContext.state.current.addDependency;
137-
var addedDependency = JSON.stringify(addDependencySpy.getCall(0).args[0]);
112+
it("adds dependency to current state", () => {
113+
const addDependencySpy = parserEventContext.state.current.addDependency;
114+
const addedDependency = JSON.stringify(addDependencySpy.getCall(0).args[0]);
138115
addDependencySpy.callCount.should.be.exactly(1);
139116
addedDependency.should.be.exactly('{"module":null,"expression":";","range":10,"loc":5}');
140117
});
141118
});
142119
});
143120

144-
describe("'call requirejs.config' handler", function() {
145-
beforeEach(function() {
146-
parserEventBinding = parserEventBindings[1];
147-
});
121+
describe("'call requirejs.config' handler", () => {
122+
beforeEach(() => parserEventBinding = parserEventBindings[1]);
148123

149-
it("binds to 'call requirejs.config' event", function() {
150-
parserEventBinding.name.should.be.exactly("call requirejs.config");
151-
});
124+
it("binds to 'call requirejs.config' event", () =>
125+
parserEventBinding.name.should.be.exactly("call requirejs.config"));
152126

153-
describe('when called', function() {
154-
beforeEach(function() {
155-
parserEventBinding.handler.call(parserEventContext, expressionMock);
156-
});
127+
describe("when called", () => {
128+
beforeEach(() =>
129+
parserEventBinding.handler.call(parserEventContext, expressionMock));
157130

158-
it('adds dependency to current state', function() {
131+
it("adds dependency to current state", () => {
159132
const addDependencySpy = parserEventContext.state.current.addDependency;
160133
const addedDependency = JSON.stringify(addDependencySpy.getCall(0).args[0]);
161134
addDependencySpy.callCount.should.be.exactly(1);
@@ -164,21 +137,17 @@ describe("RequireJsStuffPlugin", function() {
164137
});
165138
});
166139

167-
describe("'expression require.version' handler", function() {
168-
beforeEach(function() {
169-
parserEventBinding = parserEventBindings[2];
170-
});
140+
describe("'expression require.version' handler", () => {
141+
beforeEach(() => parserEventBinding = parserEventBindings[2]);
171142

172-
it("binds to 'expression require.version' event", function() {
173-
parserEventBinding.name.should.be.exactly("expression require.version");
174-
});
143+
it("binds to 'expression require.version' event", () =>
144+
parserEventBinding.name.should.be.exactly("expression require.version"));
175145

176-
describe('when called', function() {
177-
beforeEach(function() {
178-
parserEventBinding.handler.call(parserEventContext, expressionMock);
179-
});
146+
describe("when called", () => {
147+
beforeEach(() =>
148+
parserEventBinding.handler.call(parserEventContext, expressionMock));
180149

181-
it('adds dependency to current state', function() {
150+
it("adds dependency to current state", () => {
182151
const addDependencySpy = parserEventContext.state.current.addDependency;
183152
const addedDependency = JSON.stringify(addDependencySpy.getCall(0).args[0]);
184153
addDependencySpy.callCount.should.be.exactly(1);
@@ -187,21 +156,17 @@ describe("RequireJsStuffPlugin", function() {
187156
});
188157
});
189158

190-
describe("'expression requirejs.onError' handler", function() {
191-
beforeEach(function() {
192-
parserEventBinding = parserEventBindings[3];
193-
});
159+
describe("'expression requirejs.onError' handler", () => {
160+
beforeEach(() => parserEventBinding = parserEventBindings[3]);
194161

195-
it("binds to 'expression requirejs.onError' event", function() {
196-
parserEventBinding.name.should.be.exactly("expression requirejs.onError");
197-
});
162+
it("binds to 'expression requirejs.onError' event", () =>
163+
parserEventBinding.name.should.be.exactly("expression requirejs.onError"));
198164

199-
describe('when called', function() {
200-
beforeEach(function() {
201-
parserEventBinding.handler.call(parserEventContext, expressionMock);
202-
});
165+
describe("when called", () => {
166+
beforeEach(() =>
167+
parserEventBinding.handler.call(parserEventContext, expressionMock));
203168

204-
it('adds dependency to current state', function() {
169+
it("adds dependency to current state", () => {
205170
const addDependencySpy = parserEventContext.state.current.addDependency;
206171
const addedDependency = JSON.stringify(addDependencySpy.getCall(0).args[0]);
207172
addDependencySpy.callCount.should.be.exactly(1);

0 commit comments

Comments
 (0)