From 9db99178aaee1ddc59878b6b045fe208f694d8c8 Mon Sep 17 00:00:00 2001 From: Michal Dorner Date: Mon, 8 Mar 2021 21:04:14 +0100 Subject: [PATCH] Add mocha-json test case for empty test results --- __tests__/fixtures/empty/mocha-json.json | 16 ++++++++++++++++ __tests__/mocha-json.test.ts | 17 +++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 __tests__/fixtures/empty/mocha-json.json diff --git a/__tests__/fixtures/empty/mocha-json.json b/__tests__/fixtures/empty/mocha-json.json new file mode 100644 index 0000000..31ca60b --- /dev/null +++ b/__tests__/fixtures/empty/mocha-json.json @@ -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": [] +} \ No newline at end of file diff --git a/__tests__/mocha-json.test.ts b/__tests__/mocha-json.test.ts index 893808d..176d1ba 100644 --- a/__tests__/mocha-json.test.ts +++ b/__tests__/mocha-json.test.ts @@ -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')