Skip to content

Commit 8ef03de

Browse files
committed
test: modify tests on 'hermione.ctx' method
1 parent a6fec7c commit 8ef03de

File tree

3 files changed

+62
-32
lines changed

3 files changed

+62
-32
lines changed

test/lib/runner/index.js

+19
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ describe('Runner', () => {
4646
sandbox.stub(MochaRunner.prototype, 'run');
4747
MochaRunner.prototype.run.returns(q());
4848

49+
sandbox.stub(MochaRunner, 'init');
50+
sandbox.stub(MochaRunner, 'clean');
51+
4952
sandbox.stub(RetryManager.prototype);
5053
});
5154

@@ -68,6 +71,22 @@ describe('Runner', () => {
6871
assert.calledOnce(RetryManager.prototype.__constructor);
6972
assert.calledWith(RetryManager.prototype.__constructor, config);
7073
});
74+
75+
it('should init mocha runner on RUNNER_START event', () => {
76+
const runner = new Runner(makeConfigStub());
77+
78+
runner.emit(RunnerEvents.RUNNER_START);
79+
80+
assert.calledOnce(MochaRunner.init);
81+
});
82+
83+
it('should clean mocha runner on RUNNER_END event', () => {
84+
const runner = new Runner(makeConfigStub());
85+
86+
runner.emit(RunnerEvents.RUNNER_END);
87+
88+
assert.calledOnce(MochaRunner.clean);
89+
});
7190
});
7291

7392
describe('run', () => {

test/lib/runner/mocha-runner/index.js

+18
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ describe('mocha-runner', () => {
2626
const mkMochaAdapterStub_ = () => Object.create(MochaAdapter.prototype);
2727

2828
beforeEach(() => {
29+
sandbox.stub(MochaAdapter, 'init');
30+
sandbox.stub(MochaAdapter, 'clean');
2931
sandbox.stub(MochaAdapter.prototype, 'addFiles').returnsThis();
3032
sandbox.stub(MochaAdapter.prototype, 'attachTestFilter').returnsThis();
3133
sandbox.stub(MochaAdapter.prototype, 'attachTitleValidator').returnsThis();
@@ -36,6 +38,22 @@ describe('mocha-runner', () => {
3638

3739
afterEach(() => sandbox.restore());
3840

41+
describe('init', () => {
42+
it('should init mocha adapter', () => {
43+
MochaRunner.init();
44+
45+
assert.calledOnce(MochaAdapter.init);
46+
});
47+
});
48+
49+
describe('clean', () => {
50+
it('should clean mocha adapter', () => {
51+
MochaRunner.clean();
52+
53+
assert.calledOnce(MochaAdapter.clean);
54+
});
55+
});
56+
3957
describe('run', () => {
4058
beforeEach(() => sandbox.stub(MochaAdapter, 'create', () => mkMochaAdapterStub_()));
4159

test/lib/runner/mocha-runner/mocha-adapter.js

+25-32
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,26 @@ describe('mocha-runner/mocha-adapter', () => {
8484

8585
afterEach(() => sandbox.restore());
8686

87+
describe('init', () => {
88+
it('should add an empty hermione object to global', () => {
89+
MochaAdapter.init();
90+
91+
assert.deepEqual(global.hermione, {});
92+
93+
delete global.hermione;
94+
});
95+
});
96+
97+
describe('clean', () => {
98+
it('should delete hermione from global', () => {
99+
global.hermione = 'some-global-value';
100+
101+
MochaAdapter.clean();
102+
103+
assert.isUndefined(global.hermione);
104+
});
105+
});
106+
87107
describe('constructor', () => {
88108
it('should pass shared opts to mocha instance', () => {
89109
mkMochaAdapter_({grep: 'foo'});
@@ -138,54 +158,27 @@ describe('mocha-runner/mocha-adapter', () => {
138158
assert.deepEqual(mocha.files, []);
139159
});
140160

141-
it('should add global "hermione" object on "pre-require" event', () => {
142-
const mochaAdapter = mkMochaAdapter_();
143-
144-
mochaAdapter.addFiles(['path/to/file']);
145-
MochaStub.prototype.suite.emit('pre-require');
146-
147-
assert.isDefined(global.hermione);
148-
});
149-
150161
describe('hermione global', () => {
151-
afterEach(() => delete global.hermione);
162+
beforeEach(() => MochaAdapter.init());
163+
afterEach(() => MochaAdapter.clean());
152164

153165
it('hermione.skip should return SkipBuilder instance', () => {
154-
const mochaAdapter = mkMochaAdapter_();
155-
156-
mochaAdapter.addFiles(['path/to/file']);
157-
MochaStub.prototype.suite.emit('pre-require');
166+
mkMochaAdapter_();
158167

159168
assert.instanceOf(global.hermione.skip, SkipBuilder);
160169
});
161170

162171
it('hermione.only should return OnlyBuilder instance', () => {
163-
const mochaAdapter = mkMochaAdapter_();
164-
165-
mochaAdapter.addFiles(['path/to/file']);
166-
MochaStub.prototype.suite.emit('pre-require');
172+
mkMochaAdapter_();
167173

168174
assert.instanceOf(global.hermione.only, OnlyBuilder);
169175
});
170176

171177
it('hermione.ctx should return passed ctx', () => {
172-
const mochaAdapter = mkMochaAdapter_({}, {some: 'ctx'});
173-
174-
mochaAdapter.addFiles(['path/to/file.js']);
175-
MochaStub.prototype.suite.emit('pre-require');
178+
mkMochaAdapter_({}, {some: 'ctx'});
176179

177180
assert.deepEqual(global.hermione.ctx, {some: 'ctx'});
178181
});
179-
180-
it('should remove global "hermione" object on "post-require" event', () => {
181-
const mochaAdapter = mkMochaAdapter_();
182-
183-
mochaAdapter.addFiles(['path/to/file']);
184-
MochaStub.prototype.suite.emit('pre-require');
185-
MochaStub.prototype.suite.emit('post-require');
186-
187-
assert.isUndefined(global.hermione);
188-
});
189182
});
190183
});
191184

0 commit comments

Comments
 (0)