Skip to content

Commit 83bafc3

Browse files
refactor: replace migrate coffee unit tests to modern JS (#407)
1 parent 49f174d commit 83bafc3

18 files changed

Lines changed: 906 additions & 790 deletions

.eslintrc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
{
2-
"extends": "standard"
2+
"extends": "standard",
3+
"env": {
4+
"node": true,
5+
"mocha": true
6+
},
7+
"globals": {
8+
"expect": true,
9+
"sinon": true
10+
}
311
}

gruntfile.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ module.exports = function (grunt) {
88
},
99
unit: {
1010
src: [
11-
'test/mocha-globals.coffee',
12-
'test/*.spec.coffee'
11+
'test/mocha-globals.js',
12+
'test/*.spec.js'
1313
]
1414
}
1515
},

test/coverage-map.spec.coffee

Lines changed: 0 additions & 28 deletions
This file was deleted.

test/coverage-map.spec.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const coverageMap = require('../lib/coverage-map')
2+
const coverageObj = { path: './path.js', otherThings: 'that are in instrumented code' }
3+
4+
describe('coverageMap', () => {
5+
it('should add coverageMap and get them', () => {
6+
coverageMap.add(coverageObj)
7+
expect(coverageMap.get()['./path.js']).to.equal(coverageObj)
8+
})
9+
10+
it('should be able to be reset', () => {
11+
coverageMap.reset()
12+
13+
expect(coverageMap.get()['./path.js']).to.not.exist
14+
15+
coverageMap.add(coverageObj)
16+
17+
expect(coverageMap.get()['./path.js']).to.equal(coverageObj)
18+
19+
coverageMap.reset()
20+
21+
expect(coverageMap.get()['./path.js']).to.not.exist
22+
})
23+
24+
it('should be able to have multiple coverageMap', () => {
25+
coverageMap.reset()
26+
coverageMap.add(coverageObj)
27+
coverageMap.add({ path: './anotherFile.js', moarKeys: [1, 2, 3] })
28+
29+
expect(Object.keys(coverageMap.get()).length).to.equal(2)
30+
})
31+
})

test/in-memory-report.spec.coffee

Lines changed: 0 additions & 28 deletions
This file was deleted.

test/in-memory-report.spec.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const InMemoryReport = require('../lib/in-memory-report')
2+
3+
describe('InMemoryReport', () => {
4+
const emitter = {emit: sinon.stub()}
5+
const browser = { name: 'firefox' }
6+
const result = { test: { data: 'result' } }
7+
const fc = {
8+
path: 'test',
9+
toJSON: sinon.stub().returns({ data: 'result' })
10+
}
11+
const node = {getFileCoverage: sinon.stub().returns(fc)}
12+
13+
it('should raise an "coverage_complete" event.', () => {
14+
const sut = new InMemoryReport({browser, emitter})
15+
sut.onStart()
16+
sut.onDetail(node)
17+
sut.onEnd()
18+
expect(node.getFileCoverage).to.have.been.called
19+
expect(fc.toJSON).to.have.been.called
20+
expect(emitter.emit).to.have.been.calledWith('coverage_complete', browser, result)
21+
})
22+
23+
it('should be of type "in-memory"', () =>
24+
expect(InMemoryReport.TYPE).to.be.equal('in-memory')
25+
)
26+
27+
it('should not fail when created without arguments', () =>
28+
expect(new InMemoryReport()).to.be.ok
29+
)
30+
})

test/index.spec.coffee

Lines changed: 0 additions & 7 deletions
This file was deleted.

test/index.spec.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
require('../lib/index')
2+
const InMemoryReport = require('../lib/in-memory-report')
3+
const reportCreator = require('../lib/report-creator')
4+
5+
describe('Index', () => {
6+
it('should register "InMemoryReport" to Report Creator', () =>
7+
expect(reportCreator.create('in-memory', {})).to.be.an.instanceof(InMemoryReport)
8+
)
9+
})

test/mocha-globals.coffee

Lines changed: 0 additions & 13 deletions
This file was deleted.

test/mocha-globals.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const sinon = require('sinon')
2+
const chai = require('chai')
3+
4+
// publish globals that all specs can use
5+
global.expect = chai.expect
6+
global.should = chai.should()
7+
global.sinon = sinon
8+
9+
// chai plugins
10+
chai.use(require('sinon-chai'))
11+
12+
afterEach(() => global.sinon.restore())

0 commit comments

Comments
 (0)