mirror of
https://github.com/serverless/serverless.git
synced 2026-01-18 14:58:43 +00:00
improve emit and fix tests
This commit is contained in:
parent
b1dc0c48c6
commit
edfdf77fe8
@ -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}`);
|
||||
});
|
||||
}
|
||||
|
||||
@ -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'
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user