Skip to content

Commit

Permalink
feat(canDeploy): resolve with output on success
Browse files Browse the repository at this point in the history
  • Loading branch information
Phillip Kuang committed Sep 12, 2019
1 parent 1d6c915 commit d20744e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
10 changes: 8 additions & 2 deletions src/can-deploy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,10 @@ describe('CanDeploy Spec', () => {
};
const ding = canDeployFactory(opts);

ding.canDeploy().then(done);
ding.canDeploy().then((results) => {
expect(results).not.to.be.null;
done();
});
});

it('should throw an error with a table result deployable false', () => {
Expand All @@ -201,7 +204,10 @@ describe('CanDeploy Spec', () => {
};
const ding = canDeployFactory(opts);

ding.canDeploy().then(done);
ding.canDeploy().then((results) => {
expect(results).not.to.be.null;
done();
});
});

it('should throw an error with a json result deployable false', () => {
Expand Down
11 changes: 6 additions & 5 deletions src/can-deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class CanDeploy {
logger.info(
`Asking broker at ${this.options.pactBroker} if it is possible to deploy`,
);
const deferred = q.defer<string[]>();
const deferred = q.defer<any>();
const instance = pactUtil.spawnBinary(
`${pactStandalone.brokerPath} can-i-deploy`,
CanDeploy.convertForSpawnBinary(this.options),
Expand All @@ -97,22 +97,23 @@ export class CanDeploy {
instance.stdout.on('data', l => output.push(l));
instance.stderr.on('data', l => output.push(l));
instance.once('close', code => {
const o = output.join('\n');
let o: any = output.join('\n');

let success = false;
if (this.options.output === 'json') {
success = JSON.parse(o).summary.deployable;
o = JSON.parse(o);
success = o.summary.deployable;
} else {
success = /Computer says yes/gim.exec(o) !== null;
}

if (code === 0 || success) {
logger.info(o);
return deferred.resolve();
return deferred.resolve(o);
}

logger.error(`can-i-deploy did not return success message:\n${o}`);
return deferred.reject(new Error(o));
return deferred.reject(o);
});

return deferred.promise.timeout(
Expand Down

0 comments on commit d20744e

Please sign in to comment.