Skip to content

Commit

Permalink
ci(test): use eslint as ci command and add all js files to check by e…
Browse files Browse the repository at this point in the history
…slint (#410)

no-unused-expressions ignore for tests uses chai expect
  • Loading branch information
anthony-redFox committed Mar 30, 2020
1 parent 1adb27a commit 27822c9
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 68 deletions.
10 changes: 9 additions & 1 deletion .eslintrc
Expand Up @@ -7,5 +7,13 @@
"globals": {
"expect": true,
"sinon": true
}
},
"overrides": [
{
"files": ["test/**/*.js"],
"rules": {
"no-unused-expressions": "off"
}
}
]
}
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -10,4 +10,5 @@ before_script:
- npm install -g grunt-cli

script:
- npm run lint
- grunt
10 changes: 1 addition & 9 deletions gruntfile.js
Expand Up @@ -58,20 +58,12 @@ module.exports = function (grunt) {
coffeeRequireJS: {
configFile: 'examples/coffee-requirejs/karma.conf.coffee'
}
},
eslint: {
target: [
'lib/*.js',
'gruntfile.js',
'karma.conf.js'
]
}
})

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

grunt.registerTask('test', ['simplemocha', 'karma'])
grunt.registerTask('default', ['eslint', 'test'])
grunt.registerTask('default', ['simplemocha', 'karma'])

