This repository has been archived by the owner on Feb 26, 2021. It is now read-only.
forked from coverage-report/clover-json
/
index.test.ts
59 lines (51 loc) · 2.21 KB
/
index.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* eslint-disable no-magic-numbers */
import { parseFile } from '../src';
import path from 'path';
const getFilePath = (file: string): string => path.join(__dirname, 'assets', file);
describe('Check if it can parse a clover file', () => {
it('should parse a normal file', async() => {
const result = await parseFile(getFilePath('clover1.xml'));
expect(result.length).toBe(3);
expect(result[0].file).toBe('coveralls/lib/client.js');
expect(result[1].file).toBe('coveralls/lib/configuration.js');
expect(result[2].file).toBe('coveralls/lib/git_commit.js');
expect(result[0].functions.found).toBe(1);
expect(result[0].functions.hit).toBe(1);
expect(result[0].lines.found).toBe(4);
expect(result[0].lines.hit).toBe(4);
expect(result[0].functions.details[0].line).toBe(5);
expect(result[0].functions.details[0].hit).toBe(2);
expect(result[0].lines.details[0].line).toBe(6);
expect(result[0].lines.details[0].hit).toBe(2);
});
it('should parse a second file', async() => {
const result = await parseFile(getFilePath('clover2.xml'));
expect(result.length).toBe(1);
expect(result[0].functions.found).toBe(2);
expect(result[0].functions.hit).toBe(1);
expect(result[0].lines.found).toBe(4);
expect(result[0].lines.hit).toBe(1);
});
it('should parse a file with an empty class', async() => {
const result = await parseFile(getFilePath('clover-empty.xml'));
expect(result.length).toBe(1);
expect(result[0].functions.found).toBe(0);
expect(result[0].functions.hit).toBe(0);
expect(result[0].lines.found).toBe(0);
expect(result[0].lines.hit).toBe(0);
});
it('should parse a file without a package property', async() => {
const result = await parseFile(getFilePath('clover-without-package.xml'));
expect(result.length).toBe(4);
expect(result[0].functions.found).toBe(0);
expect(result[0].functions.hit).toBe(0);
expect(result[0].lines.found).toBe(1);
expect(result[0].lines.hit).toBe(1);
});
it('should throw error if file not exists', async() => {
await expect(parseFile(getFilePath('test'))).rejects.toThrow('no such file or directory');
});
it('should throw error if file is invalid', async() => {
await expect(parseFile(getFilePath('error.xml'))).rejects.toThrow('Unexpected end');
});
});