Skip to content

Commit

Permalink
[FTR] Refactor mocha under @kbn/test (#42862)
Browse files Browse the repository at this point in the history
* Run prettier on the files that will be refactored under @kbn/test, in a follow-up pr.

* Fixup all paths to mocha,
under kbn-test, with needed
exports/imports.

* Fixed borked path (bad refactor).

* Fixup one more borked path.

* Fixup tsconfig for xml.ts

* Drop setup_node_env as it's already
in KIBANA/scripts/mocha.js.
Also, fixup cwd for globby as we are
exec-ing from a different directory.
  • Loading branch information
wayneseymour authored Aug 15, 2019
1 parent 90892da commit 5d8ad40
Show file tree
Hide file tree
Showing 15 changed files with 19 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@ import Mocha from 'mocha';
import { ToolingLogTextWriter } from '@kbn/dev-utils';
import moment from 'moment';

import { setupJUnitReportGeneration } from '../../../../../../../src/dev';
import { recordLog, snapshotLogsForRunnable, setupJUnitReportGeneration } from '../../../../mocha';
import * as colors from './colors';
import * as symbols from './symbols';
import { ms } from './ms';
import { writeEpilogue } from './write_epilogue';
import { recordLog, snapshotLogsForRunnable } from '../../../../../../../src/dev/mocha/log_cache';

export function MochaReporterProvider({ getService }) {
const log = getService('log');
Expand Down
7 changes: 7 additions & 0 deletions packages/kbn-test/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,10 @@ export { setupUsers, DEFAULT_SUPERUSER_PASS } from './functional_tests/lib/auth'
export { readConfigFile } from './functional_test_runner/lib/config/read_config_file';

export { runFtrCli } from './functional_test_runner/cli';

export {
createAutoJUnitReporter,
runMochaCli,
setupJUnitReportGeneration,
escapeCdata,
} from './mocha';
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@
export { createAutoJUnitReporter } from './auto_junit_reporter';
export { setupJUnitReportGeneration } from './junit_report_generation';
export { runMochaCli } from './run_mocha_cli';
export { recordLog, snapshotLogsForRunnable } from './log_cache';
export { escapeCdata } from './xml';
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ import mkdirp from 'mkdirp';
import xmlBuilder from 'xmlbuilder';

import { getSnapshotOfRunnableLogs } from './log_cache';
import { escapeCdata } from '../xml';
import { escapeCdata } from '../';

const dateNow = Date.now.bind(Date);

export function setupJUnitReportGeneration(runner, options = {}) {
const {
reportName = 'Unnamed Mocha Tests',
rootDirectory = dirname(require.resolve('../../../package.json')),
rootDirectory = dirname(require.resolve('../../../../package.json')),
} = options;

const stats = {};
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ export function runMochaCli() {
// prevent globals injected from canvas plugins from triggering leak check
process.argv.push('--globals', '__core-js_shared__,core,_, ');

// ensure that mocha requires the setup_node_env script
process.argv.push('--require', require.resolve('../../setup_node_env'));

// set default test timeout
if (opts.timeout == null && !opts['no-timeouts']) {
if (runInBand) {
Expand Down Expand Up @@ -76,7 +73,7 @@ export function runMochaCli() {
'tasks/**/__tests__/**/*.js',
],
{
cwd: resolve(__dirname, '../../..'),
cwd: resolve(__dirname, '../../../..'),
onlyFiles: true,
absolute: true,
ignore: ['**/__tests__/fixtures/**', 'src/**/public/**', '**/_*.js'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

// when the reporter is loaded by mocha in child process it might be before setup_node_env
require('../../setup_node_env');
require('../../../../src/setup_node_env');

module.exports = require('./auto_junit_reporter').createAutoJUnitReporter({
reportName: 'Server Mocha Tests',
Expand Down
File renamed without changes.
3 changes: 2 additions & 1 deletion packages/kbn-test/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"extends": "../../tsconfig.json",
"include": [
"types/**/*",
"src/functional_test_runner/**/*"
"src/functional_test_runner/**/*",
"src/mocha/xml.ts"
]
}
2 changes: 1 addition & 1 deletion scripts/mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
*/

require('../src/setup_node_env');
require('../src/dev/mocha').runMochaCli();
require('@kbn/test').runMochaCli();
2 changes: 1 addition & 1 deletion src/dev/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
export {
createAutoJUnitReporter,
setupJUnitReportGeneration,
} from './mocha';
} from '@kbn/test';

export {
generateNoticeFromSource,
Expand Down
2 changes: 1 addition & 1 deletion src/dev/jest/junit_reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { writeFileSync } from 'fs';
import mkdirp from 'mkdirp';
import xmlBuilder from 'xmlbuilder';

import { escapeCdata } from '../xml';
import { escapeCdata } from '@kbn/test';

const ROOT_DIR = dirname(require.resolve('../../../package.json'));

Expand Down

0 comments on commit 5d8ad40

Please sign in to comment.