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