feat: add fund workspaces · npm/cli@370b36a (original) (raw)
``
1
`+
const { resolve } = require('path')
`
``
2
`+
const t = require('tap')
`
``
3
`+
const ArboristCmd = require('../../../lib/workspaces/arborist-cmd.js')
`
``
4
+
``
5
`+
t.test('arborist-cmd', async t => {
`
``
6
`+
const path = t.testdir({
`
``
7
`+
'package.json': JSON.stringify({
`
``
8
`+
name: 'simple-workspaces-list',
`
``
9
`+
version: '1.1.1',
`
``
10
`+
workspaces: [
`
``
11
`+
'a',
`
``
12
`+
'b',
`
``
13
`+
'group/*',
`
``
14
`+
],
`
``
15
`+
}),
`
``
16
`+
node_modules: {
`
``
17
`+
abbrev: {
`
``
18
`+
'package.json': JSON.stringify({ name: 'abbrev', version: '1.1.1' }),
`
``
19
`+
},
`
``
20
`+
a: t.fixture('symlink', '../a'),
`
``
21
`+
b: t.fixture('symlink', '../b'),
`
``
22
`+
},
`
``
23
`+
a: {
`
``
24
`+
'package.json': JSON.stringify({ name: 'a', version: '1.0.0' }),
`
``
25
`+
},
`
``
26
`+
b: {
`
``
27
`+
'package.json': JSON.stringify({ name: 'b', version: '1.0.0' }),
`
``
28
`+
},
`
``
29
`+
group: {
`
``
30
`+
c: {
`
``
31
`+
'package.json': JSON.stringify({
`
``
32
`+
name: 'c',
`
``
33
`+
version: '1.0.0',
`
``
34
`+
dependencies: {
`
``
35
`+
abbrev: '^1.1.1',
`
``
36
`+
},
`
``
37
`+
}),
`
``
38
`+
},
`
``
39
`+
d: {
`
``
40
`+
'package.json': JSON.stringify({ name: 'd', version: '1.0.0' }),
`
``
41
`+
},
`
``
42
`+
},
`
``
43
`+
})
`
``
44
+
``
45
`+
class TestCmd extends ArboristCmd {}
`
``
46
+
``
47
`+
const cmd = new TestCmd()
`
``
48
`+
cmd.npm = { localPrefix: path }
`
``
49
+
``
50
`+
// check filtering for a single workspace name
`
``
51
`+
cmd.exec = function (args, cb) {
`
``
52
`+
t.same(this.workspaces, ['a'], 'should set array with single ws name')
`
``
53
`+
t.same(args, ['foo'], 'should get received args')
`
``
54
`+
cb()
`
``
55
`+
}
`
``
56
`+
await new Promise(res => {
`
``
57
`+
cmd.execWorkspaces(['foo'], ['a'], res)
`
``
58
`+
})
`
``
59
+
``
60
`+
// check filtering single workspace by path
`
``
61
`+
cmd.exec = function (args, cb) {
`
``
62
`+
t.same(this.workspaces, ['a'],
`
``
63
`+
'should set array with single ws name from path')
`
``
64
`+
cb()
`
``
65
`+
}
`
``
66
`+
await new Promise(res => {
`
``
67
`+
cmd.execWorkspaces([], ['./a'], res)
`
``
68
`+
})
`
``
69
+
``
70
`+
// check filtering single workspace by full path
`
``
71
`+
cmd.exec = function (args, cb) {
`
``
72
`+
t.same(this.workspaces, ['a'],
`
``
73
`+
'should set array with single ws name from full path')
`
``
74
`+
cb()
`
``
75
`+
}
`
``
76
`+
await new Promise(res => {
`
``
77
`+
cmd.execWorkspaces([], [resolve(path, './a')], res)
`
``
78
`+
})
`
``
79
+
``
80
`+
// filtering multiple workspaces by name
`
``
81
`+
cmd.exec = function (args, cb) {
`
``
82
`+
t.same(this.workspaces, ['a', 'c'],
`
``
83
`+
'should set array with multiple listed ws names')
`
``
84
`+
cb()
`
``
85
`+
}
`
``
86
`+
await new Promise(res => {
`
``
87
`+
cmd.execWorkspaces([], ['a', 'c'], res)
`
``
88
`+
})
`
``
89
+
``
90
`+
// filtering multiple workspaces by path names
`
``
91
`+
cmd.exec = function (args, cb) {
`
``
92
`+
t.same(this.workspaces, ['a', 'c'],
`
``
93
`+
'should set array with multiple ws names from paths')
`
``
94
`+
cb()
`
``
95
`+
}
`
``
96
`+
await new Promise(res => {
`
``
97
`+
cmd.execWorkspaces([], ['./a', 'group/c'], res)
`
``
98
`+
})
`
``
99
+
``
100
`+
// filtering multiple workspaces by parent path name
`
``
101
`+
cmd.exec = function (args, cb) {
`
``
102
`+
t.same(this.workspaces, ['c', 'd'],
`
``
103
`+
'should set array with multiple ws names from a parent folder name')
`
``
104
`+
cb()
`
``
105
`+
}
`
``
106
`+
await new Promise(res => {
`
``
107
`+
cmd.execWorkspaces([], ['./group'], res)
`
``
108
`+
})
`
``
109
`+
})
`