-
Notifications
You must be signed in to change notification settings - Fork 251
/
local-test-util
executable file
·213 lines (189 loc) · 6.13 KB
/
local-test-util
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#!/usr/bin/env node
const { spawn, exec } = require('child_process')
const { promisify } = require('util')
const { dirname, join, resolve, basename } = require('path')
const execAsync = promisify(exec)
const help = `
$ ./bin/local-test-util
commands for running end-to-end browser tests locally
outside of docker for quicker iteration in development
usage:
./bin/local-test-util init
./bin/local-test-util update
./bin/local-test-util update-notifier <name>
./bin/local-test-util update-fixture <name>
./bin/local-test-util clean
`
const cmd = process.argv[2]
switch (cmd) {
case 'init':
init()
break
case 'update':
update()
break
case 'update-notifier':
updateNotifiers(process.argv[3])
break
case 'update-fixture':
updateFixtures(process.argv[3])
break
case 'clean':
clean()
break
case 'help':
default:
if (cmd && cmd !== 'help') console.log(`unknown command ${cmd}`)
console.log(help)
process.exitCode = 1
}
// --------------
// COMMANDS
// --------------
async function init () {
try {
await cleanFixtures()
await update()
} catch (e) {
console.log(e)
process.exitCode = 1
}
}
async function update () {
try {
await updateNotifiers()
await installFixtureDeps()
await buildFixtures()
} catch (e) {
console.log(e)
process.exitCode = 1
}
}
async function updateNotifiers (notifier) {
await buildNotifiers(notifier)
await packNotifiers(notifier)
await installNotifiers(notifier)
await installNgNotifier(notifier)
}
async function updateFixtures (fixture) {
await buildFixtures(fixture)
}
async function clean () {
try {
await cleanFixtures()
await cleanNotifiers()
} catch (e) {
console.log(e)
process.exitCode = 1
}
}
// --------------
// Utilities
// --------------
async function ex (cmd, args, uopts) {
const opts = { stdio: 'inherit', ...uopts }
console.log(`>>> "${cmd} ${args.join(' ')}" with opts: ${JSON.stringify(opts)}`)
return new Promise((resolve, reject) => {
const proc = spawn(cmd, args, opts)
proc.on('error', reject)
proc.on('close', () => resolve())
})
}
function trace (stepname) {
console.log(`\n• ${stepname} •\n ${Array(stepname.length).fill('-').join('')}`)
}
async function buildNotifiers (notifier) {
trace('build notifiers')
if (notifier) {
return ex(`npx`, [ `lerna`, `run`, `build` ].concat(notifier ? [ '--scope', `@bugsnag/${notifier}` ] : []))
} else {
return ex(`npm`, [ `run`, `build` ])
}
}
async function packNotifiers (notifier) {
const notifiers = notifier
? [ notifier ]
: [ 'js', 'browser', 'node', 'web-worker', 'plugin-angular', 'plugin-react', 'plugin-vue' ]
for (const n of notifiers) {
await ex(`npm`, [ `pack`, `--verbose`, `packages/${n}/` ])
}
}
async function installNotifiers (notifier) {
trace('install notifiers')
if (notifier && ![ 'browser', 'plugin-vue', 'plugin-react', 'web-worker' ].includes(notifier)) return
await ex(`npm`, [
`install`,
`--no-package-lock`,
`--no-save`,
].concat(notifier
? [
`../../../../bugsnag-${notifier}-${require(`../packages/${notifier}/package.json`).version}.tgz`
]
: [
`../../../../bugsnag-browser-${require('../packages/browser/package.json').version}.tgz`,
`../../../../bugsnag-web-worker-${require('../packages/web-worker/package.json').version}.tgz`,
`../../../../bugsnag-plugin-react-${require('../packages/plugin-react/package.json').version}.tgz`,
`../../../../bugsnag-plugin-vue-${require('../packages/plugin-vue/package.json').version}.tgz`
]
), {
cwd: `${__dirname}/../test/browser/features/fixtures`
})
}
async function installNgNotifier (notifier) {
trace('install ng notifier')
if (notifier && ![ 'browser', 'node', 'js', 'plugin-angular', 'web-worker' ].includes(notifier)) return
await ex(`npm`, [
`install`,
`--no-package-lock`,
`--no-save`,
`../../../../../../bugsnag-browser-${require('../packages/browser/package.json').version}.tgz`,
`../../../../../../bugsnag-js-${require('../packages/js/package.json').version}.tgz`,
`../../../../../../bugsnag-node-${require('../packages/node/package.json').version}.tgz`,
`../../../../../../bugsnag-web-worker-${require('../packages/web-worker/package.json').version}.tgz`,
`../../../../../../bugsnag-plugin-angular-${require('../packages/plugin-angular/package.json').version}.tgz`
], {
cwd: `${__dirname}/../test/browser/features/fixtures/plugin_angular/ng`
})
}
async function cleanFixtures (fixture) {
trace('clean fixture')
const manifests = await findFixtureManifests(fixture)
for (const m of manifests) {
const cwd = join(process.cwd(), dirname(m))
await ex('rm', [ `-fr`, `node_modules` ], { cwd })
await ex('rm', [ `-fr`, `dist` ], { cwd })
}
await ex('rm', [ `-fr`, `${process.cwd()}/test/browser/features/fixtures/node_modules` ])
}
async function cleanNotifiers () {
const { stdout, stderr } = await execAsync('ls')
if (stderr) throw new Error(`"ls" wrote this to stderr: ${stderr}`)
const tgzs = stdout.trim().split('\n').filter(f => /^bugsnag-.*\.tgz$/.test(f))
for (const t of tgzs) {
await ex('rm', [ t ])
}
}
async function findFixtureManifests (fixture) {
const { stdout, stderr } = await execAsync('find test/browser/features/fixtures \\( -path "*/package.json" -and \\! -path "*/node_modules/*" \\) -type f -mindepth 2 -maxdepth 3')
if (stderr) throw new Error(`"find" wrote this to stderr: ${stderr}`)
return stdout.trim().split('\n').filter(m => {
if (!fixture) return true
return basename(resolve(m, '..', '..')) === fixture
})
}
async function installFixtureDeps (fixture) {
trace('install fixture deps')
const manifests = await findFixtureManifests(fixture)
for (const m of manifests) {
const cwd = join(process.cwd(), dirname(m))
await ex('npm', [ `install`, `--no-package-lock` ], { cwd })
}
}
async function buildFixtures (fixture) {
trace('build fixtures')
const manifests = await findFixtureManifests(fixture)
for (const m of manifests) {
const cwd = join(process.cwd(), dirname(m))
await ex('npm', [ `run`, `build` ], { cwd })
}
}