From bc7759786b7ec9f12c5079498fd28a4d007f3ec0 Mon Sep 17 00:00:00 2001 From: Igor Klopov Date: Tue, 14 Feb 2017 20:49:48 +0300 Subject: [PATCH] test packed `now` binary (#311) --- package.json | 3 ++- test/pack-now.js | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 test/pack-now.js diff --git a/package.json b/package.json index 78f976d..e74aadc 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,8 @@ "test": "npm run build && npm run lint && ava", "prepublish": "npm run build", "build": "./build.sh", - "pack": "npm run build && pkg . --out-dir packed -t node7-alpine-x64,node7-linux-x64,node7-macos-x64,node7-win-x64" + "pack": "npm run build && npm run pkg", + "pkg": "pkg . --out-dir packed -t node7-alpine-x64,node7-linux-x64,node7-macos-x64,node7-win-x64" }, "pkg": { "scripts": [ diff --git a/test/pack-now.js b/test/pack-now.js new file mode 100644 index 0000000..c33894d --- /dev/null +++ b/test/pack-now.js @@ -0,0 +1,50 @@ +const path = require('path') +const crossSpawn = require('cross-spawn') +const test = require('ava') + +test.serial('make binary', async t => { + if (!process.env.CI) return // eslint-disable-line curly + const result = await spawn('npm', ['run', 'pkg']) + t.is(result.code, 0) +}) + +const binary = { + darwin: 'now-macos', + linux: 'now-linux', + win32: 'now-win.exe' +}[process.platform] + +const binaryPath = path.resolve(__dirname, '../packed/' + binary) +const deployHelpMessage = '𝚫 now [options] ' + +test.serial('packed "now help" prints deploy help message', async t => { + if (!process.env.CI) return // eslint-disable-line curly + const result = await spawn(binaryPath, ['help']) + + t.is(result.code, 0) + const stdout = result.stdout.split('\n') + t.true(stdout.length > 1) + t.true(stdout[1].includes(deployHelpMessage)) +}) + +function spawn(command, args) { + return new Promise((resolve, reject) => { + const child = crossSpawn.spawn(command, args) + + let stdout = '' + child.stdout.on('data', data => { + stdout += data + }) + + child.on('error', err => { + reject(err) + }) + + child.on('close', code => { + resolve({ + code, + stdout + }) + }) + }) +}