mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-10 03:32:52 +00:00
test: adjust tests
This commit is contained in:
@@ -1,293 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2018, 2019 StApps
|
|
||||||
* This program is free software: you can redistribute it and/or modify it
|
|
||||||
* under the terms of the GNU General Public License as published by the Free
|
|
||||||
* Software Foundation, version 3.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
||||||
* more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with
|
|
||||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
import * as chai from 'chai';
|
|
||||||
import {expect} from 'chai';
|
|
||||||
import * as chaiAsPromised from 'chai-as-promised';
|
|
||||||
import {slow, suite, test, timeout} from 'mocha-typescript';
|
|
||||||
import * as sinon from 'sinon';
|
|
||||||
import {Logger} from '../src/Logger';
|
|
||||||
import {DummyTransport} from './Transport.spec';
|
|
||||||
|
|
||||||
chai.should();
|
|
||||||
chai.use(chaiAsPromised);
|
|
||||||
|
|
||||||
@suite(timeout(2000), slow(1000))
|
|
||||||
export class LoggerSpec {
|
|
||||||
@test
|
|
||||||
async error() {
|
|
||||||
const stub = sinon.stub(console, 'error');
|
|
||||||
|
|
||||||
await Logger.error('Foobar');
|
|
||||||
|
|
||||||
stub.restore();
|
|
||||||
|
|
||||||
expect(stub.args[0][0]).contains('[ERROR]');
|
|
||||||
expect(stub.args[0][0]).contains('Foobar');
|
|
||||||
}
|
|
||||||
|
|
||||||
@test
|
|
||||||
async errorInProductiveEnvironment() {
|
|
||||||
const errorStub = sinon.stub(console, 'error');
|
|
||||||
|
|
||||||
const nodeEnv = process.env.NODE_ENV;
|
|
||||||
process.env.NODE_ENV = 'production';
|
|
||||||
|
|
||||||
await Logger.error('Foobar').should.be.rejectedWith(Error);
|
|
||||||
expect(errorStub.callCount).to.be.equal(1);
|
|
||||||
|
|
||||||
process.env.ALLOW_NO_TRANSPORT = 'true';
|
|
||||||
|
|
||||||
await Logger.error('Foobar').should.not.be.rejectedWith(Error);
|
|
||||||
expect(errorStub.callCount).to.be.equal(2);
|
|
||||||
|
|
||||||
delete process.env.ALLOW_NO_TRANSPORT;
|
|
||||||
|
|
||||||
Logger.setTransport(new DummyTransport());
|
|
||||||
|
|
||||||
await Logger.error('Foobar').should.not.be.rejectedWith(Error);
|
|
||||||
expect(errorStub.callCount).to.be.equal(3);
|
|
||||||
|
|
||||||
Logger.setTransport();
|
|
||||||
|
|
||||||
process.env.NODE_ENV = nodeEnv;
|
|
||||||
|
|
||||||
errorStub.restore();
|
|
||||||
}
|
|
||||||
|
|
||||||
@test
|
|
||||||
async errorNoOutput() {
|
|
||||||
const stub = sinon.stub(console, 'error');
|
|
||||||
|
|
||||||
process.env.STAPPS_LOG_LEVEL = '0';
|
|
||||||
|
|
||||||
await Logger.error('Foobar');
|
|
||||||
|
|
||||||
stub.restore();
|
|
||||||
|
|
||||||
delete process.env.STAPPS_LOG_LEVEL;
|
|
||||||
|
|
||||||
return expect(stub.called).to.be.false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@test
|
|
||||||
async errorWithError() {
|
|
||||||
const e = new Error();
|
|
||||||
const stub = sinon.stub(console, 'error');
|
|
||||||
|
|
||||||
await Logger.error(e);
|
|
||||||
|
|
||||||
stub.restore();
|
|
||||||
|
|
||||||
expect(stub.args[0][0]).contains('Error').contains('at').contains(process.cwd());
|
|
||||||
}
|
|
||||||
|
|
||||||
@test
|
|
||||||
getLogLevel() {
|
|
||||||
const savedProcess = process;
|
|
||||||
|
|
||||||
// @ts-ignore
|
|
||||||
process = undefined;
|
|
||||||
|
|
||||||
(global as any).window = {
|
|
||||||
STAPPS_LOG_LEVEL: 0,
|
|
||||||
};
|
|
||||||
|
|
||||||
const stub = sinon.stub(console, 'info');
|
|
||||||
|
|
||||||
Logger.info('Foobar');
|
|
||||||
|
|
||||||
stub.restore();
|
|
||||||
|
|
||||||
process = savedProcess;
|
|
||||||
|
|
||||||
delete (global as any).window;
|
|
||||||
|
|
||||||
return expect(stub.called).to.be.false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@test
|
|
||||||
info() {
|
|
||||||
const stub = sinon.stub(console, 'info');
|
|
||||||
|
|
||||||
Logger.info('Foobar');
|
|
||||||
|
|
||||||
stub.restore();
|
|
||||||
|
|
||||||
expect(stub.args[0][0]).contains('[INFO]');
|
|
||||||
expect(stub.args[0][0]).contains('Foobar');
|
|
||||||
}
|
|
||||||
|
|
||||||
@test
|
|
||||||
infoNoOutput() {
|
|
||||||
const stub = sinon.stub(console, 'info');
|
|
||||||
|
|
||||||
process.env.STAPPS_LOG_LEVEL = '0';
|
|
||||||
|
|
||||||
Logger.info('Foobar');
|
|
||||||
|
|
||||||
stub.restore();
|
|
||||||
|
|
||||||
delete process.env.STAPPS_LOG_LEVEL;
|
|
||||||
|
|
||||||
return expect(stub.called).to.be.false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@test
|
|
||||||
initialized() {
|
|
||||||
Logger.setTransport(new DummyTransport());
|
|
||||||
|
|
||||||
expect(() => {
|
|
||||||
Logger.initialized();
|
|
||||||
}).not.to.throw();
|
|
||||||
|
|
||||||
Logger.setTransport();
|
|
||||||
}
|
|
||||||
|
|
||||||
@test
|
|
||||||
initializedInProductiveEnvironment() {
|
|
||||||
const nodeEnv = process.env.NODE_ENV;
|
|
||||||
process.env.NODE_ENV = 'production';
|
|
||||||
|
|
||||||
Logger.setTransport(new DummyTransport());
|
|
||||||
|
|
||||||
expect(() => {
|
|
||||||
Logger.initialized();
|
|
||||||
}).not.to.throw();
|
|
||||||
|
|
||||||
Logger.setTransport();
|
|
||||||
|
|
||||||
expect(() => {
|
|
||||||
Logger.initialized();
|
|
||||||
}).to.throw();
|
|
||||||
|
|
||||||
const stub = sinon.stub(console, 'warn');
|
|
||||||
|
|
||||||
process.env.ALLOW_NO_TRANSPORT = 'true';
|
|
||||||
|
|
||||||
expect(() => {
|
|
||||||
Logger.initialized();
|
|
||||||
}).not.to.throw();
|
|
||||||
|
|
||||||
delete process.env.ALLOW_NO_TRANSPORT;
|
|
||||||
|
|
||||||
expect(stub.called).to.be.equal(true);
|
|
||||||
|
|
||||||
stub.restore();
|
|
||||||
|
|
||||||
process.env.NODE_ENV = nodeEnv;
|
|
||||||
}
|
|
||||||
|
|
||||||
@test
|
|
||||||
log() {
|
|
||||||
const stub = sinon.stub(console, 'log');
|
|
||||||
|
|
||||||
Logger.log('Foobar');
|
|
||||||
|
|
||||||
stub.restore();
|
|
||||||
|
|
||||||
expect(stub.args[0][0]).contains('[LOG]');
|
|
||||||
expect(stub.args[0][0]).contains('Foobar');
|
|
||||||
}
|
|
||||||
|
|
||||||
@test
|
|
||||||
logNoOutput() {
|
|
||||||
const stub = sinon.stub(console, 'log');
|
|
||||||
|
|
||||||
process.env.STAPPS_LOG_LEVEL = '0';
|
|
||||||
|
|
||||||
Logger.log('Foobar');
|
|
||||||
|
|
||||||
stub.restore();
|
|
||||||
|
|
||||||
delete process.env.STAPPS_LOG_LEVEL;
|
|
||||||
|
|
||||||
return expect(stub.called).to.be.false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@test
|
|
||||||
ok() {
|
|
||||||
const stub = sinon.stub(console, 'log');
|
|
||||||
|
|
||||||
Logger.ok('Foobar');
|
|
||||||
|
|
||||||
stub.restore();
|
|
||||||
|
|
||||||
expect(stub.args[0][0]).contains('[OK]');
|
|
||||||
expect(stub.args[0][0]).contains('Foobar');
|
|
||||||
}
|
|
||||||
|
|
||||||
@test
|
|
||||||
okNoOutput() {
|
|
||||||
const stub = sinon.stub(console, 'log');
|
|
||||||
|
|
||||||
process.env.STAPPS_LOG_LEVEL = '0';
|
|
||||||
|
|
||||||
Logger.ok('Foobar');
|
|
||||||
|
|
||||||
stub.restore();
|
|
||||||
|
|
||||||
delete process.env.STAPPS_LOG_LEVEL;
|
|
||||||
|
|
||||||
return expect(stub.called).to.be.false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@test
|
|
||||||
setTransport() {
|
|
||||||
expect(() => {
|
|
||||||
Logger.setTransport(new DummyTransport());
|
|
||||||
Logger.setTransport();
|
|
||||||
}).not.to.throw();
|
|
||||||
}
|
|
||||||
|
|
||||||
@test
|
|
||||||
stringifyArguments() {
|
|
||||||
const stub = sinon.stub(console, 'log');
|
|
||||||
|
|
||||||
Logger.log('foo', 'bar');
|
|
||||||
|
|
||||||
stub.restore();
|
|
||||||
|
|
||||||
expect(stub.args[0][0]).contains('[LOG]');
|
|
||||||
expect(stub.args[0][0]).contains('foo');
|
|
||||||
expect(stub.args[0][0]).contains('bar');
|
|
||||||
}
|
|
||||||
|
|
||||||
@test
|
|
||||||
warn() {
|
|
||||||
const stub = sinon.stub(console, 'warn');
|
|
||||||
|
|
||||||
Logger.warn('Foobar');
|
|
||||||
|
|
||||||
stub.restore();
|
|
||||||
|
|
||||||
expect(stub.args[0][0]).contains('[WARN]');
|
|
||||||
expect(stub.args[0][0]).contains('Foobar');
|
|
||||||
}
|
|
||||||
|
|
||||||
@test
|
|
||||||
warnNoOutput() {
|
|
||||||
const stub = sinon.stub(console, 'warn');
|
|
||||||
|
|
||||||
process.env.STAPPS_LOG_LEVEL = '0';
|
|
||||||
|
|
||||||
Logger.warn('Foobar');
|
|
||||||
|
|
||||||
stub.restore();
|
|
||||||
|
|
||||||
delete process.env.STAPPS_LOG_LEVEL;
|
|
||||||
|
|
||||||
return expect(stub.called).to.be.false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
35
test/dummyTransport.ts
Normal file
35
test/dummyTransport.ts
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
import {Transport, VerifiableTransport} from '../src/transport';
|
||||||
|
|
||||||
|
export class DummyTransport extends Transport {
|
||||||
|
send(subject: string, message: string): Promise<string> {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
if (0 === 0) {
|
||||||
|
resolve(subject);
|
||||||
|
}
|
||||||
|
|
||||||
|
reject(message);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class VerifiableDummyTransport extends VerifiableTransport {
|
||||||
|
isVerified(): boolean {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
send(subject: string, message: string): Promise<string> {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
if (0 === 0) {
|
||||||
|
resolve(subject);
|
||||||
|
}
|
||||||
|
|
||||||
|
reject(message);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
verify(): Promise<boolean> {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
resolve(true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
314
test/logger.spec.ts
Normal file
314
test/logger.spec.ts
Normal file
@@ -0,0 +1,314 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2018, 2019 StApps
|
||||||
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by the Free
|
||||||
|
* Software Foundation, version 3.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
* more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with
|
||||||
|
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
import * as chai from 'chai';
|
||||||
|
import {expect} from 'chai';
|
||||||
|
import * as chaiAsPromised from 'chai-as-promised';
|
||||||
|
import * as chaiSpies from 'chai-spies';
|
||||||
|
import {slow, suite, timeout} from 'mocha-typescript';
|
||||||
|
import {Logger} from '../src/logger';
|
||||||
|
import {DummyTransport} from './dummyTransport';
|
||||||
|
|
||||||
|
chai.should();
|
||||||
|
chai.use(chaiSpies);
|
||||||
|
chai.use(chaiAsPromised);
|
||||||
|
|
||||||
|
@suite(timeout(2000), slow(1000))
|
||||||
|
export class LoggerSpec {
|
||||||
|
static sandbox: any;
|
||||||
|
|
||||||
|
static before() {
|
||||||
|
LoggerSpec.sandbox = chai.spy.sandbox();
|
||||||
|
}
|
||||||
|
|
||||||
|
before() {
|
||||||
|
LoggerSpec.sandbox.restore();
|
||||||
|
}
|
||||||
|
|
||||||
|
@test
|
||||||
|
async 'default log level'() {
|
||||||
|
expect((Logger as any).getLogLevel()).to.be.equal(31);
|
||||||
|
}
|
||||||
|
|
||||||
|
@test
|
||||||
|
async error() {
|
||||||
|
const spy = LoggerSpec.sandbox.on(console, 'error', () => {
|
||||||
|
});
|
||||||
|
|
||||||
|
await Logger.error('Foobar');
|
||||||
|
|
||||||
|
expect(spy).to.have.been.called();
|
||||||
|
expect(spy.__spy.calls[0][0]).to.contain('[ERROR]');
|
||||||
|
expect(spy.__spy.calls[0][0]).to.contain('Foobar');
|
||||||
|
}
|
||||||
|
|
||||||
|
@test
|
||||||
|
async 'error in productive environment'() {
|
||||||
|
const spy = LoggerSpec.sandbox.on(console, 'error', () => {
|
||||||
|
});
|
||||||
|
|
||||||
|
const nodeEnv = process.env.NODE_ENV;
|
||||||
|
process.env.NODE_ENV = 'production';
|
||||||
|
|
||||||
|
await Logger.error('Foobar').should.be.rejectedWith(Error);
|
||||||
|
expect(spy).to.have.been.called.exactly(1);
|
||||||
|
|
||||||
|
process.env.ALLOW_NO_TRANSPORT = 'true';
|
||||||
|
|
||||||
|
await Logger.error('Foobar').should.not.be.rejectedWith(Error);
|
||||||
|
expect(spy).to.have.been.called.exactly(2);
|
||||||
|
|
||||||
|
delete process.env.ALLOW_NO_TRANSPORT;
|
||||||
|
|
||||||
|
Logger.setTransport(new DummyTransport());
|
||||||
|
|
||||||
|
await Logger.error('Foobar').should.not.be.rejectedWith(Error);
|
||||||
|
expect(spy).to.have.been.called.exactly(3);
|
||||||
|
|
||||||
|
Logger.setTransport();
|
||||||
|
|
||||||
|
process.env.NODE_ENV = nodeEnv;
|
||||||
|
}
|
||||||
|
|
||||||
|
@test
|
||||||
|
async 'error without output'() {
|
||||||
|
const spy = LoggerSpec.sandbox.on(console, 'error', () => {
|
||||||
|
});
|
||||||
|
|
||||||
|
process.env.STAPPS_LOG_LEVEL = '0';
|
||||||
|
|
||||||
|
await Logger.error('Foobar');
|
||||||
|
|
||||||
|
delete process.env.STAPPS_LOG_LEVEL;
|
||||||
|
|
||||||
|
expect(spy).not.to.have.been.called();
|
||||||
|
}
|
||||||
|
|
||||||
|
@test
|
||||||
|
async 'error with Error'() {
|
||||||
|
const spy = LoggerSpec.sandbox.on(console, 'error', () => {
|
||||||
|
});
|
||||||
|
|
||||||
|
await Logger.error(new Error());
|
||||||
|
|
||||||
|
expect(spy).to.have.been.called();
|
||||||
|
expect(spy.__spy.calls[0][0]).to.contain('Error');
|
||||||
|
expect(spy.__spy.calls[0][0]).to.contain(process.cwd());
|
||||||
|
}
|
||||||
|
|
||||||
|
@test
|
||||||
|
info() {
|
||||||
|
const spy = LoggerSpec.sandbox.on(console, 'info', () => {
|
||||||
|
});
|
||||||
|
|
||||||
|
Logger.info('Foobar');
|
||||||
|
|
||||||
|
expect(spy).to.have.been.called();
|
||||||
|
expect(spy.__spy.calls[0][0]).to.contain('[INFO]');
|
||||||
|
expect(spy.__spy.calls[0][0]).to.contain('Foobar');
|
||||||
|
}
|
||||||
|
|
||||||
|
@test
|
||||||
|
'info without output'() {
|
||||||
|
const spy = LoggerSpec.sandbox.on(console, 'info', () => {
|
||||||
|
});
|
||||||
|
|
||||||
|
process.env.STAPPS_LOG_LEVEL = '0';
|
||||||
|
|
||||||
|
Logger.info('Foobar');
|
||||||
|
|
||||||
|
delete process.env.STAPPS_LOG_LEVEL;
|
||||||
|
|
||||||
|
expect(spy).not.to.have.been.called;
|
||||||
|
}
|
||||||
|
|
||||||
|
@test
|
||||||
|
initialized() {
|
||||||
|
Logger.setTransport(new DummyTransport());
|
||||||
|
|
||||||
|
expect(() => {
|
||||||
|
Logger.initialized();
|
||||||
|
}).not.to.throw();
|
||||||
|
|
||||||
|
Logger.setTransport();
|
||||||
|
}
|
||||||
|
|
||||||
|
@test
|
||||||
|
'initialized in productive environment'() {
|
||||||
|
const nodeEnv = process.env.NODE_ENV;
|
||||||
|
process.env.NODE_ENV = 'production';
|
||||||
|
|
||||||
|
Logger.setTransport(new DummyTransport());
|
||||||
|
|
||||||
|
expect(() => {
|
||||||
|
Logger.initialized();
|
||||||
|
}).not.to.throw();
|
||||||
|
|
||||||
|
Logger.setTransport();
|
||||||
|
|
||||||
|
expect(() => {
|
||||||
|
Logger.initialized();
|
||||||
|
}).to.throw();
|
||||||
|
|
||||||
|
const spy = LoggerSpec.sandbox.on(console, 'warn', () => {
|
||||||
|
});
|
||||||
|
|
||||||
|
process.env.ALLOW_NO_TRANSPORT = 'true';
|
||||||
|
|
||||||
|
expect(() => {
|
||||||
|
Logger.initialized();
|
||||||
|
}).not.to.throw();
|
||||||
|
|
||||||
|
delete process.env.ALLOW_NO_TRANSPORT;
|
||||||
|
|
||||||
|
expect(spy).to.have.been.called();
|
||||||
|
|
||||||
|
process.env.NODE_ENV = nodeEnv;
|
||||||
|
}
|
||||||
|
|
||||||
|
@test
|
||||||
|
log() {
|
||||||
|
const spy = LoggerSpec.sandbox.on(console, 'log', () => {
|
||||||
|
});
|
||||||
|
|
||||||
|
Logger.log('Foobar');
|
||||||
|
|
||||||
|
expect(spy).to.have.been.called();
|
||||||
|
expect(spy.__spy.calls[0][0]).to.contain('[LOG]');
|
||||||
|
expect(spy.__spy.calls[0][0]).to.contain('Foobar');
|
||||||
|
}
|
||||||
|
|
||||||
|
@test
|
||||||
|
'log without output'() {
|
||||||
|
const spy = LoggerSpec.sandbox.on(console, 'log', () => {
|
||||||
|
});
|
||||||
|
|
||||||
|
process.env.STAPPS_LOG_LEVEL = '0';
|
||||||
|
|
||||||
|
Logger.log('Foobar');
|
||||||
|
|
||||||
|
delete process.env.STAPPS_LOG_LEVEL;
|
||||||
|
|
||||||
|
expect(spy).to.not.have.been.called();
|
||||||
|
}
|
||||||
|
|
||||||
|
@test
|
||||||
|
ok() {
|
||||||
|
const spy = LoggerSpec.sandbox.on(console, 'log', () => {
|
||||||
|
});
|
||||||
|
|
||||||
|
Logger.ok('Foobar');
|
||||||
|
|
||||||
|
expect(spy).to.have.been.called();
|
||||||
|
expect(spy.__spy.calls[0][0]).to.contain('[OK]');
|
||||||
|
expect(spy.__spy.calls[0][0]).to.contain('Foobar');
|
||||||
|
}
|
||||||
|
|
||||||
|
@test
|
||||||
|
'ok without output'() {
|
||||||
|
const spy = LoggerSpec.sandbox.on(console, 'log', () => {
|
||||||
|
});
|
||||||
|
|
||||||
|
process.env.STAPPS_LOG_LEVEL = '0';
|
||||||
|
|
||||||
|
Logger.ok('Foobar');
|
||||||
|
|
||||||
|
delete process.env.STAPPS_LOG_LEVEL;
|
||||||
|
|
||||||
|
expect(spy).not.to.have.been.called()
|
||||||
|
}
|
||||||
|
|
||||||
|
@test
|
||||||
|
setTransport() {
|
||||||
|
expect(() => {
|
||||||
|
Logger.setTransport(new DummyTransport());
|
||||||
|
Logger.setTransport();
|
||||||
|
}).not.to.throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
@test
|
||||||
|
'stringify'() {
|
||||||
|
const spy = LoggerSpec.sandbox.on(console, 'log', () => {
|
||||||
|
});
|
||||||
|
|
||||||
|
Logger.log('foo', 'bar');
|
||||||
|
|
||||||
|
expect(spy).to.have.been.called();
|
||||||
|
expect(spy.__spy.calls[0][0]).to.contain('foo');
|
||||||
|
expect(spy.__spy.calls[0][0]).to.contain('bar');
|
||||||
|
}
|
||||||
|
|
||||||
|
@test
|
||||||
|
'stringify object'() {
|
||||||
|
const spy = LoggerSpec.sandbox.on(console, 'log', () => {
|
||||||
|
});
|
||||||
|
|
||||||
|
Logger.log({
|
||||||
|
foo: 'bar'
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(spy).to.have.been.called();
|
||||||
|
expect(spy.__spy.calls[0][0]).to.contain('foo');
|
||||||
|
expect(spy.__spy.calls[0][0]).to.contain('bar');
|
||||||
|
}
|
||||||
|
|
||||||
|
@test
|
||||||
|
warn() {
|
||||||
|
const spy = LoggerSpec.sandbox.on(console, 'warn', () => {
|
||||||
|
});
|
||||||
|
|
||||||
|
Logger.warn('Foobar');
|
||||||
|
|
||||||
|
expect(spy).to.have.been.called();
|
||||||
|
expect(spy.__spy.calls[0][0]).to.contain('[WARN]');
|
||||||
|
expect(spy.__spy.calls[0][0]).to.contain('Foobar');
|
||||||
|
}
|
||||||
|
|
||||||
|
@test
|
||||||
|
'warn without output'() {
|
||||||
|
const spy = LoggerSpec.sandbox.on(console, 'warn', () => {
|
||||||
|
});
|
||||||
|
|
||||||
|
process.env.STAPPS_LOG_LEVEL = '0';
|
||||||
|
|
||||||
|
Logger.warn('Foobar');
|
||||||
|
|
||||||
|
delete process.env.STAPPS_LOG_LEVEL;
|
||||||
|
|
||||||
|
expect(spy).not.to.have.been.called();
|
||||||
|
}
|
||||||
|
|
||||||
|
@test
|
||||||
|
getLogLevel() {
|
||||||
|
const savedProcess = process;
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
|
process = undefined;
|
||||||
|
|
||||||
|
(global as any).window = {
|
||||||
|
STAPPS_LOG_LEVEL: 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
const stub = LoggerSpec.sandbox.on(console, 'info', () => {
|
||||||
|
});
|
||||||
|
|
||||||
|
Logger.info('Foobar');
|
||||||
|
|
||||||
|
process = savedProcess;
|
||||||
|
|
||||||
|
delete (global as any).window;
|
||||||
|
|
||||||
|
expect(stub).not.to.have.been.called();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,9 +14,7 @@
|
|||||||
*/
|
*/
|
||||||
import {expect} from 'chai';
|
import {expect} from 'chai';
|
||||||
import {slow, suite, test, timeout} from 'mocha-typescript';
|
import {slow, suite, test, timeout} from 'mocha-typescript';
|
||||||
import {SMTP} from '../src/SMTP';
|
import {SMTP} from '../src/smtp';
|
||||||
|
|
||||||
// tslint:disable:no-unused-expression
|
|
||||||
|
|
||||||
@suite(timeout(2000), slow(1000))
|
@suite(timeout(2000), slow(1000))
|
||||||
export class SMTPSpec {
|
export class SMTPSpec {
|
||||||
@@ -15,41 +15,7 @@
|
|||||||
import {expect} from 'chai';
|
import {expect} from 'chai';
|
||||||
import {slow, suite, test, timeout} from 'mocha-typescript';
|
import {slow, suite, test, timeout} from 'mocha-typescript';
|
||||||
import {isTransportWithVerification} from '../src/common';
|
import {isTransportWithVerification} from '../src/common';
|
||||||
import {Transport, VerifiableTransport} from '../src/Transport';
|
import {DummyTransport, VerifiableDummyTransport} from './dummyTransport';
|
||||||
|
|
||||||
export class DummyTransport extends Transport {
|
|
||||||
send(subject: string, message: string): Promise<string> {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
if (0 === 0) {
|
|
||||||
resolve(subject);
|
|
||||||
}
|
|
||||||
|
|
||||||
reject(message);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class VerifiableDummyTransport extends VerifiableTransport {
|
|
||||||
isVerified(): boolean {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
send(subject: string, message: string): Promise<string> {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
if (0 === 0) {
|
|
||||||
resolve(subject);
|
|
||||||
}
|
|
||||||
|
|
||||||
reject(message);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
verify(): Promise<boolean> {
|
|
||||||
return new Promise((resolve) => {
|
|
||||||
resolve(true);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@suite(timeout(2000), slow(1000))
|
@suite(timeout(2000), slow(1000))
|
||||||
export class TransportSpec {
|
export class TransportSpec {
|
||||||
Reference in New Issue
Block a user