Welcome to mirror list, hosted at ThFree Co, Russian Federation.

test.js « lib « test « npm « deps - github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c151b1e825343ff9dbf5c979019f890518758927 (plain)
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
const t = require('tap')
let RUN_ARGS = null
const npm = {
  commands: {
    'run-script': (args, cb) => {
      RUN_ARGS = args
      cb()
    },
  },
}
const Test = require('../../lib/test.js')
const test = new Test(npm)

t.test('run a test', t => {
  test.exec([], (er) => {
    t.strictSame(RUN_ARGS, ['test'], 'added "test" to the args')
  })
  test.exec(['hello', 'world'], (er) => {
    t.strictSame(RUN_ARGS, ['test', 'hello', 'world'], 'added positional args')
  })

  const lcErr = Object.assign(new Error('should not see this'), {
    code: 'ELIFECYCLE',
  })
  const otherErr = new Error('should see this')

  npm.commands['run-script'] = (args, cb) => cb(lcErr)
  test.exec([], (er) => {
    t.equal(er, 'Test failed.  See above for more details.')
  })

  npm.commands['run-script'] = (args, cb) => cb(otherErr)
  test.exec([], (er) => {
    t.match(er, { message: 'should see this' })
  })

  t.end()
})