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

get-workspace-nodes.js « test « arborist « workspaces - github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3de4d73da7b9fffd22db43842844f90653b653d2 (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
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
const t = require('tap')
const getWorkspaceNodes = require('../lib/get-workspace-nodes.js')
const Arborist = require('../lib/arborist/index.js')
const { resolve } = require('path')
const path = resolve(__dirname, './fixtures/workspaces-shared-deps-virtual')

const warningTracker = () => {
  const list = []
  const onlog = (...msg) => msg[0] === 'warn' && list.push(msg)
  process.on('log', onlog)
  return () => {
    process.removeListener('log', onlog)
    return list
  }
}

let tree
t.before(async () => {
  tree = await new Arborist({ path }).loadVirtual()
})

t.test('basic behavior', t => {
  const getLogs = warningTracker()
  const wsNodes = getWorkspaceNodes(tree, ['a'])
  t.equal(wsNodes.length, 1)
  t.equal(wsNodes[0], tree.children.get('a').target)
  t.same(getLogs(), [])
  t.end()
})

t.test('filter set, but no workspaces present', t => {
  const getLogs = warningTracker()
  const wsNodes = getWorkspaceNodes(tree.children.get('b').target, ['xyz'])
  t.same(wsNodes, [])
  t.same(getLogs(), [
    ['warn', 'workspaces', 'filter set, but no workspaces present'],
  ])
  t.end()
})

t.test('name in filter set, but not in workspaces', t => {
  const getLogs = warningTracker()
  const wsNodes = getWorkspaceNodes(tree, ['xyz'])
  t.same(wsNodes, [])
  t.same(getLogs(), [
    ['warn', 'workspaces', 'xyz in filter set, but not in workspaces'],
  ])
  t.end()
})

t.test('name in filter set, but no workspace folder present', t => {
  const getLogs = warningTracker()
  // damage the tree somehow.  Note that the getWorkspaces() function
  // that returns the map already *should* prevent this from happening,
  // but if we start moving things around and make a mistake, it's
  // possible to get there.
  tree.children.get('c').target.root = null
  const wsNodes = getWorkspaceNodes(tree, ['c'])
  t.same(wsNodes, [])
  t.same(getLogs(), [
    ['warn', 'workspaces', 'c in filter set, but no workspace folder present'],
  ])
  t.end()
})