UNPKG

zapier-platform-cli

Version:

The CLI for apps in the Zapier Developer Platform.

57 lines (48 loc) 2.21 kB
'use strict'; var _ = require('lodash'); var constants = require('../constants'); var utils = require('../utils'); var validate = require('./validate'); var test = function test(context) { var extraEnv = { ZAPIER_BASE_ENDPOINT: constants.BASE_ENDPOINT }; if (global.argOpts.debug) { extraEnv.LOG_TO_STDOUT = 'true'; extraEnv.DETAILED_LOG_TO_STDOUT = 'true'; } if (!utils.isCorrectVersion(context)) { process.exitCode = 1; return Promise.resolve(); } var validated = global.argOpts['skip-validate'] ? Promise.resolve() : validate(context); return validated.then(function () { return utils.readCredentials(undefined, false); }).then(function (credentials) { context.line('Adding ' + constants.AUTH_LOCATION + ' to environment as ZAPIER_DEPLOY_KEY...'); extraEnv.ZAPIER_DEPLOY_KEY = credentials.deployKey; }).then(function () { var env = _.extend({}, process.env, extraEnv); var commands = ['run', '--silent', 'test']; if (global.argOpts.timeout) { commands.push('--'); commands.push('--timeout=' + global.argOpts.timeout); } context.line('Running test suite.'); return utils.runCommand('npm', commands, { stdio: 'inherit', env: env }).then(function (stdout) { if (stdout) { context.line(stdout); } }); }); }; test.argsSpec = []; test.argOptsSpec = { debug: { flag: true, help: 'print zapier detailed logs to standard out' }, timeout: { help: 'add a default timeout to mocha, in milliseconds' }, 'skip-validate': { flag: true, help: 'forgo running `zapier validate` before `npm test`' } }; test.help = 'Tests your app via `npm test`.'; test.example = 'zapier test'; test.docs = '\nThis command is effectively the same as `npm test`, except we also validate your app and set up the environment. We recommend using mocha as your testing framework.\n\n**Arguments**\n\n' + utils.argsFragment(test.argsSpec) + '\n' + utils.argOptsFragment(test.argOptsSpec) + '\n\n' + '```' + 'bash\n$ zapier test\n#\n# triggers\n# hello world\n# \u2713 should load fine (777ms)\n# \u2713 should accept parameters (331ms)\n#\n# 2 passing (817ms)\n#\n' + '```' + '\n'; module.exports = test;