Skip to content
This repository has been archived by the owner on Jun 27, 2019. It is now read-only.

Commit

Permalink
Merge pull request #175 from zapier/feature-convert-tester
Browse files Browse the repository at this point in the history
Adding a command to test converted apps.
  • Loading branch information
Bruno Bernardino authored Nov 7, 2017
2 parents cc706e0 + a7cf028 commit f2c44cc
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 1 deletion.
1 change: 1 addition & 0 deletions README-source.md
Original file line number Diff line number Diff line change
Expand Up @@ -1256,6 +1256,7 @@ While not always required, it's also recommended you use the same `zapier-platfo
- `npm install` for getting started
- `npm run build` for updating `./lib` from `./src`
- `npm test` for running tests (also runs `npm run build`)
- `npm run test-convert` for running integration tests for the `zapier convert` command
- `npm run docs` for updating docs
- `npm run gen-completions` for updating the auto complete scripts

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2022,6 +2022,7 @@ While not always required, it's also recommended you use the same `zapier-platfo
- `npm install` for getting started
- `npm run build` for updating `./lib` from `./src`
- `npm test` for running tests (also runs `npm run build`)
- `npm run test-convert` for running integration tests for the `zapier convert` command
- `npm run docs` for updating docs
- `npm run gen-completions` for updating the auto complete scripts

Expand Down
1 change: 1 addition & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3645,6 +3645,7 @@ <h2 id="development-of-the-cli">Development of the CLI</h2>
<li><code>npm install</code> for getting started</li>
<li><code>npm run build</code> for updating <code>./lib</code> from <code>./src</code></li>
<li><code>npm test</code> for running tests (also runs <code>npm run build</code>)</li>
<li><code>npm run test-convert</code> for running integration tests for the <code>zapier convert</code> command</li>
<li><code>npm run docs</code> for updating docs</li>
<li><code>npm run gen-completions</code> for updating the auto complete scripts</li>
</ul>
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"zapier": "zapier.js",
"validate-templates": "./scripts/validate-app-templates.js",
"set-template-versions": "./scripts/set-app-template-versions.js",
"gen-completions": "./scripts/gen-zsh-completions.js > ./goodies/zsh/_zapier && ./scripts/gen-bash-completions.js > ./goodies/bash/_zapier"
"gen-completions": "./scripts/gen-zsh-completions.js > ./goodies/zsh/_zapier && ./scripts/gen-bash-completions.js > ./goodies/bash/_zapier",
"test-convert": "./scripts/test-convert.js"
},
"dependencies": {
"adm-zip": "0.4.7",
Expand Down
66 changes: 66 additions & 0 deletions scripts/test-convert.js
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');
}
});

0 comments on commit f2c44cc

Please sign in to comment.