Skip to content

Commit

Permalink
[FTR] Refactor mocha under @kbn/test (elastic#42862) (elastic#83369)
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.

Co-authored-by: Tre <wayne.seymour@elastic.co>
  • Loading branch information
Tyler Smalley and wayneseymour authored Nov 13, 2020
1 parent 74dfc79 commit 2a0f465
Show file tree
Hide file tree
Showing 13 changed files with 17 additions and 48 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.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ export { readConfigFile } from './functional_test_runner/lib/config/read_config_

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

export {
createAutoJUnitReporter,
runMochaCli,
setupJUnitReportGeneration,
escapeCdata,
} from './mocha';

export { runFailedTestsReporterCli } from './failed_tests_reporter';

export { CI_PARALLEL_PROCESS_PREFIX } from './ci_parallel_process_prefix';
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ export { createAutoJUnitReporter } from './auto_junit_reporter';
export { setupJUnitReportGeneration } from './junit_report_generation';
// @ts-ignore not typed yet
export { runMochaCli } from './run_mocha_cli';
// @ts-ignore not typed yet
export { recordLog, snapshotLogsForRunnable } from './log_cache';
// @ts-ignore not typed yet
export { escapeCdata } from './xml';
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ import xmlBuilder from 'xmlbuilder';
import { getUniqueJunitReportPath } from '@kbn/test';

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')),
getTestMetadata = () => ({}),
} = options;

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,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
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
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 @@ -17,6 +17,6 @@
* under the License.
*/

export { createAutoJUnitReporter, setupJUnitReportGeneration } from './mocha';
export { createAutoJUnitReporter, setupJUnitReportGeneration } from '@kbn/test';

export { generateNoticeFromSource } from './notice';
38 changes: 0 additions & 38 deletions src/dev/xml.ts

This file was deleted.

0 comments on commit 2a0f465

Please sign in to comment.