/
arborist-cmd.js
109 lines (100 loc) · 2.81 KB
/
arborist-cmd.js
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
const { resolve } = require('path')
const t = require('tap')
const ArboristCmd = require('../../../lib/workspaces/arborist-cmd.js')
t.test('arborist-cmd', async t => {
const path = t.testdir({
'package.json': JSON.stringify({
name: 'simple-workspaces-list',
version: '1.1.1',
workspaces: [
'a',
'b',
'group/*',
],
}),
node_modules: {
abbrev: {
'package.json': JSON.stringify({ name: 'abbrev', version: '1.1.1' }),
},
a: t.fixture('symlink', '../a'),
b: t.fixture('symlink', '../b'),
},
a: {
'package.json': JSON.stringify({ name: 'a', version: '1.0.0' }),
},
b: {
'package.json': JSON.stringify({ name: 'b', version: '1.0.0' }),
},
group: {
c: {
'package.json': JSON.stringify({
name: 'c',
version: '1.0.0',
dependencies: {
abbrev: '^1.1.1',
},
}),
},
d: {
'package.json': JSON.stringify({ name: 'd', version: '1.0.0' }),
},
},
})
class TestCmd extends ArboristCmd {}
const cmd = new TestCmd()
cmd.npm = { localPrefix: path }
// check filtering for a single workspace name
cmd.exec = function (args, cb) {
t.same(this.workspaces, ['a'], 'should set array with single ws name')
t.same(args, ['foo'], 'should get received args')
cb()
}
await new Promise(res => {
cmd.execWorkspaces(['foo'], ['a'], res)
})
// check filtering single workspace by path
cmd.exec = function (args, cb) {
t.same(this.workspaces, ['a'],
'should set array with single ws name from path')
cb()
}
await new Promise(res => {
cmd.execWorkspaces([], ['./a'], res)
})
// check filtering single workspace by full path
cmd.exec = function (args, cb) {
t.same(this.workspaces, ['a'],
'should set array with single ws name from full path')
cb()
}
await new Promise(res => {
cmd.execWorkspaces([], [resolve(path, './a')], res)
})
// filtering multiple workspaces by name
cmd.exec = function (args, cb) {
t.same(this.workspaces, ['a', 'c'],
'should set array with multiple listed ws names')
cb()
}
await new Promise(res => {
cmd.execWorkspaces([], ['a', 'c'], res)
})
// filtering multiple workspaces by path names
cmd.exec = function (args, cb) {
t.same(this.workspaces, ['a', 'c'],
'should set array with multiple ws names from paths')
cb()
}
await new Promise(res => {
cmd.execWorkspaces([], ['./a', 'group/c'], res)
})
// filtering multiple workspaces by parent path name
cmd.exec = function (args, cb) {
t.same(this.workspaces, ['c', 'd'],
'should set array with multiple ws names from a parent folder name')
cb()
}
await new Promise(res => {
cmd.execWorkspaces([], ['./group'], res)
})
})