forked from expr-lang/expr
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcoverage.mjs
More file actions
executable file
·39 lines (35 loc) · 1.44 KB
/
coverage.mjs
File metadata and controls
executable file
·39 lines (35 loc) · 1.44 KB
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
#!/usr/bin/env zx
const expected = 90
const exclude = [
'expr/test', // We do not need to test the test package.
'checker/mock', // Mocks only used for testing.
'vm/func_types', // Generated files.
'vm/runtime/helpers', // Generated files.
'internal/difflib', // Test dependency. This is vendored dependency, and ideally we also have good tests for it.
'internal/spew', // Test dependency.
'internal/testify', // Test dependency.
'patcher/value', // Contains a lot of repeating code. Ideally we should have a test for it.
'pro', // Expr Pro is not a part of the main codebase.
]
cd(path.resolve(__dirname, '..', '..'))
await spinner('Running tests', async () => {
await $`go test -coverprofile=coverage.out -coverpkg=github.com/expr-lang/expr/... ./...`
const coverage = fs.readFileSync('coverage.out').toString()
.split('\n')
.filter(line => {
for (const ex of exclude)
if (line.includes(ex)) return false
return true
})
.join('\n')
fs.writeFileSync('coverage.out', coverage)
await $`go tool cover -html=coverage.out -o coverage.html`
})
const cover = await $({verbose: true})`go tool cover -func=coverage.out`
const total = +cover.stdout.match(/total:\s+\(statements\)\s+(\d+\.\d+)%/)[1]
if (total < expected) {
echo(chalk.red(`Coverage is too low: ${total}% < ${expected}% (expected)`))
process.exit(1)
} else {
echo(`Coverage is good: ${chalk.green(total + '%')} >= ${expected}% (expected)`)
}