grunt.registerTask('release', 'Bump the version and publish to NPM.', function (type) {
grunt.task.run([
Expand Down
10 changes: 0 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -4,7 +4,8 @@
"description": "A Karma plugin. Generate code coverage.",
"main": "lib/index.js",
"scripts": {
"test": "grunt test"
"lint": "eslint **/*.js",
"test": "grunt"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -40,7 +41,6 @@
"grunt-cli": "^1.3.2",
"grunt-conventional-changelog": "^6.1.0",
"grunt-conventional-github-releaser": "^1.0.0",
"grunt-eslint": "^22.0.0",
"grunt-karma": "^3.0.2",
"grunt-npm": "^0.0.2",
"grunt-simple-mocha": "^0.4.1",
Expand Down
6 changes: 3 additions & 3 deletions test/in-memory-report.spec.js
@@ -1,17 +1,17 @@
const InMemoryReport = require('../lib/in-memory-report')

describe('InMemoryReport', () => {
const emitter = {emit: sinon.stub()}
const emitter = { emit: sinon.stub() }
const browser = { name: 'firefox' }
const result = { test: { data: 'result' } }
const fc = {
path: 'test',
toJSON: sinon.stub().returns({ data: 'result' })
}
const node = {getFileCoverage: sinon.stub().returns(fc)}
const node = { getFileCoverage: sinon.stub().returns(fc) }

it('should raise an "coverage_complete" event.', () => {
const sut = new InMemoryReport({browser, emitter})
const sut = new InMemoryReport({ browser, emitter })
sut.onStart()
sut.onDetail(node)
sut.onEnd()
Expand Down
24 changes: 15 additions & 9 deletions test/preprocessor.spec.js
Expand Up @@ -22,14 +22,16 @@ describe('preprocessor', () => {
other()
`

const mockLogger = {create: () => {
return {
error: (...arg) => { throw new Error(util.format.apply(util, arg)) },
warn: () => {},
info: () => {},
debug: () => {}
const mockLogger = {
create: () => {
return {
error: (...arg) => { throw new Error(util.format.apply(util, arg)) },
warn: () => {},
info: () => {},
debug: () => {}
}
}
}}
}

// TODO(vojta): refactor this somehow ;-) it's copy pasted from lib/file-list.js
function File (path, mtime) {
Expand Down Expand Up @@ -72,6 +74,7 @@ describe('preprocessor', () => {
instrument (_a, _b, callback) {
callback()
}

lastSourceMap () {}
}
const process = createPreprocessor(mockLogger, '/base/path', ['coverage', 'progress'], {
Expand Down Expand Up @@ -103,9 +106,11 @@ describe('preprocessor', () => {
constructor (options) {
expect(options.experimental).to.be.ok
}

instrument (_a, _b, callback) {
callback()
}

lastSourceMap () {}
}
const process = createPreprocessor(mockLogger, '/base/path', ['coverage', 'progress'], {
Expand All @@ -129,7 +134,7 @@ describe('preprocessor', () => {
})

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

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

it('should fail if invalid instrumenter provided', () => {
const work = () => {
createPreprocessor(mockLogger, '/base/path', ['coverage', 'progress'], {instrumenter: {'**/*.coffee': 'madeup'}})
createPreprocessor(mockLogger, '/base/path', ['coverage', 'progress'], { instrumenter: { '**/*.coffee': 'madeup' } })
}
expect(work).to.throw()
})
Expand Down Expand Up @@ -193,6 +198,7 @@ describe('preprocessor', () => {
instrument (_a, _b, callback) {
callback()
}

lastSourceMap () {}
}

Expand Down
74 changes: 40 additions & 34 deletions test/reporter.spec.js
Expand Up @@ -49,8 +49,8 @@ describe('reporter', () => {
let globalCoverageMapGetStub = null
let reportCreateStub = null

const mockFs = {writeFile: sinon.spy()}
const mocks = {fs: mockFs}
const mockFs = { writeFile: sinon.spy() }
const mocks = { fs: mockFs }

beforeEach(() => {
mockCoverageSummary = {
Expand Down Expand Up @@ -111,19 +111,21 @@ describe('reporter', () => {
let browsers = null
let fakeChrome = null
let fakeOpera = null
const mockLogger = { create: (name) => {
return {
debug () {},
info () {},
warn () {},
error () {}
const mockLogger = {
create: (name) => {
return {
debug () {},
info () {},
warn () {},
error () {}
}
}
}}
}

beforeEach(() => {
rootConfig = {
basePath: '/base',
coverageReporter: {dir: 'path/to/coverage/'}
coverageReporter: { dir: 'path/to/coverage/' }
}
emitter = new events.EventEmitter()
reporter = new m.CoverageReporter(rootConfig, mockHelper, mockLogger, emitter)
Expand Down Expand Up @@ -446,24 +448,26 @@ describe('reporter', () => {

mockCoverageMap.files.returns(['./foo/bar.js', './foo/baz.js'])
mockCoverageSummary.toJSON.returns({
lines: {total: 5, covered: 1, skipped: 0, pct: 20},
statements: {total: 5, covered: 1, skipped: 0, pct: 20},
functions: {total: 5, covered: 1, skipped: 0, pct: 20},
branches: {total: 5, covered: 1, skipped: 0, pct: 20}
lines: { total: 5, covered: 1, skipped: 0, pct: 20 },
statements: { total: 5, covered: 1, skipped: 0, pct: 20 },
functions: { total: 5, covered: 1, skipped: 0, pct: 20 },
branches: { total: 5, covered: 1, skipped: 0, pct: 20 }
})

const spy1 = sinon.spy()

const customLogger = {create: (name) => {
return {
debug () {},
info () {},
warn () {},
error: spy1
const customLogger = {
create: (name) => {
return {
debug () {},
info () {},
warn () {},
error: spy1
}
}
}}
}

const results = {exitCode: 0}
const results = { exitCode: 0 }

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

mockCoverageMap.files.returns(['./foo/bar.js', './foo/baz.js'])
mockCoverageSummary.toJSON.returns({
lines: {total: 5, covered: 1, skipped: 0, pct: 20},
statements: {total: 5, covered: 1, skipped: 0, pct: 20},
functions: {total: 5, covered: 1, skipped: 0, pct: 20},
branches: {total: 5, covered: 1, skipped: 0, pct: 20}
lines: { total: 5, covered: 1, skipped: 0, pct: 20 },
statements: { total: 5, covered: 1, skipped: 0, pct: 20 },
functions: { total: 5, covered: 1, skipped: 0, pct: 20 },
branches: { total: 5, covered: 1, skipped: 0, pct: 20 }
})

const spy1 = sinon.spy()

const customLogger = {create: (name) => {
return {
debug () {},
info () {},
warn () {},
error: spy1
const customLogger = {
create: (name) => {
return {
debug () {},
info () {},
warn () {},
error: spy1
}
}
}}
}

const results = {exitCode: 0}
const results = { exitCode: 0 }

reporter = new m.CoverageReporter(customConfig, mockHelper, customLogger)
reporter.onRunStart()
Expand Down

0 comments on commit 27822c9

Please sign in to comment.