Skip to content

Commit dd659c2

Browse files
committed
style(lint): lint test files
1 parent 3825f21 commit dd659c2

9 files changed

+311
-182
lines changed

test/unit/CancellationToken.spec.js

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,22 @@ var beforeEach = require('mocha').beforeEach;
77
var afterEach = require('mocha').afterEach;
88
var expect = require('chai').expect;
99
var mockFs = require('mock-fs');
10-
var CancellationToken = require('../../lib/CancellationToken').CancellationToken;
10+
var CancellationToken = require('../../lib/CancellationToken')
11+
.CancellationToken;
1112

12-
describe('[UNIT] CancellationToken', function () {
13-
beforeEach(function () {
13+
describe('[UNIT] CancellationToken', function() {
14+
beforeEach(function() {
1415
var fsTree = {};
1516
fsTree[os.tmpdir()] = mockFs.directory();
1617

1718
mockFs(fsTree);
1819
});
1920

20-
afterEach(function () {
21+
afterEach(function() {
2122
mockFs.restore();
2223
});
2324

24-
it('should create valid cancellation token', function () {
25+
it('should create valid cancellation token', function() {
2526
var tokenA = new CancellationToken();
2627
expect(tokenA.isCancellationRequested()).to.be.false;
2728

@@ -35,42 +36,54 @@ describe('[UNIT] CancellationToken', function () {
3536
expect(tokenD.isCancellationRequested()).to.be.true;
3637
});
3738

38-
it('should serialize to JSON', function () {
39+
it('should serialize to JSON', function() {
3940
var tokenA = new CancellationToken();
4041
var json = JSON.stringify(tokenA);
4142

4243
expect(json).to.be.a('string');
43-
expect(function() { JSON.parse(json); }).to.not.throw(Error);
44+
expect(function() {
45+
JSON.parse(json);
46+
}).to.not.throw(Error);
4447
expect(JSON.parse(json)).to.be.a('object');
4548

4649
var tokenB = CancellationToken.createFromJSON(JSON.parse(json));
47-
expect(tokenA.getCancellationFilePath()).to.be.equal(tokenB.getCancellationFilePath());
48-
expect(tokenA.isCancellationRequested()).to.be.equal(tokenB.isCancellationRequested());
50+
expect(tokenA.getCancellationFilePath()).to.be.equal(
51+
tokenB.getCancellationFilePath()
52+
);
53+
expect(tokenA.isCancellationRequested()).to.be.equal(
54+
tokenB.isCancellationRequested()
55+
);
4956
});
5057

51-
it('should generate path in os.tmpdir() directory', function () {
58+
it('should generate path in os.tmpdir() directory', function() {
5259
var tokenA = new CancellationToken();
5360

54-
expect(tokenA.getCancellationFilePath().indexOf(os.tmpdir())).to.be.equal(0);
61+
expect(tokenA.getCancellationFilePath().indexOf(os.tmpdir())).to.be.equal(
62+
0
63+
);
5564
});
5665

57-
it('should throw ts.OperationCanceledException error on cancelled', function () {
66+
it('should throw ts.OperationCanceledException error on cancelled', function() {
5867
var tokenA = new CancellationToken();
59-
expect(function () { tokenA.throwIfCancellationRequested(); }).to.not.throw();
68+
expect(function() {
69+
tokenA.throwIfCancellationRequested();
70+
}).to.not.throw();
6071

6172
var tokenB = new CancellationToken('rgeer#R23r$#T$3t#$t43', true);
62-
expect(function () { tokenB.throwIfCancellationRequested(); }).to.throw(ts.OperationCanceledException);
73+
expect(function() {
74+
tokenB.throwIfCancellationRequested();
75+
}).to.throw(ts.OperationCanceledException);
6376
});
6477

65-
it('should write file in filesystem on requestCancellation', function () {
78+
it('should write file in filesystem on requestCancellation', function() {
6679
var tokenA = new CancellationToken();
6780
tokenA.requestCancellation();
6881

6982
expect(tokenA.isCancellationRequested()).to.be.true;
7083
expect(fs.existsSync(tokenA.getCancellationFilePath())).to.be.true;
7184
});
7285

73-
it('should cleanup file on cleanupCancellation', function () {
86+
it('should cleanup file on cleanupCancellation', function() {
7487
var tokenA = new CancellationToken();
7588
tokenA.requestCancellation();
7689
tokenA.cleanupCancellation();
@@ -79,18 +92,24 @@ describe('[UNIT] CancellationToken', function () {
7992
expect(fs.existsSync(tokenA.getCancellationFilePath())).to.be.false;
8093

8194
// make sure we can call it as many times as we want to
82-
expect(function() { tokenA.cleanupCancellation(); }).to.not.throw(Error);
95+
expect(function() {
96+
tokenA.cleanupCancellation();
97+
}).to.not.throw(Error);
8398
expect(tokenA.isCancellationRequested()).to.be.false;
8499
});
85100

86-
it('should not throw error on cleanupCancellation with no file exists', function () {
101+
it('should not throw error on cleanupCancellation with no file exists', function() {
87102
var tokenA = new CancellationToken('some_file_that_doesnt_exists', true);
88103

89-
expect(function() { tokenA.cleanupCancellation(); }).to.not.throw();
90-
expect(function() { tokenA.cleanupCancellation(); }).to.not.throw();
104+
expect(function() {
105+
tokenA.cleanupCancellation();
106+
}).to.not.throw();
107+
expect(function() {
108+
tokenA.cleanupCancellation();
109+
}).to.not.throw();
91110
});
92111

93-
it('should throttle check for 10ms', function (done) {
112+
it('should throttle check for 10ms', function(done) {
94113
var tokenA = new CancellationToken();
95114
var tokenB = CancellationToken.createFromJSON(tokenA.toJSON());
96115
var start = Date.now();
@@ -107,7 +126,7 @@ describe('[UNIT] CancellationToken', function () {
107126
expect(tokenB.isCancellationRequested()).to.be.false;
108127
}
109128

110-
setTimeout(function () {
129+
setTimeout(function() {
111130
expect(tokenB.isCancellationRequested()).to.be.true;
112131
done();
113132
}, 11);

test/unit/FileRegister.spec.js

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ var beforeEach = require('mocha').beforeEach;
44
var expect = require('chai').expect;
55
var FilesRegister = require('../../lib/FilesRegister').FilesRegister;
66

7-
describe('[UNIT] FilesRegister', function () {
7+
describe('[UNIT] FilesRegister', function() {
88
var register;
9-
beforeEach(function () {
10-
register = new FilesRegister(function () {
9+
beforeEach(function() {
10+
register = new FilesRegister(function() {
1111
return {
1212
test: true
1313
};
1414
});
1515
});
1616

17-
it('should add and remove files', function () {
17+
it('should add and remove files', function() {
1818
register.add('/test');
1919
register.add('/test2');
2020
expect(register.has('/test')).to.be.true;
@@ -23,37 +23,52 @@ describe('[UNIT] FilesRegister', function () {
2323
expect(register.has('/test')).to.be.false;
2424
expect(register.has('/test2')).to.be.true;
2525

26-
expect(function() { register.remove('/test'); }).to.not.throw();
26+
expect(function() {
27+
register.remove('/test');
28+
}).to.not.throw();
2729
register.remove('/test2');
2830
expect(register.has('/test')).to.be.false;
2931
expect(register.has('/test2')).to.be.false;
3032
});
3133

32-
it('should get file that exists in register', function () {
34+
it('should get file that exists in register', function() {
3335
register.add('/test');
34-
expect(function() { register.get('/test'); }).to.not.throw();
35-
expect(function() { register.get('/test2'); }).to.throw();
36+
expect(function() {
37+
register.get('/test');
38+
}).to.not.throw();
39+
expect(function() {
40+
register.get('/test2');
41+
}).to.throw();
3642
expect(register.get('/test')).to.be.a('object');
37-
expect(Object.keys(register.get('/test'))).to.be.deep.equal(['mtime', 'data']);
43+
expect(Object.keys(register.get('/test'))).to.be.deep.equal([
44+
'mtime',
45+
'data'
46+
]);
3847
});
3948

40-
it('should list all keys in register', function () {
49+
it('should list all keys in register', function() {
4150
register.add('/test');
4251
register.add('/test/foo');
4352
register.add('/test/foo/bar');
44-
expect(register.keys()).to.be.deep.equal(['/test', '/test/foo', '/test/foo/bar']);
53+
expect(register.keys()).to.be.deep.equal([
54+
'/test',
55+
'/test/foo',
56+
'/test/foo/bar'
57+
]);
4558

4659
register.remove('/test');
4760
expect(register.keys()).to.be.deep.equal(['/test/foo', '/test/foo/bar']);
4861
});
4962

50-
it('should get data from file', function () {
63+
it('should get data from file', function() {
5164
register.add('/test');
5265
expect(register.getData('/test')).to.be.deep.equal({ test: true });
53-
expect(function() { register.getData('/test2'); }).to.throw(Error);
66+
expect(function() {
67+
register.getData('/test2');
68+
}).to.throw(Error);
5469
});
5570

56-
it('should ensure if file exists', function () {
71+
it('should ensure if file exists', function() {
5772
expect(register.has('/test')).to.be.false;
5873
register.ensure('/test');
5974
expect(register.has('/test')).to.be.true;
@@ -63,20 +78,20 @@ describe('[UNIT] FilesRegister', function () {
6378
expect(reference).to.be.equal(register.get('/test'));
6479
});
6580

66-
it('should mutate existing data', function () {
81+
it('should mutate existing data', function() {
6782
register.add('/test');
6883
var dataReference = register.getData('/test');
6984
expect(dataReference.test).to.be.true;
70-
register.mutateData('/test', function (data) {
85+
register.mutateData('/test', function(data) {
7186
data.test = false;
7287
});
7388
expect(dataReference).to.be.equal(register.getData('/test'));
7489
expect(dataReference.test).to.be.false;
7590
});
7691

77-
it('should set mtime and reset data if mtime changes', function () {
92+
it('should set mtime and reset data if mtime changes', function() {
7893
register.add('/test');
79-
register.mutateData('/test', function (data) {
94+
register.mutateData('/test', function(data) {
8095
data.test = false;
8196
});
8297
expect(register.getData('/test').test).to.be.false;
@@ -85,7 +100,7 @@ describe('[UNIT] FilesRegister', function () {
85100
register.setMtime('/test', 1000);
86101
expect(register.getMtime('/test')).to.be.equal(1000);
87102
expect(register.getData('/test').test).to.be.true;
88-
register.mutateData('/test', function (data) {
103+
register.mutateData('/test', function(data) {
89104
data.test = false;
90105
});
91106
expect(register.getData('/test').test).to.be.false;

test/unit/FilesWatcher.spec.js

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ var sinon = require('sinon');
66
var expect = require('chai').expect;
77
var mockRequire = require('mock-require');
88

9-
describe('[UNIT] FilesWatcher', function () {
9+
describe('[UNIT] FilesWatcher', function() {
1010
var FilesWatcher;
1111
var watcher;
1212
var watchStub;
1313
var watcherStub;
1414

15-
beforeEach(function () {
15+
beforeEach(function() {
1616
watcherStub = {
1717
on: sinon.stub().returnsThis()
1818
};
@@ -21,24 +21,21 @@ describe('[UNIT] FilesWatcher', function () {
2121
mockRequire('chokidar', { watch: watchStub });
2222
FilesWatcher = mockRequire.reRequire('../../lib/FilesWatcher').FilesWatcher;
2323

24-
watcher = new FilesWatcher(
25-
['/test', '/bar'],
26-
['.ext1', '.ext2']
27-
);
24+
watcher = new FilesWatcher(['/test', '/bar'], ['.ext1', '.ext2']);
2825
});
2926

30-
afterEach(function () {
27+
afterEach(function() {
3128
mockRequire.stopAll();
3229
});
3330

34-
it('should check if file is supported', function () {
31+
it('should check if file is supported', function() {
3532
expect(watcher.isFileSupported('/foo.ext1')).to.be.true;
3633
expect(watcher.isFileSupported('/foo.ext2')).to.be.true;
3734
expect(watcher.isFileSupported('/foo.txt')).to.be.false;
3835
expect(watcher.isFileSupported('/foo.ext1.txt')).to.be.false;
3936
});
4037

41-
it('should check if is watching file', function () {
38+
it('should check if is watching file', function() {
4239
expect(watcher.isWatchingFile('/test/a.ext1')).to.be.false;
4340
expect(watcher.isWatchingFile('/test/a.txt')).to.be.false;
4441
expect(watcher.isWatchingFile('/test')).to.be.false;
@@ -52,18 +49,18 @@ describe('[UNIT] FilesWatcher', function () {
5249
expect(watcher.isWatchingFile('/foo/a.ext1')).to.be.false;
5350
});
5451

55-
it('should check if watcher is watching', function () {
52+
it('should check if watcher is watching', function() {
5653
expect(watcher.isWatching()).to.be.false;
5754
watcher.watch();
5855
expect(watcher.isWatching()).to.be.true;
59-
expect(function () { watcher.watch(); }).to.throw(Error);
56+
expect(function() {
57+
watcher.watch();
58+
}).to.throw(Error);
6059
});
6160

62-
it('should add and remove listeners', function () {
63-
var listenerA = function () {
64-
};
65-
var listenerB = function () {
66-
};
61+
it('should add and remove listeners', function() {
62+
var listenerA = function() {};
63+
var listenerB = function() {};
6764

6865
expect(watcher.listeners).to.be.a('object');
6966
watcher.on('event', listenerA);
@@ -74,19 +71,23 @@ describe('[UNIT] FilesWatcher', function () {
7471
watcher.off('event', listenerA);
7572
expect(watcher.listeners['event']).to.be.deep.equal([listenerB]);
7673

77-
expect(function() { watcher.off('event', listenerA); }).to.not.throw();
74+
expect(function() {
75+
watcher.off('event', listenerA);
76+
}).to.not.throw();
7877
expect(watcher.listeners['event']).to.be.deep.equal([listenerB]);
7978

8079
watcher.off('event', listenerB);
8180
expect(watcher.listeners['event']).to.be.deep.equal([]);
8281

8382
expect(watcher.listeners['foo']).to.be.undefined;
84-
expect(function() { watcher.off('foo', listenerA); }).to.not.throw();
83+
expect(function() {
84+
watcher.off('foo', listenerA);
85+
}).to.not.throw();
8586

8687
expect(watcher.listeners['foo']).to.be.undefined;
8788
});
8889

89-
it('should watch filesystem using chokidar', function () {
90+
it('should watch filesystem using chokidar', function() {
9091
expect(watchStub.called).to.be.false;
9192

9293
var changeListenerA = sinon.spy();
@@ -105,8 +106,12 @@ describe('[UNIT] FilesWatcher', function () {
105106
expect(triggerChange).to.be.a('function');
106107
expect(triggerUnlink).to.be.a('function');
107108

108-
expect(function() { triggerChange('/test/test.ext1', {}); }).to.not.throw();
109-
expect(function() { triggerUnlink('/test/test.ext1', {}); }).to.not.throw();
109+
expect(function() {
110+
triggerChange('/test/test.ext1', {});
111+
}).to.not.throw();
112+
expect(function() {
113+
triggerUnlink('/test/test.ext1', {});
114+
}).to.not.throw();
110115

111116
watcher.on('change', changeListenerA);
112117
watcher.on('change', changeListenerB);
@@ -126,7 +131,6 @@ describe('[UNIT] FilesWatcher', function () {
126131
expect(changeListenerB.called).to.be.true;
127132
expect(changeListenerB.called).to.be.true;
128133

129-
130134
// manually trigger unlink listeners
131135
triggerUnlink('/test/test.txt');
132136
expect(unlinkListenerA.called).to.be.false;

0 commit comments

Comments
 (0)