mirror of
https://github.com/serverless/serverless.git
synced 2026-01-18 14:58:43 +00:00
The 2nd argument of Logs constructor contains just a command line
arguments like `{"-f", "hello"}`.
As of the above, logs command always fail on the last of logs command.
PR#4344 aims to inject userStats, so I've solved this problem by
injecting userStats by substitution not the constructor argument.
69 lines
1.7 KiB
JavaScript
69 lines
1.7 KiB
JavaScript
'use strict';
|
|
|
|
const expect = require('chai').expect;
|
|
const sinon = require('sinon');
|
|
const Logs = require('./logs');
|
|
const Serverless = require('../../Serverless');
|
|
|
|
describe('Logs', () => {
|
|
let logs;
|
|
let serverless;
|
|
|
|
beforeEach(() => {
|
|
serverless = new Serverless();
|
|
logs = new Logs(serverless);
|
|
});
|
|
|
|
describe('#constructor()', () => {
|
|
it('should have commands', () => expect(logs.commands).to.be.not.empty);
|
|
});
|
|
|
|
describe('#track()', () => {
|
|
let userStats;
|
|
|
|
beforeEach(() => {
|
|
userStats = { track: sinon.spy() };
|
|
});
|
|
|
|
describe('Without cli processed input', () => {
|
|
it('do not track user stats', () => {
|
|
const newLogs = new Logs(serverless);
|
|
newLogs.userStats = userStats;
|
|
|
|
return newLogs.track()
|
|
.then(() => {
|
|
expect(userStats.track.called).to.be.equal(false);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('With cli processed input', () => {
|
|
it('tracks user stats with viewed option', () => {
|
|
serverless.processedInput = { commands: [], options: {} };
|
|
|
|
const newLogs = new Logs(serverless);
|
|
newLogs.userStats = userStats;
|
|
|
|
return newLogs.track()
|
|
.then(() => {
|
|
expect(userStats.track.calledWithExactly('service_logsViewed'))
|
|
.to.be.equal(true);
|
|
});
|
|
});
|
|
|
|
it('tracks user stats with tailed option', () => {
|
|
serverless.processedInput = { commands: [], options: { tail: true } };
|
|
|
|
const newLogs = new Logs(serverless);
|
|
newLogs.userStats = userStats;
|
|
|
|
return newLogs.track()
|
|
.then(() => {
|
|
expect(userStats.track.calledWithExactly('service_logsTailed'))
|
|
.to.be.equal(true);
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|