This repository has been archived by the owner on Jun 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #175 from zapier/feature-convert-tester
Adding a command to test converted apps.
- Loading branch information
Showing
5 changed files
with
71 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#!/usr/bin/env node | ||
|
||
const _ = require('lodash'); | ||
const path = require('path'); | ||
const tmp = require('tmp'); | ||
const utils = require('../lib/utils'); | ||
|
||
const fse = require('fs-extra'); | ||
const childProcess = utils.promisifyAll(require('child_process')); | ||
|
||
const appsToConvert = [ | ||
{id: 80082, name: 'simple-basic-auth'}, | ||
// TODO: Add more apps that require scripting and different auths, once zapier-platform-legacy-scripting-runner is live | ||
]; | ||
|
||
const testConvertedApp = (appToConvert, rootTmpDir) => { | ||
const zapierCmd = path.resolve(__dirname, '../zapier.js'); | ||
// Prepare all env variables the apps might need | ||
const exportCmd = 'export CLIENT_ID=1234 CLIENT_SECRET=asdf USERNAME=user PASSWORD=passwd API_KEY=anything-goes ACCESS_TOKEN=a_token REFRESH_TOKEN=a_refresh_token'; | ||
|
||
const logFile = path.resolve(__dirname, '..', `${appToConvert.name}.log`); | ||
const logStream = fse.createWriteStream(logFile); | ||
|
||
console.log(`Converting and testing ${appToConvert.name}, writing logs to ${logFile}`); | ||
return fse.ensureFile(logFile) | ||
.then(() => { | ||
return new Promise((resolve, reject) => { | ||
const cmd = `${zapierCmd} convert ${appToConvert.id} ${appToConvert.name} --debug && cd ${appToConvert.name} && npm install && ${zapierCmd} validate && ${exportCmd} && ${zapierCmd} test --timeout=10000`; | ||
const child = childProcess.exec(cmd, {cwd: rootTmpDir}, err => { | ||
if (err) { | ||
console.log('error starting child process:', err); | ||
reject(err); | ||
} | ||
resolve(); | ||
}); | ||
child.stdout.pipe(logStream); | ||
child.stderr.pipe(logStream); | ||
}); | ||
}) | ||
.then(() => { | ||
console.log(`${appToConvert.name} converted successfully`); | ||
return null; | ||
}) | ||
.catch(() => { | ||
console.error(`${appToConvert.name} conversion failed. See ${logFile}.`); | ||
return appToConvert.name; | ||
}); | ||
}; | ||
|
||
global.argOpts = {}; | ||
|
||
const rootTmpDir = tmp.tmpNameSync(); | ||
fse.removeSync(rootTmpDir); | ||
fse.ensureDirSync(rootTmpDir); | ||
|
||
const tasks = _.map(appsToConvert, template => testConvertedApp(template, rootTmpDir)); | ||
|
||
Promise.all(tasks) | ||
.then(results => { | ||
const failures = _.filter(results, result => result !== null); | ||
if (failures.length) { | ||
console.error('these apps failed conversion:', failures.join(', ')); | ||
} else { | ||
console.log('apps converted successfully'); | ||
} | ||
}); |