Skip to content

Commit 27822c9

Browse files
authoredMar 30, 2020
ci(test): use eslint as ci command and add all js files to check by eslint (#410)
no-unused-expressions ignore for tests uses chai expect
1 parent 1adb27a commit 27822c9

8 files changed

+71
-68
lines changed
 

‎.eslintrc

+9-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,13 @@
77
"globals": {
88
"expect": true,
99
"sinon": true
10-
}
10+
},
11+
"overrides": [
12+
{
13+
"files": ["test/**/*.js"],
14+
"rules": {
15+
"no-unused-expressions": "off"
16+
}
17+
}
18+
]
1119
}

‎.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ before_script:
1010
- npm install -g grunt-cli
1111

1212
script:
13+
- npm run lint
1314
- grunt

‎gruntfile.js

+1-9
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,12 @@ module.exports = function (grunt) {
5858
coffeeRequireJS: {
5959
configFile: 'examples/coffee-requirejs/karma.conf.coffee'
6060
}
61-
},
62-
eslint: {
63-
target: [
64-
'lib/*.js',
65-
'gruntfile.js',
66-
'karma.conf.js'
67-
]
6861
}
6962
})
7063

7164
require('load-grunt-tasks')(grunt)
7265

73-
grunt.registerTask('test', ['simplemocha', 'karma'])
74-
grunt.registerTask('default', ['eslint', 'test'])
66+
grunt.registerTask('default', ['simplemocha', 'karma'])
7567

