File: coverage-export.js

package info (click to toggle)
node-tap 12.0.1+ds-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 3,916 kB
  • sloc: makefile: 84; sh: 75
file content (57 lines) | stat: -rw-r--r-- 1,402 bytes parent folder | download | duplicates (2)
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
'use strict'

var t = require('../')
var spawn = require('child_process').spawn
var node = process.execPath
var run = require.resolve('../bin/run.js')
var ok = require.resolve('./test/ok.js')
var testRe = /COVERAGE_SERVICE_TEST/

process.exit()

t.test('generate some coverage data', function (tt) {
  spawn(node, [run, ok, '--coverage'], {
    stdio: 'ignore'
  }).on('close', function (code, signal) {
    tt.equal(code, 0)
    tt.equal(signal, null)
    tt.end()
  })
})

t.test('no coverage export when no tokens in env', function (tt) {
  doTest(tt, {}, function (actual) {
    tt.notMatch(actual, /Coveralls:coveralls_token\n/)
    tt.end()
  })
})

t.test('coverage to Coveralls', function (tt) {
  var env = {
    COVERALLS_REPO_TOKEN: 'coveralls_token'
  }
  doTest(tt, env, function (actual) {
    tt.match(actual, /Coveralls:coveralls_token\n/)
    tt.end()
  })
})

function doTest (tt, env, cb) {
  var args = [ run, '--no-coverage', '--coverage-report=text-lcov' ]
  env.COVERAGE_SERVICE_TEST = 'true'
  var output = ''
  var child = spawn(node, args, {
    stdio: [0, 'pipe', 2],
    env: env
  })
  child.stdout.setEncoding('utf-8')
  child.stdout.on('data', function (data) {
    output += data
  })
  child.on('close', function (code, signal) {
    tt.equal(code, 0)
    tt.equal(signal, null)
    tt.match(output, testRe)
    cb(output.toString().split('FN:27,parseArgs')[0])
  })
}