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

mock-npm.js « fixtures « test « npm « deps - github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: aa8d44020ee361cf1d619d8f7f6e4e7342d67763 (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
// Basic npm fixture that you can give a config object that acts like
// npm.config You still need a separate flatOptions but this is the first step
// to eventually just using npm itself

const realConfig = require('../../lib/utils/config')

const mockLog = {
  clearProgress: () => {},
  disableProgress: () => {},
  enableProgress: () => {},
  http: () => {},
  info: () => {},
  levels: [],
  notice: () => {},
  pause: () => {},
  silly: () => {},
  verbose: () => {},
  warn: () => {},
}
const mockNpm = (base = {}) => {
  const config = base.config || {}
  const flatOptions = base.flatOptions || {}
  return {
    log: mockLog,
    ...base,
    flatOptions,
    config: {
      // for now just set `find` to what config.find should return
      // this works cause `find` is not an existing config entry
      find: (k) => ({...realConfig.defaults, ...config})[k],
      get: (k) => ({...realConfig.defaults, ...config})[k],
      set: (k, v) => config[k] = v,
      list: [{ ...realConfig.defaults, ...config}]
    },
  }
}

module.exports = mockNpm