File: rcfiles.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 (88 lines) | stat: -rw-r--r-- 1,938 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
var fs = require('fs')
var t = require('../')
var spawn = require('child_process').spawn
var node = process.execPath
var run = require.resolve('../bin/run.js')
var os = require('os')

// fake this one in case you have some weird stuff in ~/.taprc
var path = require('path')
process.env.HOME = path.resolve(__dirname, 'fixtures')

var defaults = {
  grep: [],
  grepInvert: false,
  nodeArgs: [],
  nycArgs: [],
  testArgs: [],
  timeout: 30,
  color: false,
  reporter: 'tap',
  files: [],
  bail: false,
  saveFile: null,
  pipeToService: false,
  coverageReport: null,
  browser: true,
  coverage: false,
  checkCoverage: false,
  branches: 0,
  functions: 0,
  jobs: 1,
  lines: 0,
  statements: 0,
  rcFile: os.homedir() + '/.taprc',
  outputFile: null
}

function runTest (rcFile, expect) { return function (t) {
  var env = {
    HOME: process.env.HOME,
    TAP_TIMEOUT: 30
  }

  if (rcFile) {
    env.TAP_RCFILE = rcFile
    expect.rcFile = rcFile
  }

  var child = spawn(node, [ run, '--dump-config' ], { env: env })

  var out = ''
  child.stdout.on('data', function (c) {
    out += c
  })

  child.stderr.pipe(process.stderr)

  t.plan(3)
  child.on('close', function (code, sig) {
    t.equal(code, 0)
    t.equal(sig, null)
    Object.keys(defaults).forEach(function (k) {
      if (!expect.hasOwnProperty(k)) {
        expect[k] = defaults[k]
      }
    })

    t.strictSame(JSON.parse(out), expect)
  })
}}

t.test('parseRcFile', function (t) {
  t.test('nonexistent rc file uses defaults', runTest('./does/not/exist', {}))
  t.test('invalid rc file uses defaults',
         runTest('./test-legacy/fixtures/invalid-rc-file.yml', {}))

  t.test('parses when valid yaml',
    runTest('./test-legacy/fixtures/valid-rc-file.yml', {
      timeout: 9999,
      coverage: false,
      coverageReport: false,
      reporter: 'classic'
    }))

  t.test('uses homedir rcfile when none provided', runTest(null, {}))

  t.end()
})