forked from tlvince/make-coverage-badge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
executable file
·42 lines (36 loc) · 932 Bytes
/
test.js
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
#!/usr/bin/env node
const assert = require('assert')
const { exec } = require('child_process')
const { promisify } = require('util')
const { mkdir, rmdir, unlink, readFile, writeFile } = require('fs').promises
const execP = promisify(exec)
const setup = async () => {
await mkdir('./coverage')
const report = {
total: {
statements: {
pct: 90,
},
},
}
const json = JSON.stringify(report)
await writeFile('./coverage/coverage-summary.json', json)
}
const teardown = async () => {
await unlink('./coverage/coverage-summary.json')
await unlink('./coverage/badge.svg')
await rmdir('./coverage')
}
const test = async () => {
await execP('./cli.js')
const buffer = await readFile('./coverage/badge.svg')
const badge = buffer.toString()
assert.ok(badge.includes('90%'))
}
setup()
.then(test)
.then(teardown)
.catch(error => {
console.error(error)
process.exit(1)
})