Skip to content

Commit

Permalink
Add mocha-json test case for empty test results
Browse files Browse the repository at this point in the history
  • Loading branch information
Michal Dorner committed Mar 8, 2021
1 parent 3768e4e commit 9db9917
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
16 changes: 16 additions & 0 deletions __tests__/fixtures/empty/mocha-json.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"stats": {
"suites": 0,
"tests": 0,
"passes": 0,
"pending": 0,
"failures": 0,
"start": "2021-03-08T20:01:44.391Z",
"end": "2021-03-08T20:01:44.391Z",
"duration": 0
},
"tests": [],
"pending": [],
"failures": [],
"passes": []
}
17 changes: 17 additions & 0 deletions __tests__/mocha-json.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,23 @@ import {getReport} from '../src/report/get-report'
import {normalizeFilePath} from '../src/utils/path-utils'

describe('mocha-json tests', () => {

it('produces empty test run result when there are no test cases', async () => {
const fixturePath = path.join(__dirname, 'fixtures', 'empty', 'mocha-json.json')
const filePath = normalizeFilePath(path.relative(__dirname, fixturePath))
const fileContent = fs.readFileSync(fixturePath, {encoding: 'utf8'})

const opts: ParseOptions = {
parseErrors: true,
trackedFiles: []
}

const parser = new MochaJsonParser(opts)
const result = await parser.parse(filePath, fileContent)
expect(result.tests).toBe(0)
expect(result.result).toBe('success')
})

it('report from ./reports/mocha-json test results matches snapshot', async () => {
const fixturePath = path.join(__dirname, 'fixtures', 'mocha-json.json')
const outputPath = path.join(__dirname, '__outputs__', 'mocha-json.md')
Expand Down

0 comments on commit 9db9917

Please sign in to comment.