mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
* [mocha] run tests with mocha script, remove grunt-simple-mocha * [ci] force colored output * [ci] disable color when reading the yarn bin * [dev/build/exec] support tooling log having its own chalk * [dev/mocha] avoid changing the cwd of the process * [dev/mocha] only match files, speed up negative matches * [cli/serve/test] strip ansi control characters from logs * [ci] disable color in all `yarn bin` invocations * [dev/mocha] cleanup old runInBand check * [dev/mocha] enable gloabl leak checks
This commit is contained in:
parent
01d786359e
commit
7dbec2e1e7
19 changed files with 111 additions and 80 deletions
|
@ -259,7 +259,6 @@
|
|||
"grunt-karma": "2.0.0",
|
||||
"grunt-peg": "^2.0.1",
|
||||
"grunt-run": "0.7.0",
|
||||
"grunt-simple-mocha": "0.4.0",
|
||||
"gulp-babel": "^7.0.1",
|
||||
"gulp-sourcemaps": "1.7.3",
|
||||
"husky": "0.8.1",
|
||||
|
|
|
@ -51,7 +51,7 @@ Today a package can follow the pattern of having a `__tests__` directory in each
|
|||
If a package's tests should be run with Mocha, you'll have to opt-in to run them by appending the package's test file pattern(s) to Kibana's `tasks/config/simplemocha.js` file. These will then be run by the unit test runner.
|
||||
|
||||
* `yarn test` or `yarn grunt test` runs all unit tests.
|
||||
* `yarn grunt simplemocha:all` runs all Mocha tests.
|
||||
* `node scripts/mocha` runs all Mocha tests.
|
||||
|
||||
### 2. Jest
|
||||
A package can also follow the pattern of having `.test.js` files as siblings of the source code files, and these run by Jest.
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
require('../src/babel-register');
|
||||
require('../test/scripts/run_mocha');
|
||||
require('../src/dev/mocha').runMochaCli();
|
||||
|
|
|
@ -3,6 +3,7 @@ import { writeFileSync } from 'fs';
|
|||
import { relative, resolve } from 'path';
|
||||
import { safeDump } from 'js-yaml';
|
||||
import es from 'event-stream';
|
||||
import stripAnsi from 'strip-ansi';
|
||||
import { readYamlConfig } from '../read_yaml_config';
|
||||
|
||||
const testConfigFile = follow('__fixtures__/reload_logging_config/kibana.test.yml');
|
||||
|
@ -29,10 +30,10 @@ const prepareJson = obj => ({
|
|||
});
|
||||
|
||||
const prepareLogLine = str =>
|
||||
str.replace(
|
||||
stripAnsi(str.replace(
|
||||
/\[\d{2}:\d{2}:\d{2}.\d{3}\]/,
|
||||
'[## timestamp ##]'
|
||||
);
|
||||
));
|
||||
|
||||
describe('Server logging configuration', function () {
|
||||
let child;
|
||||
|
|
|
@ -1,23 +1,18 @@
|
|||
import { resolve } from 'path';
|
||||
|
||||
import sinon from 'sinon';
|
||||
import chalk from 'chalk';
|
||||
import stripAnsi from 'strip-ansi';
|
||||
|
||||
import { createToolingLog } from '../../../tooling_log';
|
||||
import { exec } from '../exec';
|
||||
|
||||
describe('dev/build/lib/exec', () => {
|
||||
// disable colors so logging is easier to test
|
||||
const chalkWasEnabled = chalk.enabled;
|
||||
before(() => chalk.enabled = false);
|
||||
after(() => chalk.enabled = chalkWasEnabled);
|
||||
|
||||
const sandbox = sinon.sandbox.create();
|
||||
afterEach(() => sandbox.reset());
|
||||
|
||||
const log = createToolingLog('verbose');
|
||||
const onLogLine = sandbox.stub();
|
||||
log.on('data', onLogLine);
|
||||
log.on('data', line => onLogLine(stripAnsi(line)));
|
||||
|
||||
it('executes a command, logs the command, and logs the output', async () => {
|
||||
await exec(log, process.execPath, ['-e', 'console.log("hi")']);
|
||||
|
|
|
@ -5,6 +5,14 @@ set -e
|
|||
dir="$(pwd)"
|
||||
cacheDir="${CACHE_DIR:-"$HOME/.kibana"}"
|
||||
|
||||
###
|
||||
### Since the Jenkins logging output collector doesn't look like a TTY
|
||||
### Node/Chalk and other color libs disable their color output. But Jenkins
|
||||
### can handle color fine, so this forces https://github.com/chalk/supports-color
|
||||
### to enable color support in Chalk and other related modules.
|
||||
###
|
||||
export FORCE_COLOR=1
|
||||
|
||||
###
|
||||
### check that we seem to be in a kibana project
|
||||
###
|
||||
|
|
|
@ -4,7 +4,7 @@ import { setupJunitReportGeneration } from './junit_report_generation';
|
|||
const MochaSpecReporter = mocha.reporters.spec;
|
||||
|
||||
export function createAutoJunitReporter(junitReportOptions) {
|
||||
return class createAutoJunitReporter {
|
||||
return class AutoJunitReporter {
|
||||
constructor(runner, options) {
|
||||
// setup a spec reporter for console output
|
||||
new MochaSpecReporter(runner, options);
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
export { createAutoJunitReporter } from './auto_junit_reporter';
|
||||
export { setupJunitReportGeneration } from './junit_report_generation';
|
||||
export { runMochaCli } from './run_mocha_cli';
|
||||
|
|
75
src/dev/mocha/run_mocha_cli.js
Normal file
75
src/dev/mocha/run_mocha_cli.js
Normal file
|
@ -0,0 +1,75 @@
|
|||
import { resolve } from 'path';
|
||||
|
||||
import getopts from 'getopts';
|
||||
import globby from 'globby';
|
||||
|
||||
export function runMochaCli() {
|
||||
const opts = getopts(process.argv.slice(2), {
|
||||
alias: {
|
||||
t: 'timeout',
|
||||
},
|
||||
boolean: [
|
||||
'no-timeouts'
|
||||
],
|
||||
});
|
||||
|
||||
const runInBand = (
|
||||
process.execArgv.includes('--inspect') ||
|
||||
process.execArgv.includes('--inspect-brk')
|
||||
);
|
||||
|
||||
// ensure that mocha exits when test have completed
|
||||
process.argv.push('--exit');
|
||||
|
||||
// check that we aren't leaking any globals
|
||||
process.argv.push('--check-leaks');
|
||||
|
||||
// ensure that mocha requires the babel-register script
|
||||
process.argv.push('--require', require.resolve('../../babel-register'));
|
||||
|
||||
// set default test timeout
|
||||
if (opts.timeout == null && !opts['no-timeouts']) {
|
||||
if (runInBand) {
|
||||
process.argv.push('--no-timeouts');
|
||||
} else {
|
||||
process.argv.push('--timeout', '10000');
|
||||
}
|
||||
}
|
||||
|
||||
// set default slow timeout
|
||||
if (opts.slow == null) {
|
||||
process.argv.push('--slow', '5000');
|
||||
}
|
||||
|
||||
// set default reporter
|
||||
if (opts.reporter == null) {
|
||||
process.argv.push('--reporter', require.resolve('./server_junit_reporter'));
|
||||
}
|
||||
|
||||
// set default test files
|
||||
if (!opts._.length) {
|
||||
globby.sync([
|
||||
'src/**/__tests__/**/*.js',
|
||||
'packages/kbn-datemath/test/**/*.js',
|
||||
'packages/kbn-dev-utils/src/**/__tests__/**/*.js',
|
||||
'tasks/**/__tests__/**/*.js',
|
||||
], {
|
||||
cwd: resolve(__dirname, '../../..'),
|
||||
onlyFiles: true,
|
||||
absolute: true,
|
||||
ignore: [
|
||||
'**/__tests__/fixtures/**',
|
||||
'src/**/public/**',
|
||||
'**/_*.js'
|
||||
]
|
||||
}).forEach(file => {
|
||||
process.argv.push(file);
|
||||
});
|
||||
}
|
||||
|
||||
if (runInBand) {
|
||||
require('mocha/bin/_mocha');
|
||||
} else {
|
||||
require('mocha/bin/mocha');
|
||||
}
|
||||
}
|
6
src/dev/mocha/server_junit_reporter.js
Normal file
6
src/dev/mocha/server_junit_reporter.js
Normal file
|
@ -0,0 +1,6 @@
|
|||
// when the reporter is loaded by mocha in child process it might be before babel-register
|
||||
require('../../babel-register');
|
||||
|
||||
module.exports = require('./auto_junit_reporter').createAutoJunitReporter({
|
||||
reportName: 'Server Mocha Tests',
|
||||
});
|
|
@ -74,6 +74,15 @@ module.exports = function (grunt) {
|
|||
]
|
||||
},
|
||||
|
||||
// used by the test:server task
|
||||
// runs all node.js/server mocha tests
|
||||
mocha: {
|
||||
cmd: process.execPath,
|
||||
args: [
|
||||
require.resolve('../../scripts/mocha')
|
||||
]
|
||||
},
|
||||
|
||||
// used by the test:api task
|
||||
// runs the kibana server prepared for the api_integration tests
|
||||
apiTestServer: createKbnServerTask({
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
import { createAutoJunitReporter } from '../../src/dev';
|
||||
|
||||
export default {
|
||||
options: {
|
||||
timeout: 10000,
|
||||
slow: 5000,
|
||||
ignoreLeaks: false,
|
||||
reporter: createAutoJunitReporter({
|
||||
reportName: 'Server Mocha Tests',
|
||||
}),
|
||||
globals: ['nil'],
|
||||
},
|
||||
all: {
|
||||
src: [
|
||||
'test/**/__tests__/**/*.js',
|
||||
'src/**/__tests__/**/*.js',
|
||||
'packages/kbn-pm/**/__tests__/**/*.js',
|
||||
'packages/kbn-datemath/test/**/*.js',
|
||||
'packages/kbn-dev-utils/**/__tests__/**/*.js',
|
||||
'tasks/**/__tests__/**/*.js',
|
||||
'test/fixtures/__tests__/*.js',
|
||||
'!**/__tests__/fixtures/**/*',
|
||||
'!src/**/public/**',
|
||||
'!**/_*.js',
|
||||
],
|
||||
},
|
||||
};
|
|
@ -14,7 +14,7 @@ module.exports = function (grunt) {
|
|||
|
||||
grunt.registerTask('test:server', [
|
||||
'checkPlugins',
|
||||
'simplemocha:all',
|
||||
'run:mocha',
|
||||
]);
|
||||
|
||||
grunt.registerTask('test:browser', [
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
--require src/babel-register
|
|
@ -3,4 +3,4 @@
|
|||
set -e
|
||||
source "$(dirname $0)/../../src/dev/ci_setup/setup.sh"
|
||||
|
||||
"$(yarn bin)/grunt" jenkins:docs;
|
||||
"$(FORCE_COLOR=0 yarn bin)/grunt" jenkins:docs;
|
||||
|
|
|
@ -7,4 +7,4 @@ source "$(dirname $0)/../../src/dev/ci_setup/java_setup.sh"
|
|||
|
||||
node scripts/build --release --debug --oss;
|
||||
|
||||
xvfb-run "$(yarn bin)/grunt" jenkins:selenium --from=source;
|
||||
xvfb-run "$(FORCE_COLOR=0 yarn bin)/grunt" jenkins:selenium --from=source;
|
||||
|
|
|
@ -6,4 +6,4 @@ source "$(dirname $0)/../../src/dev/ci_setup/git_setup.sh"
|
|||
source "$(dirname $0)/../../src/dev/ci_setup/java_setup.sh"
|
||||
|
||||
export TEST_ES_FROM=source
|
||||
xvfb-run "$(yarn bin)/grunt" jenkins:unit --from=source;
|
||||
xvfb-run "$(FORCE_COLOR=0 yarn bin)/grunt" jenkins:unit --from=source;
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
const debugInBand = process.execArgv.some(arg => {
|
||||
switch (arg) {
|
||||
case '--inspect':
|
||||
case '--inspect-brk':
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
if (debugInBand) {
|
||||
process.argv.push('--no-timeouts');
|
||||
require('mocha/bin/_mocha');
|
||||
} else {
|
||||
require('mocha/bin/mocha');
|
||||
}
|
21
yarn.lock
21
yarn.lock
|
@ -5378,12 +5378,6 @@ grunt-run@0.7.0:
|
|||
lodash "^3.10.0"
|
||||
strip-ansi "^3.0.0"
|
||||
|
||||
grunt-simple-mocha@0.4.0:
|
||||
version "0.4.0"
|
||||
resolved "https://registry.yarnpkg.com/grunt-simple-mocha/-/grunt-simple-mocha-0.4.0.tgz#bdf4c1b26d93cf938a875481c1786211faad7ac0"
|
||||
dependencies:
|
||||
mocha "*"
|
||||
|
||||
grunt@1.0.1:
|
||||
version "1.0.1"
|
||||
resolved "https://registry.yarnpkg.com/grunt/-/grunt-1.0.1.tgz#e8778764e944b18f32bb0f10b9078475c9dfb56b"
|
||||
|
@ -8358,21 +8352,6 @@ mkdirp@^0.3.5, mkdirp@~0.3.5:
|
|||
version "0.3.5"
|
||||
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.3.5.tgz#de3e5f8961c88c787ee1368df849ac4413eca8d7"
|
||||
|
||||
mocha@*:
|
||||
version "5.0.4"
|
||||
resolved "https://registry.yarnpkg.com/mocha/-/mocha-5.0.4.tgz#6b7aa328472da1088e69d47e75925fd3a3bb63c6"
|
||||
dependencies:
|
||||
browser-stdout "1.3.1"
|
||||
commander "2.11.0"
|
||||
debug "3.1.0"
|
||||
diff "3.5.0"
|
||||
escape-string-regexp "1.0.5"
|
||||
glob "7.1.2"
|
||||
growl "1.10.3"
|
||||
he "1.1.1"
|
||||
mkdirp "0.5.1"
|
||||
supports-color "4.4.0"
|
||||
|
||||
mocha@^5.0.5:
|
||||
version "5.1.1"
|
||||
resolved "https://registry.yarnpkg.com/mocha/-/mocha-5.1.1.tgz#b774c75609dac05eb48f4d9ba1d827b97fde8a7b"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue