mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
Replace tooling-log instances with @kbn/dev-utils (#17324)
This commit is contained in:
parent
abd9ee9848
commit
0f49d67db3
15 changed files with 9 additions and 316 deletions
|
@ -22,10 +22,6 @@ function resolveKibanaPath(path) {
|
|||
return resolve(plugin.kibanaRoot, path);
|
||||
}
|
||||
|
||||
function createToolingLog(level) {
|
||||
return require(resolveKibanaPath('src/dev')).createToolingLog(level);
|
||||
}
|
||||
|
||||
function readFtrConfigFile(log, path, settingOverrides) {
|
||||
return require(resolveKibanaPath('src/functional_test_runner')).readConfigFile(log, path, settingOverrides);
|
||||
}
|
||||
|
@ -33,6 +29,5 @@ function readFtrConfigFile(log, path, settingOverrides) {
|
|||
module.exports = {
|
||||
babelRegister: babelRegister,
|
||||
resolveKibanaPath: resolveKibanaPath,
|
||||
createToolingLog: createToolingLog,
|
||||
readFtrConfigFile: readFtrConfigFile,
|
||||
};
|
||||
};
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
export { createToolingLog } from './tooling_log';
|
||||
export {
|
||||
createAutoJunitReporter,
|
||||
setupJunitReportGeneration,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { createToolingLog, pickLevelFromFlags } from '../tooling_log';
|
||||
import { createToolingLog, pickLevelFromFlags } from '@kbn/dev-utils';
|
||||
import { isFailError } from './fail';
|
||||
import { getFlags, getHelp } from './flags';
|
||||
|
||||
|
|
|
@ -1,87 +0,0 @@
|
|||
import expect from 'expect.js';
|
||||
import Chance from 'chance';
|
||||
|
||||
import {
|
||||
createConcatStream,
|
||||
createPromiseFromStreams
|
||||
} from '../../../utils';
|
||||
|
||||
import { createToolingLog } from '../tooling_log';
|
||||
|
||||
const chance = new Chance();
|
||||
const capture = (level, block) => {
|
||||
const log = createToolingLog(level);
|
||||
block(log);
|
||||
log.end();
|
||||
return createPromiseFromStreams([ log, createConcatStream('') ]);
|
||||
};
|
||||
|
||||
const nothingTest = (logLevel, method) => {
|
||||
describe(`#${method}(...any)`, () => {
|
||||
it('logs nothing', async () => {
|
||||
const output = await capture(logLevel, log => log[method]('foo'));
|
||||
expect(output).to.be('');
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const somethingTest = (logLevel, method) => {
|
||||
describe(`#${method}(...any)`, () => {
|
||||
it('logs to output stream', async () => {
|
||||
const output = await capture(logLevel, log => log[method]('foo'));
|
||||
expect(output).to.contain('foo');
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
describe('utils: createToolingLog(logLevel, output)', () => {
|
||||
it('is a readable stream', async () => {
|
||||
const log = createToolingLog('debug');
|
||||
log.info('Foo');
|
||||
log.info('Bar');
|
||||
log.info('Baz');
|
||||
log.end();
|
||||
|
||||
const output = await createPromiseFromStreams([
|
||||
log,
|
||||
createConcatStream('')
|
||||
]);
|
||||
|
||||
expect(output).to.contain('Foo');
|
||||
expect(output).to.contain('Bar');
|
||||
expect(output).to.contain('Baz');
|
||||
});
|
||||
|
||||
describe('log level', () => {
|
||||
describe('logLevel=silent', () => {
|
||||
nothingTest('silent', 'debug');
|
||||
nothingTest('silent', 'info');
|
||||
nothingTest('silent', 'error');
|
||||
});
|
||||
describe('logLevel=error', () => {
|
||||
nothingTest('error', 'debug');
|
||||
nothingTest('error', 'info');
|
||||
somethingTest('error', 'error');
|
||||
});
|
||||
describe('logLevel=info', () => {
|
||||
nothingTest('info', 'debug');
|
||||
somethingTest('info', 'info');
|
||||
somethingTest('info', 'error');
|
||||
});
|
||||
describe('logLevel=debug', () => {
|
||||
somethingTest('debug', 'debug');
|
||||
somethingTest('debug', 'info');
|
||||
somethingTest('debug', 'error');
|
||||
});
|
||||
describe('invalid logLevel', () => {
|
||||
it('throw error', () => {
|
||||
// avoid the impossiblity that a valid level is generated
|
||||
// by specifying a long length
|
||||
const level = chance.word({ length: 10 });
|
||||
|
||||
expect(() => createToolingLog(level))
|
||||
.to.throwError(level);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,96 +0,0 @@
|
|||
import expect from 'expect.js';
|
||||
import Chance from 'chance';
|
||||
import { parseLogLevel } from '../log_levels';
|
||||
|
||||
const chance = new Chance();
|
||||
|
||||
describe('parseLogLevel(logLevel).flags', () => {
|
||||
describe('logLevel=silent', () => {
|
||||
it('produces correct map', () => {
|
||||
expect(parseLogLevel('silent').flags).to.eql({
|
||||
silent: true,
|
||||
error: false,
|
||||
warning: false,
|
||||
info: false,
|
||||
debug: false,
|
||||
verbose: false,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('logLevel=error', () => {
|
||||
it('produces correct map', () => {
|
||||
expect(parseLogLevel('error').flags).to.eql({
|
||||
silent: true,
|
||||
error: true,
|
||||
warning: false,
|
||||
info: false,
|
||||
debug: false,
|
||||
verbose: false,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('logLevel=warning', () => {
|
||||
it('produces correct map', () => {
|
||||
expect(parseLogLevel('warning').flags).to.eql({
|
||||
silent: true,
|
||||
error: true,
|
||||
warning: true,
|
||||
info: false,
|
||||
debug: false,
|
||||
verbose: false,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('logLevel=info', () => {
|
||||
it('produces correct map', () => {
|
||||
expect(parseLogLevel('info').flags).to.eql({
|
||||
silent: true,
|
||||
error: true,
|
||||
warning: true,
|
||||
info: true,
|
||||
debug: false,
|
||||
verbose: false,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('logLevel=debug', () => {
|
||||
it('produces correct map', () => {
|
||||
expect(parseLogLevel('debug').flags).to.eql({
|
||||
silent: true,
|
||||
error: true,
|
||||
warning: true,
|
||||
info: true,
|
||||
debug: true,
|
||||
verbose: false,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('logLevel=verbose', () => {
|
||||
it('produces correct map', () => {
|
||||
expect(parseLogLevel('verbose').flags).to.eql({
|
||||
silent: true,
|
||||
error: true,
|
||||
warning: true,
|
||||
info: true,
|
||||
debug: true,
|
||||
verbose: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('invalid logLevel', () => {
|
||||
it('throws error', () => {
|
||||
// avoid the impossiblity that a valid level is generated
|
||||
// by specifying a long length
|
||||
const level = chance.word({ length: 10 });
|
||||
|
||||
expect(() => parseLogLevel(level))
|
||||
.to.throwError(level);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,2 +0,0 @@
|
|||
export { createToolingLog } from './tooling_log';
|
||||
export { pickLevelFromFlags } from './log_levels';
|
|
@ -1,36 +0,0 @@
|
|||
|
||||
const LEVELS = [
|
||||
'silent',
|
||||
'error',
|
||||
'warning',
|
||||
'info',
|
||||
'debug',
|
||||
'verbose',
|
||||
];
|
||||
|
||||
export function pickLevelFromFlags(flags) {
|
||||
if (flags.verbose) return 'verbose';
|
||||
if (flags.debug) return 'debug';
|
||||
if (flags.quiet) return 'error';
|
||||
if (flags.silent) return 'silent';
|
||||
return 'info';
|
||||
}
|
||||
|
||||
export function parseLogLevel(name) {
|
||||
const i = LEVELS.indexOf(name);
|
||||
|
||||
if (i === -1) {
|
||||
const msg = (
|
||||
`Invalid log level "${name}" ` +
|
||||
`(expected one of ${LEVELS.join(',')})`
|
||||
);
|
||||
throw new Error(msg);
|
||||
}
|
||||
|
||||
const flags = {};
|
||||
LEVELS.forEach((level, levelI) => {
|
||||
flags[level] = levelI <= i;
|
||||
});
|
||||
|
||||
return { name, flags };
|
||||
}
|
|
@ -1,80 +0,0 @@
|
|||
import { format } from 'util';
|
||||
import { PassThrough } from 'stream';
|
||||
|
||||
import { magentaBright, yellow, red, blue, green, dim } from 'chalk';
|
||||
|
||||
import { parseLogLevel } from './log_levels';
|
||||
|
||||
export function createToolingLog(initialLogLevelName = 'silent') {
|
||||
// current log level (see logLevel.name and logLevel.flags) changed
|
||||
// with ToolingLog#setLevel(newLogLevelName);
|
||||
let logLevel = parseLogLevel(initialLogLevelName);
|
||||
|
||||
// current indentation level, changed with ToolingLog#indent(delta)
|
||||
let indentString = '';
|
||||
|
||||
class ToolingLog extends PassThrough {
|
||||
constructor() {
|
||||
super({ objectMode: true });
|
||||
}
|
||||
|
||||
verbose(...args) {
|
||||
if (!logLevel.flags.verbose) return;
|
||||
this.write(' %s ', magentaBright('sill'), format(...args));
|
||||
}
|
||||
|
||||
debug(...args) {
|
||||
if (!logLevel.flags.debug) return;
|
||||
this.write(' %s ', dim('debg'), format(...args));
|
||||
}
|
||||
|
||||
info(...args) {
|
||||
if (!logLevel.flags.info) return;
|
||||
this.write(' %s ', blue('info'), format(...args));
|
||||
}
|
||||
|
||||
success(...args) {
|
||||
if (!logLevel.flags.info) return;
|
||||
this.write(' %s ', green('succ'), format(...args));
|
||||
}
|
||||
|
||||
warning(...args) {
|
||||
if (!logLevel.flags.warning) return;
|
||||
this.write(' %s ', yellow('warn'), format(...args));
|
||||
}
|
||||
|
||||
error(err) {
|
||||
if (!logLevel.flags.error) return;
|
||||
|
||||
if (typeof err !== 'string' && !(err instanceof Error)) {
|
||||
err = new Error(`"${err}" thrown`);
|
||||
}
|
||||
|
||||
this.write('%s ', red('ERROR'), err.stack || err.message || err);
|
||||
}
|
||||
|
||||
indent(delta = 0) {
|
||||
const width = Math.max(0, indentString.length + delta);
|
||||
indentString = ' '.repeat(width);
|
||||
return indentString.length;
|
||||
}
|
||||
|
||||
getLevel() {
|
||||
return logLevel.name;
|
||||
}
|
||||
|
||||
setLevel(newLogLevelName) {
|
||||
logLevel = parseLogLevel(newLogLevelName);
|
||||
}
|
||||
|
||||
write(...args) {
|
||||
format(...args).split('\n').forEach((line, i) => {
|
||||
const subLineIndent = i === 0 ? '' : ' ';
|
||||
const indent = !indentString ? '' : indentString.slice(0, -1) + (i === 0 && line[0] === '-' ? '└' : '│');
|
||||
super.write(`${indent}${subLineIndent}${line}\n`);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return new ToolingLog();
|
||||
}
|
|
@ -12,7 +12,7 @@ import { Command } from 'commander';
|
|||
import elasticsearch from 'elasticsearch';
|
||||
|
||||
import { EsArchiver } from './es_archiver';
|
||||
import { createToolingLog } from '../dev';
|
||||
import { createToolingLog } from '@kbn/dev-utils';
|
||||
import { readConfigFile } from '../functional_test_runner';
|
||||
|
||||
const cmd = new Command('node scripts/es_archiver');
|
||||
|
|
|
@ -3,7 +3,7 @@ import { uniq } from 'lodash';
|
|||
import sinon from 'sinon';
|
||||
|
||||
import { createStats } from '../';
|
||||
import { createToolingLog } from '../../../dev';
|
||||
import { createToolingLog } from '@kbn/dev-utils';
|
||||
import {
|
||||
createConcatStream,
|
||||
createPromiseFromStreams
|
||||
|
|
|
@ -4,7 +4,7 @@ import { resolve } from 'path';
|
|||
import expect from 'expect.js';
|
||||
|
||||
import { readConfigFile } from '../../lib';
|
||||
import { createToolingLog } from '../../../dev';
|
||||
import { createToolingLog } from '@kbn/dev-utils';
|
||||
import { createReduceStream } from '../../../utils';
|
||||
import { createTestCluster } from '../../../test_utils/es';
|
||||
import { startupKibana } from '../lib';
|
||||
|
|
|
@ -2,7 +2,7 @@ import { resolve } from 'path';
|
|||
|
||||
import { Command } from 'commander';
|
||||
|
||||
import { createToolingLog } from '../dev';
|
||||
import { createToolingLog } from '@kbn/dev-utils';
|
||||
import { createFunctionalTestRunner } from './functional_test_runner';
|
||||
|
||||
const cmd = new Command('node scripts/functional_test_runner');
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import expect from 'expect.js';
|
||||
|
||||
import { createToolingLog } from '../../../../dev';
|
||||
import { createToolingLog } from '@kbn/dev-utils';
|
||||
import { readConfigFile } from '../read_config_file';
|
||||
import { Config } from '../config';
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ import expect from 'expect.js';
|
|||
|
||||
import { createTestCluster } from '../../../../test_utils/es';
|
||||
import { createServerWithCorePlugins } from '../../../../test_utils/kbn_server';
|
||||
import { createToolingLog } from '../../../../dev';
|
||||
import { createToolingLog } from '@kbn/dev-utils';
|
||||
import { createOrUpgradeSavedConfig } from '../create_or_upgrade_saved_config';
|
||||
|
||||
describe('createOrUpgradeSavedConfig()', () => {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { createFunctionalTestRunner } from '../src/functional_test_runner';
|
||||
import { createToolingLog } from '../src/dev';
|
||||
import { createToolingLog } from '@kbn/dev-utils';
|
||||
|
||||
export default function (grunt) {
|
||||
grunt.registerMultiTask('functional_test_runner', 'run tests with the functional test runner', function () {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue