|
15 | 15 | 'use strict'; |
16 | 16 |
|
17 | 17 | const assert = require('assert'); |
18 | | -const {spawn} = require('child_process'); |
| 18 | +const {execSync, spawn} = require('child_process'); |
19 | 19 | const {Storage} = require('@google-cloud/storage'); |
20 | 20 | const sinon = require('sinon'); |
21 | 21 | const {request} = require('gaxios'); |
@@ -47,13 +47,26 @@ async function startFF(port) { |
47 | 47 | let stderr = ''; |
48 | 48 | ffProc.stdout.on('data', data => (stdout += data)); |
49 | 49 | ffProc.stderr.on('data', data => (stderr += data)); |
50 | | - ffProc.on('error', reject); |
51 | | - ffProc.on('exit', c => (c === 0 ? resolve(stdout) : reject(stderr))); |
| 50 | + ffProc.on('exit', code => { |
| 51 | + if (code === 0 || code === null) { |
| 52 | + // code === null corresponds to a signal-kill |
| 53 | + // (which doesn't necessarily indicate a test failure) |
| 54 | + resolve(stdout); |
| 55 | + } else { |
| 56 | + stderr = `Error code: ${code}\n${stderr}`; |
| 57 | + reject(new Error(stderr)); |
| 58 | + } |
| 59 | + }); |
52 | 60 | }); |
53 | 61 | await waitPort({host: 'localhost', port}); |
54 | 62 | return {ffProc, ffProcHandler}; |
55 | 63 | } |
56 | 64 |
|
| 65 | +// ImageMagick is available by default in Cloud Run Functions environments |
| 66 | +// https://cloud.google.com/functions/1stgendocs/tutorials/imagemagick-1st-gen.md#importing_dependencies |
| 67 | +// Manually install it for testing only. |
| 68 | +execSync('sudo apt-get install imagemagick -y'); |
| 69 | + |
57 | 70 | describe('functions/imagemagick tests', () => { |
58 | 71 | before(async () => { |
59 | 72 | let exists; |
|
0 commit comments