7668
grunt.registerTask('release', 'Bump the version and publish to NPM.', function (type) {
7769
grunt.task.run([

‎package-lock.json

-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"description": "A Karma plugin. Generate code coverage.",
55
"main": "lib/index.js",
66
"scripts": {
7-
"test": "grunt test"
7+
"lint": "eslint **/*.js",
8+
"test": "grunt"
89
},
910
"repository": {
1011
"type": "git",
@@ -40,7 +41,6 @@
4041
"grunt-cli": "^1.3.2",
4142
"grunt-conventional-changelog": "^6.1.0",
4243
"grunt-conventional-github-releaser": "^1.0.0",
43-
"grunt-eslint": "^22.0.0",
4444
"grunt-karma": "^3.0.2",
4545
"grunt-npm": "^0.0.2",
4646
"grunt-simple-mocha": "^0.4.1",

‎test/in-memory-report.spec.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
const InMemoryReport = require('../lib/in-memory-report')
22

33
describe('InMemoryReport', () => {
4-
const emitter = {emit: sinon.stub()}
4+
const emitter = { emit: sinon.stub() }
55
const browser = { name: 'firefox' }
66
const result = { test: { data: 'result' } }
77
const fc = {
88
path: 'test',
99
toJSON: sinon.stub().returns({ data: 'result' })
1010
}
11-
const node = {getFileCoverage: sinon.stub().returns(fc)}
11+
const node = { getFileCoverage: sinon.stub().returns(fc) }
1212

1313
it('should raise an "coverage_complete" event.', () => {
14-
const sut = new InMemoryReport({browser, emitter})
14+
const sut = new InMemoryReport({ browser, emitter })
1515
sut.onStart()
1616
sut.onDetail(node)
1717
sut.onEnd()

‎test/preprocessor.spec.js

+15-9
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,16 @@ describe('preprocessor', () => {
2222
other()
2323
`
2424

25-
const mockLogger = {create: () => {
26-
return {
27-
error: (...arg) => { throw new Error(util.format.apply(util, arg)) },
28-
warn: () => {},
29-
info: () => {},
30-
debug: () => {}
25+
const mockLogger = {
26+
create: () => {
27+
return {
28+
error: (...arg) => { throw new Error(util.format.apply(util, arg)) },
29+
warn: () => {},
30+
info: () => {},
31+
debug: () => {}
32+
}
3133
}
32-
}}
34+
}
3335

3436
// TODO(vojta): refactor this somehow ;-) it's copy pasted from lib/file-list.js
3537
function File (path, mtime) {
@@ -72,6 +74,7 @@ describe('preprocessor', () => {
7274
instrument (_a, _b, callback) {
7375
callback()
7476
}
77+
7578
lastSourceMap () {}
7679
}
7780
const process = createPreprocessor(mockLogger, '/base/path', ['coverage', 'progress'], {
@@ -103,9 +106,11 @@ describe('preprocessor', () => {
103106
constructor (options) {
104107
expect(options.experimental).to.be.ok
105108
}
109+
106110
instrument (_a, _b, callback) {
107111
callback()
108112
}
113+
109114
lastSourceMap () {}
110115
}
111116
const process = createPreprocessor(mockLogger, '/base/path', ['coverage', 'progress'], {
@@ -129,7 +134,7 @@ describe('preprocessor', () => {
129134
})
130135

131136
it('should not preprocess the coffee code', (done) => {
132-
const process = createPreprocessor(mockLogger, '/base/path', ['coverage', 'progress'], {instrumenter: {'**/*.coffee': 'istanbul'}})
137+
const process = createPreprocessor(mockLogger, '/base/path', ['coverage', 'progress'], { instrumenter: { '**/*.coffee': 'istanbul' } })
133138
const file = new File('/base/path/file.coffee')
134139

135140
process(ORIGINAL_CODE, file, (preprocessedCode) => {
@@ -147,7 +152,7 @@ describe('preprocessor', () => {
147152

148153
it('should fail if invalid instrumenter provided', () => {
149154
const work = () => {
150-
createPreprocessor(mockLogger, '/base/path', ['coverage', 'progress'], {instrumenter: {'**/*.coffee': 'madeup'}})
155+
createPreprocessor(mockLogger, '/base/path', ['coverage', 'progress'], { instrumenter: { '**/*.coffee': 'madeup' } })
151156
}
152157
expect(work).to.throw()
153158
})
@@ -193,6 +198,7 @@ describe('preprocessor', () => {
193198
instrument (_a, _b, callback) {
194199
callback()
195200
}
201+
196202
lastSourceMap () {}
197203
}
198204

‎test/reporter.spec.js

+40-34
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ describe('reporter', () => {
4949
let globalCoverageMapGetStub = null
5050
let reportCreateStub = null
5151

52-
const mockFs = {writeFile: sinon.spy()}
53-
const mocks = {fs: mockFs}
52+
const mockFs = { writeFile: sinon.spy() }
53+
const mocks = { fs: mockFs }
5454

5555
beforeEach(() => {
5656
mockCoverageSummary = {
@@ -111,19 +111,21 @@ describe('reporter', () => {
111111
let browsers = null
112112
let fakeChrome = null
113113
let fakeOpera = null
114-
const mockLogger = { create: (name) => {
115-
return {
116-
debug () {},
117-
info () {},
118-
warn () {},
119-
error () {}
114+
const mockLogger = {
115+
create: (name) => {
116+
return {
117+
debug () {},
118+
info () {},
119+
warn () {},
120+
error () {}
121+
}
120122
}
121-
}}
123+
}
122124

123125
beforeEach(() => {
124126
rootConfig = {
125127
basePath: '/base',
126-
coverageReporter: {dir: 'path/to/coverage/'}
128+
coverageReporter: { dir: 'path/to/coverage/' }
127129
}
128130
emitter = new events.EventEmitter()
129131
reporter = new m.CoverageReporter(rootConfig, mockHelper, mockLogger, emitter)
@@ -446,24 +448,26 @@ describe('reporter', () => {
446448

447449
mockCoverageMap.files.returns(['./foo/bar.js', './foo/baz.js'])
448450
mockCoverageSummary.toJSON.returns({
449-
lines: {total: 5, covered: 1, skipped: 0, pct: 20},
450-
statements: {total: 5, covered: 1, skipped: 0, pct: 20},
451-
functions: {total: 5, covered: 1, skipped: 0, pct: 20},
452-
branches: {total: 5, covered: 1, skipped: 0, pct: 20}
451+
lines: { total: 5, covered: 1, skipped: 0, pct: 20 },
452+
statements: { total: 5, covered: 1, skipped: 0, pct: 20 },
453+
functions: { total: 5, covered: 1, skipped: 0, pct: 20 },
454+
branches: { total: 5, covered: 1, skipped: 0, pct: 20 }
453455
})
454456

455457
const spy1 = sinon.spy()
456458

457-
const customLogger = {create: (name) => {
458-
return {
459-
debug () {},
460-
info () {},
461-
warn () {},
462-
error: spy1
459+
const customLogger = {
460+
create: (name) => {
461+
return {
462+
debug () {},
463+
info () {},
464+
warn () {},
465+
error: spy1
466+
}
463467
}
464-
}}
468+
}
465469

466-
const results = {exitCode: 0}
470+
const results = { exitCode: 0 }
467471

468472
reporter = new m.CoverageReporter(customConfig, mockHelper, customLogger)
469473
reporter.onRunStart()
@@ -487,24 +491,26 @@ describe('reporter', () => {
487491

488492
mockCoverageMap.files.returns(['./foo/bar.js', './foo/baz.js'])
489493
mockCoverageSummary.toJSON.returns({
490-
lines: {total: 5, covered: 1, skipped: 0, pct: 20},
491-
statements: {total: 5, covered: 1, skipped: 0, pct: 20},
492-
functions: {total: 5, covered: 1, skipped: 0, pct: 20},
493-
branches: {total: 5, covered: 1, skipped: 0, pct: 20}
494+
lines: { total: 5, covered: 1, skipped: 0, pct: 20 },
495+
statements: { total: 5, covered: 1, skipped: 0, pct: 20 },
496+
functions: { total: 5, covered: 1, skipped: 0, pct: 20 },
497+
branches: { total: 5, covered: 1, skipped: 0, pct: 20 }
494498
})
495499

496500
const spy1 = sinon.spy()
497501

498-
const customLogger = {create: (name) => {
499-
return {
500-
debug () {},
501-
info () {},
502-
warn () {},
503-
error: spy1
502+
const customLogger = {
503+
create: (name) => {
504+
return {
505+
debug () {},
506+
info () {},
507+
warn () {},
508+
error: spy1
509+
}
504510
}
505-
}}
511+
}
506512

507-
const results = {exitCode: 0}
513+
const results = { exitCode: 0 }
508514

509515
reporter = new m.CoverageReporter(customConfig, mockHelper, customLogger)
510516
reporter.onRunStart()

0 commit comments

Comments
 (0)
Please sign in to comment.