improve emit and fix tests

This commit is contained in:
Nik Graf 2017-08-14 14:40:04 +02:00
parent b1dc0c48c6
commit edfdf77fe8
No known key found for this signature in database
GPG Key ID: 7A97512F916175F1
2 changed files with 11 additions and 14 deletions

View File

@ -1,5 +1,6 @@
'use strict';
const os = require('os');
const BbPromise = require('bluebird');
const fdk = require('@serverless/fdk');
const path = require('path');
@ -134,14 +135,12 @@ class Emit {
.then(() => {
const msg = `${prefix}Emitted the event ${name} as datatype ${emitParams.dataType ||
'application/json'}:`;
this.serverless.cli.consoleLog(`${msg}`);
this.serverless.cli.consoleLog(prettifyValue(data));
this.serverless.cli.consoleLog(`${msg}${os.EOL}${prettifyValue(data)}`);
})
.catch(() => {
const msg = `${prefix}Failed to emit the event ${name} as datatype ${emitParams.dataType ||
'application/json'}:`;
this.serverless.cli.consoleLog(`${msg}`);
this.serverless.cli.consoleLog(prettifyValue(data));
this.serverless.cli.consoleLog(`${msg}${os.EOL}${prettifyValue(data)}`);
throw new Error(`Failed to emit the event ${name}`);
});
}

View File

@ -141,11 +141,10 @@ describe('Emit', () => {
data: emit.data,
})
).to.equal(true);
expect(logStub.calledOnce).to.equal(true);
const msgPartOne = 'Successfully emitted the event userCreated as datatype';
expect(
logStub.calledWithExactly(`${msgPartOne} application/json with:\n{"key":"value"}`)
).to.equal(true);
expect(logStub.getCall(0).args[0]).to.equal(
// eslint-disable-next-line max-len
'\u001b[38;5;178m Serverless \u001b[39mEmitted the event userCreated as datatype application/json:\n \u001b[38;5;243m{\u001b[39m\n\u001b[38;5;243m "key": "value"\u001b[39m\n\u001b[38;5;243m }\u001b[39m'
);
});
});
@ -162,11 +161,10 @@ describe('Emit', () => {
dataType: 'text/plain',
})
).to.equal(true);
expect(logStub.calledOnce).to.equal(true);
const msgPartOne = 'Successfully emitted the event userCreated as datatype';
expect(
logStub.calledWithExactly(`${msgPartOne} text/plain with:\n"This is a message"`)
).to.equal(true);
expect(logStub.getCall(0).args[0]).to.equal(
// eslint-disable-next-line max-len
'\u001b[38;5;178m Serverless \u001b[39mEmitted the event userCreated as datatype text/plain:\n \u001b[38;5;243m"This is a message"\u001b[39m'
);
});
});
});