Skip to content

Commit

Permalink
refactor: replace migrate coffee unit tests to modern JS (#407)
Browse files Browse the repository at this point in the history
  • Loading branch information
anthony-redFox committed Mar 23, 2020
1 parent 49f174d commit 83bafc3
Show file tree
Hide file tree
Showing 18 changed files with 906 additions and 790 deletions.
10 changes: 9 additions & 1 deletion .eslintrc
@@ -1,3 +1,11 @@
{
"extends": "standard"
"extends": "standard",
"env": {
"node": true,
"mocha": true
},
"globals": {
"expect": true,
"sinon": true
}
}
4 changes: 2 additions & 2 deletions gruntfile.js
Expand Up @@ -8,8 +8,8 @@ module.exports = function (grunt) {
},
unit: {
src: [
'test/mocha-globals.coffee',
'test/*.spec.coffee'
'test/mocha-globals.js',
'test/*.spec.js'
]
}
},
Expand Down
28 changes: 0 additions & 28 deletions test/coverage-map.spec.coffee

This file was deleted.

31 changes: 31 additions & 0 deletions test/coverage-map.spec.js
@@ -0,0 +1,31 @@
const coverageMap = require('../lib/coverage-map')
const coverageObj = { path: './path.js', otherThings: 'that are in instrumented code' }

describe('coverageMap', () => {
it('should add coverageMap and get them', () => {
coverageMap.add(coverageObj)
expect(coverageMap.get()['./path.js']).to.equal(coverageObj)
})

it('should be able to be reset', () => {
coverageMap.reset()

expect(coverageMap.get()['./path.js']).to.not.exist

coverageMap.add(coverageObj)

expect(coverageMap.get()['./path.js']).to.equal(coverageObj)

coverageMap.reset()

expect(coverageMap.get()['./path.js']).to.not.exist
})

it('should be able to have multiple coverageMap', () => {
coverageMap.reset()
coverageMap.add(coverageObj)
coverageMap.add({ path: './anotherFile.js', moarKeys: [1, 2, 3] })

expect(Object.keys(coverageMap.get()).length).to.equal(2)
})
})
28 changes: 0 additions & 28 deletions test/in-memory-report.spec.coffee

This file was deleted.

30 changes: 30 additions & 0 deletions test/in-memory-report.spec.js
@@ -0,0 +1,30 @@
const InMemoryReport = require('../lib/in-memory-report')

describe('InMemoryReport', () => {
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)}

it('should raise an "coverage_complete" event.', () => {
const sut = new InMemoryReport({browser, emitter})
sut.onStart()
sut.onDetail(node)
sut.onEnd()
expect(node.getFileCoverage).to.have.been.called
expect(fc.toJSON).to.have.been.called
expect(emitter.emit).to.have.been.calledWith('coverage_complete', browser, result)
})

it('should be of type "in-memory"', () =>
expect(InMemoryReport.TYPE).to.be.equal('in-memory')
)

it('should not fail when created without arguments', () =>
expect(new InMemoryReport()).to.be.ok
)
})
7 changes: 0 additions & 7 deletions test/index.spec.coffee

This file was deleted.

9 changes: 9 additions & 0 deletions test/index.spec.js
@@ -0,0 +1,9 @@
require('../lib/index')
const InMemoryReport = require('../lib/in-memory-report')
const reportCreator = require('../lib/report-creator')

describe('Index', () => {
it('should register "InMemoryReport" to Report Creator', () =>
expect(reportCreator.create('in-memory', {})).to.be.an.instanceof(InMemoryReport)
)
})
13 changes: 0 additions & 13 deletions test/mocha-globals.coffee

This file was deleted.

12 changes: 12 additions & 0 deletions test/mocha-globals.js
@@ -0,0 +1,12 @@
const sinon = require('sinon')
const chai = require('chai')

// publish globals that all specs can use
global.expect = chai.expect
global.should = chai.should()
global.sinon = sinon

// chai plugins
chai.use(require('sinon-chai'))

afterEach(() => global.sinon.restore())
190 changes: 0 additions & 190 deletions test/preprocessor.spec.coffee

This file was deleted.

0 comments on commit 83bafc3

Please sign in to comment.