• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1const t = require('tap')
2const mockGlobals = require('@npmcli/mock-globals')
3const tmock = require('../../fixtures/tmock')
4
5const mockValidateEngines = (t) => {
6  const validateEngines = tmock(t, '{LIB}/es6/validate-engines.js', {
7    '{ROOT}/package.json': { version: '1.2.3', engines: { node: '>=0' } },
8  })
9  mockGlobals(t, { 'process.version': 'v4.5.6' })
10  return validateEngines(process, () => (_, r) => r)
11}
12
13t.test('validate engines', async t => {
14  t.equal(process.listenerCount('uncaughtException'), 0)
15  t.equal(process.listenerCount('unhandledRejection'), 0)
16
17  const result = mockValidateEngines(t)
18
19  t.equal(process.listenerCount('uncaughtException'), 1)
20  t.equal(process.listenerCount('unhandledRejection'), 1)
21
22  t.match(result, {
23    node: 'v4.5.6',
24    npm: 'v1.2.3',
25    engines: '>=0',
26    /* eslint-disable-next-line max-len */
27    unsupportedMessage: 'npm v1.2.3 does not support Node.js v4.5.6. This version of npm supports the following node versions: `>=0`. You can find the latest version at https://nodejs.org/.',
28  })
29
30  result.off()
31
32  t.equal(process.listenerCount('uncaughtException'), 0)
33  t.equal(process.listenerCount('unhandledRejection'), 0)
34})
35