-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
run
executable file
·557 lines (470 loc) · 14.8 KB
/
run
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
#!/usr/bin/env bash
# See README.md for info on running these tests.
testEnvBlacklist() {
local cache=$(mktmpdir)
local env_dir=$(mktmpdir)
echo 'tr_TR.UTF-8' > "$env_dir"/LANG
echo 'safeVar' > "$env_dir"/SAFE
compile "echo-lang" $cache $env_dir
assertCaptured "safeVar"
assertNotCaptured "tr_TR.UTF-8"
assertCapturedSuccess
}
testPrePostBuildScripts() {
compile "pre-post-build-scripts"
assertCaptured "Running heroku-prebuild"
assertCaptured "echo heroku-prebuild hook message"
assertCaptured "Running heroku-postbuild"
assertCaptured "echo heroku-postbuild hook message"
assertCapturedSuccess
compile "stable-node"
assertNotCaptured "Running heroku-prebuild"
assertNotCaptured "Running heroku-postbuild"
assertCapturedSuccess
}
testWarningsOnFailure() {
compile "many-warnings"
assertCaptured "troubleshooting-node-deploys"
assertCaptured "node_modules checked into source"
assertCaptured "has several known issues"
assertNotCaptured "please submit a ticket"
assertCapturedError
}
testMultipleRuns() {
local compileDir=$(mktmpdir)
local cacheDir=$(mktmpdir)
cp -a test/fixtures/stable-node/. ${compileDir}
compileDir "$compileDir" "$cacheDir"
assertCapturedSuccess
compileDir "$compileDir" "$cacheDir"
assertCapturedSuccess
}
testDisableCache() {
cache=$(mktmpdir)
env_dir=$(mktmpdir)
compile "node-modules-cache-1" $cache
assertCaptured "lodash@1.0.0"
assertEquals "1" "$(ls -1 $cache/node/node_modules | grep lodash | wc -l | tr -d ' ')"
assertCapturedSuccess
compile "node-modules-cache-2" $cache
assertCaptured "lodash@1.0.0"
assertCaptured "Saving 2 cacheDirectories"
assertCapturedSuccess
echo "false" > $env_dir/NODE_MODULES_CACHE
compile "node-modules-cache-2" $cache $env_dir
assertCaptured "lodash@1.3.1"
assertNotCaptured "Saving 2 cacheDirectories"
assertCapturedSuccess
}
testBowerAngularResolution() {
compile "bower-angular-resolution"
assertCaptured "Bower may need a resolution hint for angular"
assertCapturedError
}
testUntrackedDependencies() {
compile "missing-grunt"
assertCaptured "Grunt may not be tracked in package.json"
assertCapturedError
}
testBadJson() {
compile "bad-json"
assertCaptured "Build failed"
assertCaptured "We're sorry this build is failing"
assertNotCaptured "Installing binaries"
assertCapturedError 1 "Unable to parse"
}
testNodeModulesCached() {
cache=$(mktmpdir)
compile "caching" $cache
assertCaptured "Saving 2 cacheDirectories (default)"
assertCaptured "- node_modules"
assertCaptured "- bower_components (nothing to cache)"
assertEquals "1" "$(ls -1 $cache/node | grep node_modules | wc -l | tr -d ' ')"
assertCapturedSuccess
}
testBuildWithUserCacheDirectoriesCamel() {
cache=$(mktmpdir)
compile "cache-directories-camel" $cache
assertCaptured "- non/existent (nothing to cache)"
assertEquals "1" "$(ls -1 $cache/node/server | grep node_modules | wc -l | tr -d ' ')"
assertEquals "1" "$(ls -1 $cache/node/client | grep node_modules | wc -l | tr -d ' ')"
assertCapturedSuccess
compile "cache-directories-camel" $cache
assertCaptured "Loading 3 from cacheDirectories"
assertCaptured "- server/node_modules"
assertCaptured "- client/node_modules"
assertCaptured "- non/existent (not cached - skipping)"
assertCapturedSuccess
}
testConcurrency1X() {
LOG_CONCURRENCY=true MEMORY_AVAILABLE=512 capture $(pwd)/profile/nodejs.sh
assertCaptured "Detected 512 MB available memory, 512 MB limit per process (WEB_MEMORY)"
assertCaptured "Recommending WEB_CONCURRENCY=1"
assertCapturedSuccess
}
testConcurrency2X() {
LOG_CONCURRENCY=true MEMORY_AVAILABLE=1024 capture $(pwd)/profile/nodejs.sh
assertCaptured "Detected 1024 MB available memory, 512 MB limit per process (WEB_MEMORY)"
assertCaptured "Recommending WEB_CONCURRENCY=2"
assertCapturedSuccess
}
testConcurrencyPerformanceM() {
LOG_CONCURRENCY=true MEMORY_AVAILABLE=2560 capture $(pwd)/profile/nodejs.sh
assertCaptured "Detected 2560 MB available memory, 512 MB limit per process (WEB_MEMORY)"
assertCaptured "Recommending WEB_CONCURRENCY=5"
assertCapturedSuccess
}
testConcurrencyPerformanceL() {
LOG_CONCURRENCY=true MEMORY_AVAILABLE=14336 capture $(pwd)/profile/nodejs.sh
assertCaptured "Detected 14336 MB available memory, 512 MB limit per process (WEB_MEMORY)"
assertCaptured "Recommending WEB_CONCURRENCY=28"
assertCapturedSuccess
}
testConcurrencyCustomLimit() {
LOG_CONCURRENCY=true MEMORY_AVAILABLE=1024 WEB_MEMORY=256 capture $(pwd)/profile/nodejs.sh
assertCaptured "Detected 1024 MB available memory, 256 MB limit per process (WEB_MEMORY)"
assertCaptured "Recommending WEB_CONCURRENCY=4"
assertCapturedSuccess
}
testConcurrencySaneMaximum() {
LOG_CONCURRENCY=true MEMORY_AVAILABLE=6144 WEB_MEMORY=32 capture $(pwd)/profile/nodejs.sh
assertCaptured "Detected 6144 MB available memory, 32 MB limit per process (WEB_MEMORY)"
assertCaptured "Recommending WEB_CONCURRENCY=32"
assertCapturedSuccess
}
testInvalidNode() {
compile "invalid-node"
assertCaptured "Downloading and installing node 0.11.33"
assertCaptured "Unable to download node 0.11.33"
assertCapturedError
}
testInvalidIo() {
compile "invalid-io"
assertCaptured "Downloading and installing iojs 2.0.99"
assertCaptured "Unable to download iojs 2.0.99"
assertCapturedError
}
testBuildWithCache() {
cache=$(mktmpdir)
compile "stable-node" $cache
assertCaptured "Skipping cache restore (new runtime"
assertEquals "1" "$(ls -1 $cache/node | grep node_modules | wc -l | tr -d ' ')"
assertCapturedSuccess
compile "stable-node" $cache
assertNotCaptured "- node_modules (not cached - skipping)"
assertCapturedSuccess
rm -rf "$cache/node/node_modules"
compile "stable-node" $cache
assertCaptured "- node_modules (not cached - skipping)"
assertCapturedSuccess
}
testSignatureInvalidation() {
cache=$(mktmpdir)
env_dir=$(mktmpdir)
compile "node-0.12.6" $cache
assertCaptured "Downloading and installing node 0.12.6"
assertCapturedSuccess
compile "node-0.12.7" $cache
assertCaptured "Downloading and installing node 0.12.7"
assertCaptured "Skipping cache restore (new runtime"
assertCapturedSuccess
}
testModulesCheckedIn() {
cache=$(mktmpdir)
compile "modules-checked-in" $cache
assertCapturedSuccess
compile "modules-checked-in" $cache
assertCaptured "Prebuild detected"
assertCaptured "Rebuilding any native modules"
assertCaptured "(preinstall script)"
assertCaptured "Installing any new modules"
assertCaptured "(postinstall script)"
assertNotCaptured "Pruning any extraneous modules"
assertCapturedSuccess
}
testDetectWithPackageJson() {
detect "stable-node"
assertCaptured "Node.js"
assertCapturedSuccess
}
testDetectWithoutPackageJson() {
detect "no-package-json"
assertCapturedError 1 ""
}
testIoJs() {
compile "iojs"
assertCaptured "engines.iojs (package.json): 1.0."
assertCaptured "Downloading and installing iojs 1.0."
assertNotCaptured "Downloading and installing npm"
assertCapturedSuccess
}
testNoVersion() {
compile "no-version"
assertCaptured "engines.node (package.json): unspecified"
assertCaptured "Resolving node version (latest stable) via semver.io"
assertCaptured "Downloading and installing node 5."
assertCapturedSuccess
}
testSpecificVersion() {
compile "specific-version"
assertNotCaptured "Resolving node version"
assertCaptured "Downloading and installing node 0.10.29"
assertCaptured "Using default npm version: 1.4.14"
assertCapturedSuccess
}
testStableVersion() {
compile "stable-node"
assertCaptured "Downloading and installing node 0.10."
assertNotCaptured "We're sorry this build is failing"
assertCapturedSuccess
}
testUnstableVersion() {
compile "unstable-version"
assertCaptured "Resolving node version 0.11.x via semver.io"
assertCaptured "Downloading and installing node 0.11."
assertCapturedSuccess
}
testOldNpm() {
compile "old-npm"
assertCaptured "This version of npm (1.2.8000) has several known issues - consider upgrading to the latest release (3."
assertNotCaptured "integer expression expected"
assertCapturedError
}
testOldNpm2() {
compile "failing-build"
assertCaptured "This version of npm (1.4.28) has several known issues"
}
testNonexistentNpm() {
compile "nonexistent-npm"
assertCaptured "version not found: npm@1.1.65"
assertCapturedError 1 ""
}
testSameNpm() {
compile "same-npm"
assertCaptured "npm 1.4.28 already installed"
assertCapturedSuccess
}
testNpmVersionRange() {
compile "npm-version-range"
assertCaptured "Resolving npm version"
assertCaptured "installing npm 1.4."
assertCapturedSuccess
}
testNpmVersionSpecific() {
compile "npm-version-specific"
assertCaptured "installing npm 2.1.11"
assertNotCaptured "Resolving npm version"
assertNotCaptured "WARNING"
assertCapturedSuccess
}
testFailingBuild() {
compile "failing-build"
assertCaptured "Building dependencies"
assertCaptured "Build failed"
assertCaptured "We're sorry this build is failing"
assertNotCaptured "Checking startup method"
assertCapturedError 1 ""
}
testTicketOnFailure() {
compile "invalid-dependency"
assertCaptured "troubleshooting-node-deploys"
assertCaptured "please submit a ticket"
assertNotCaptured "possible problems"
assertCapturedError
}
testInfoEmpty() {
compile "info-empty"
assertCaptured "engines.node (package.json): unspecified"
assertCaptured "engines.npm (package.json): unspecified"
assertCaptured "Installing node modules (package.json)"
assertCapturedSuccess
}
testDangerousRangeStar() {
compile "dangerous-range-star"
assertCaptured "Dangerous semver range"
assertCaptured "Resolving node version * via semver.io"
assertCaptured "Downloading and installing node 5."
assertCapturedError
}
testDangerousRangeGreaterThan() {
compile "dangerous-range-greater-than"
assertCaptured "Dangerous semver range"
assertCaptured "Resolving node version >0.4 via semver.io"
assertCaptured "Downloading and installing node 5."
assertCapturedError
}
testRangeWithSpace() {
compile "range-with-space"
assertCaptured "Resolving node version >= 0.8.x via semver.io"
assertCaptured "Downloading and installing node 5."
assertCapturedSuccess
}
testInvalidDependency() {
compile "invalid-dependency"
assertCaptured "npm ERR! 404"
assertCapturedError 1 ""
}
testBuildWithUserCacheDirectories() {
cache=$(mktmpdir)
compile "cache-directories" $cache
assertCaptured "Saving 2 cacheDirectories"
assertEquals "1" "$(ls -1 $cache/node | grep bower_components | wc -l | tr -d ' ')"
assertEquals "1" "$(ls -1 $cache/node | grep node_modules | wc -l | tr -d ' ')"
assertCapturedSuccess
compile "cache-directories" $cache
assertCaptured "Loading 2 from cacheDirectories"
assertCaptured "- node_modules"
assertCaptured "- bower_components"
assertCapturedSuccess
}
testUserConfig() {
compile "userconfig"
assertCaptured "www.google.com"
assertCaptured "registry error"
assertCapturedError 1 ""
}
testDefaultProcType() {
release "stable-node"
assertCaptured "web: npm start"
assertCapturedSuccess
}
testDynamicProcfile() {
compile "dynamic-procfile"
assertFileContains "web: node index.js customArg" "${compile_dir}/Procfile"
assertCapturedSuccess
}
testEnvVars() {
env_dir=$(mktmpdir)
echo "false" > $env_dir/NPM_CONFIG_PRODUCTION
compile "stable-node" "$(mktmpdir)" $env_dir
assertCaptured "NPM_CONFIG_PRODUCTION=false"
assertCapturedSuccess
}
testNoEnvVars() {
env_dir=$(mktmpdir)
compile "stable-node" "$(mktmpdir)" $env_dir
assertCaptured "NPM_CONFIG_PRODUCTION=true"
assertCapturedSuccess
}
testNonFileEnvVars() {
export NPM_CONFIG_FOO=bar
export NPM_CONFIG_PRODUCTION=false
compile "stable-node"
assertCaptured "NPM_CONFIG_FOO=bar"
assertCaptured "NPM_CONFIG_PRODUCTION=false"
assertCapturedSuccess
unset NPM_CONFIG_FOO
unset NPM_CONFIG_PRODUCTION
}
testNoDevDependencies() {
compile "dev-dependencies"
assertNotCaptured "lodash"
assertCapturedSuccess
}
testDevDependencies() {
env_dir=$(mktmpdir)
echo "false" > $env_dir/NPM_CONFIG_PRODUCTION
compile "dev-dependencies" "$(mktmpdir)" $env_dir
assertCaptured "lodash"
assertCapturedSuccess
}
testOptionalDependencies() {
env_dir=$(mktmpdir)
compile "optional-dependencies" "$(mktmpdir)" $env_dir
assertNotCaptured "NPM_CONFIG_OPTIONAL"
assertCaptured "less"
assertCaptured "mime"
assertCaptured "mkdirp"
assertCaptured "clean-css"
assertCaptured "request"
assertCapturedSuccess
}
testNoOptionalDependencies() {
env_dir=$(mktmpdir)
echo "false" > $env_dir/NPM_CONFIG_OPTIONAL
compile "optional-dependencies" "$(mktmpdir)" $env_dir
assertCaptured "NPM_CONFIG_OPTIONAL=false"
assertCaptured "less"
assertNotCaptured "mime"
assertNotCaptured "mkdirp"
assertNotCaptured "clean-css"
assertNotCaptured "request"
assertCapturedSuccess
}
testNpmrc() {
compile "dev-dependencies"
assertNotCaptured "lodash"
assertCapturedSuccess
compile "dev-dependencies-npmrc"
assertCaptured "lodash"
assertCapturedSuccess
}
testShrinkwrap() {
compile "shrinkwrap"
assertCaptured "express@4.10.4"
assertCaptured "lodash@2.4.0"
assertNotCaptured "mocha"
assertCapturedSuccess
}
testProfileExport() {
compile "stable-node"
assertCaptured "Creating runtime environment"
assertFileContains "export PATH=\"\$HOME/.heroku/node/bin:\$PATH:\$HOME/bin:\$HOME/node_modules/.bin\"" "${compile_dir}/.profile.d/nodejs.sh"
assertFileContains "export NODE_HOME=\"\$HOME/.heroku/node\"" "${compile_dir}/.profile.d/nodejs.sh"
assertCapturedSuccess
}
testMultiExport() {
compile "stable-node"
assertFileContains "export PATH=" "${bp_dir}/export"
assertFileContains "/.heroku/node/bin" "${bp_dir}/export"
assertFileContains "/node_modules/.bin" "${bp_dir}/export"
assertFileContains "export NODE_HOME=" "${bp_dir}/export"
assertFileContains "/.heroku/node\"" "${bp_dir}/export"
assertCapturedSuccess
}
# Utils
pushd $(dirname 0) >/dev/null
popd >/dev/null
source $(pwd)/test/utils
mktmpdir() {
dir=$(mktemp -t testXXXXX)
rm -rf $dir
mkdir $dir
echo $dir
}
detect() {
capture $(pwd)/bin/detect $(pwd)/test/fixtures/$1
}
compile_dir=""
default_process_types_cleanup() {
file="/tmp/default_process_types"
if [ -f "$file" ]; then
rm "$file"
fi
}
compile() {
default_process_types_cleanup
bp_dir=$(mktmpdir)
compile_dir=$(mktmpdir)
cp -a $(pwd)/* ${bp_dir}
cp -a ${bp_dir}/test/fixtures/$1/. ${compile_dir}
capture ${bp_dir}/bin/compile ${compile_dir} ${2:-$(mktmpdir)} $3
}
compileDir() {
default_process_types_cleanup
local bp_dir=$(mktmpdir)
local compile_dir=${1:-$(mktmpdir)}
local cache_dir=${2:-$(mktmpdir)}
local env_dir=$3
cp -a $(pwd)/* ${bp_dir}
capture ${bp_dir}/bin/compile ${compile_dir} ${cache_dir} ${env_dir}
}
release() {
bp_dir=$(mktmpdir)
cp -a $(pwd)/* ${bp_dir}
capture ${bp_dir}/bin/release ${bp_dir}/test/fixtures/$1
}
assertFile() {
assertEquals "$1" "$(cat ${compile_dir}/$2)"
}
source $(pwd)/test/shunit2