mirror of
				https://github.com/Unleash/unleash.git
				synced 2025-10-27 11:02:16 +01:00 
			
		
		
		
	fix: cleanup test console output
This commit is contained in:
		
							parent
							
								
									e279a700b8
								
							
						
					
					
						commit
						203036192d
					
				@ -1,6 +1,6 @@
 | 
			
		||||
/* eslint camelcase:off */
 | 
			
		||||
 | 
			
		||||
'use strict';
 | 
			
		||||
const NotFoundError = require('../error/notfound-error');
 | 
			
		||||
 | 
			
		||||
const COLUMNS = [
 | 
			
		||||
    'app_name',
 | 
			
		||||
@ -84,6 +84,10 @@ class ClientApplicationsDb {
 | 
			
		||||
            .from(TABLE)
 | 
			
		||||
            .first();
 | 
			
		||||
 | 
			
		||||
        if (!row) {
 | 
			
		||||
            throw new NotFoundError(`Could not find appName=${appName}`);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return mapRow(row);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -43,6 +43,7 @@ test.cb('should call database on startup', t => {
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
test.cb('should start poller even if inital database fetch fails', t => {
 | 
			
		||||
    getLogger.setMuteError(true);
 | 
			
		||||
    const clock = lolex.install();
 | 
			
		||||
    const mock = getMockDb();
 | 
			
		||||
    mock.getMetricsLastHour = () => Promise.reject(new Error('oops'));
 | 
			
		||||
@ -62,6 +63,7 @@ test.cb('should start poller even if inital database fetch fails', t => {
 | 
			
		||||
            t.end();
 | 
			
		||||
        });
 | 
			
		||||
    });
 | 
			
		||||
    getLogger.setMuteError(false);
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
test.cb('should poll for updates', t => {
 | 
			
		||||
 | 
			
		||||
@ -83,7 +83,7 @@ class MetricsController extends Controller {
 | 
			
		||||
        try {
 | 
			
		||||
            await this.clientApplicationsStore.getApplication(appName);
 | 
			
		||||
        } catch (e) {
 | 
			
		||||
            this.logger.error(e);
 | 
			
		||||
            this.logger.warn(e);
 | 
			
		||||
            res.status(409).end();
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@ -36,6 +36,10 @@ function getSetup() {
 | 
			
		||||
    };
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
test.afterEach(() => {
 | 
			
		||||
    getLogger.setMuteError(false);
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
test('add version numbers for /stategies', t => {
 | 
			
		||||
    t.plan(1);
 | 
			
		||||
    const { request, base } = getSetup();
 | 
			
		||||
@ -142,6 +146,7 @@ test('validate format when updating strategy', t => {
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
test('editable=false will stop delete request', t => {
 | 
			
		||||
    getLogger.setMuteError(true);
 | 
			
		||||
    t.plan(0);
 | 
			
		||||
    const name = 'default';
 | 
			
		||||
    const { request, base, perms } = getSetup();
 | 
			
		||||
@ -151,6 +156,7 @@ test('editable=false will stop delete request', t => {
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
test('editable=false will stop edit request', t => {
 | 
			
		||||
    getLogger.setMuteError(true);
 | 
			
		||||
    t.plan(0);
 | 
			
		||||
    const name = 'default';
 | 
			
		||||
    const { request, base, perms } = getSetup();
 | 
			
		||||
 | 
			
		||||
@ -24,6 +24,10 @@ function getSetup() {
 | 
			
		||||
    };
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
test.afterEach(() => {
 | 
			
		||||
    getLogger.setMuteError(false);
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
test('should register client', t => {
 | 
			
		||||
    t.plan(0);
 | 
			
		||||
    const { request } = getSetup();
 | 
			
		||||
@ -78,6 +82,7 @@ test('should require strategies field', t => {
 | 
			
		||||
 | 
			
		||||
test('should fail if store fails', t => {
 | 
			
		||||
    t.plan(0);
 | 
			
		||||
    getLogger.setMuteError(true);
 | 
			
		||||
 | 
			
		||||
    // --- start custom config
 | 
			
		||||
    const stores = store.createStores();
 | 
			
		||||
 | 
			
		||||
@ -25,7 +25,12 @@ function getSetup() {
 | 
			
		||||
    };
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
test.afterEach(() => {
 | 
			
		||||
    getLogger.setMuteError(false);
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
test('should give 500 when db is failing', t => {
 | 
			
		||||
    getLogger.setMuteError(true);
 | 
			
		||||
    t.plan(2);
 | 
			
		||||
    const { request, db } = getSetup();
 | 
			
		||||
    db.select = () => ({
 | 
			
		||||
 | 
			
		||||
@ -81,6 +81,7 @@ module.exports = async function init(databaseSchema = 'test', getLogger) {
 | 
			
		||||
    await migrator(options);
 | 
			
		||||
    await db.destroy();
 | 
			
		||||
    const stores = await createStores(options, eventBus);
 | 
			
		||||
    stores.clientMetricsStore.setMaxListeners(0);
 | 
			
		||||
    await resetDatabase(stores);
 | 
			
		||||
    await setupDatabase(stores);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										5
									
								
								test/fixtures/fake-metrics-store.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										5
									
								
								test/fixtures/fake-metrics-store.js
									
									
									
									
										vendored
									
									
								
							@ -3,6 +3,11 @@
 | 
			
		||||
const { EventEmitter } = require('events');
 | 
			
		||||
 | 
			
		||||
class FakeMetricsStore extends EventEmitter {
 | 
			
		||||
    constructor() {
 | 
			
		||||
        super();
 | 
			
		||||
        this.setMaxListeners(0);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    getMetricsLastHour() {
 | 
			
		||||
        return Promise.resolve([]);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										12
									
								
								test/fixtures/no-logger.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										12
									
								
								test/fixtures/no-logger.js
									
									
									
									
										vendored
									
									
								
							@ -1,13 +1,19 @@
 | 
			
		||||
/* eslint-disable no-console */
 | 
			
		||||
 | 
			
		||||
'use strict';
 | 
			
		||||
let muteError = false;
 | 
			
		||||
 | 
			
		||||
module.exports = function noLoggerProvider() {
 | 
			
		||||
function noLoggerProvider() {
 | 
			
		||||
    // do something with the name
 | 
			
		||||
    return {
 | 
			
		||||
        debug: () => {},
 | 
			
		||||
        info: () => {},
 | 
			
		||||
        warn: () => {},
 | 
			
		||||
        error: console.error,
 | 
			
		||||
        error: muteError ? () => {} : console.error,
 | 
			
		||||
    };
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
noLoggerProvider.setMuteError = mute => {
 | 
			
		||||
    muteError = mute;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
module.exports = noLoggerProvider;
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user