diff --git a/packages/kbn-test/src/functional_test_runner/lib/mocha/reporter/reporter.js b/packages/kbn-test/src/functional_test_runner/lib/mocha/reporter/reporter.js index 9f89efddf49ba..f4200d6f47574 100644 --- a/packages/kbn-test/src/functional_test_runner/lib/mocha/reporter/reporter.js +++ b/packages/kbn-test/src/functional_test_runner/lib/mocha/reporter/reporter.js @@ -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'); diff --git a/packages/kbn-test/src/index.ts b/packages/kbn-test/src/index.ts index 2afa28b3408c8..a57b92fbdde25 100644 --- a/packages/kbn-test/src/index.ts +++ b/packages/kbn-test/src/index.ts @@ -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'; diff --git a/src/dev/mocha/__tests__/fixtures/project/test.js b/packages/kbn-test/src/mocha/__tests__/fixtures/project/test.js similarity index 100% rename from src/dev/mocha/__tests__/fixtures/project/test.js rename to packages/kbn-test/src/mocha/__tests__/fixtures/project/test.js diff --git a/src/dev/mocha/__tests__/junit_report_generation.js b/packages/kbn-test/src/mocha/__tests__/junit_report_generation.js similarity index 100% rename from src/dev/mocha/__tests__/junit_report_generation.js rename to packages/kbn-test/src/mocha/__tests__/junit_report_generation.js diff --git a/src/dev/mocha/auto_junit_reporter.js b/packages/kbn-test/src/mocha/auto_junit_reporter.js similarity index 100% rename from src/dev/mocha/auto_junit_reporter.js rename to packages/kbn-test/src/mocha/auto_junit_reporter.js diff --git a/src/dev/mocha/index.js b/packages/kbn-test/src/mocha/index.ts similarity index 87% rename from src/dev/mocha/index.js rename to packages/kbn-test/src/mocha/index.ts index 4586cc2a2ff76..99c0f6f4230b7 100644 --- a/src/dev/mocha/index.js +++ b/packages/kbn-test/src/mocha/index.ts @@ -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'; diff --git a/src/dev/mocha/junit_report_generation.js b/packages/kbn-test/src/mocha/junit_report_generation.js similarity index 97% rename from src/dev/mocha/junit_report_generation.js rename to packages/kbn-test/src/mocha/junit_report_generation.js index 096d82778ca42..9ac9bd18548f4 100644 --- a/src/dev/mocha/junit_report_generation.js +++ b/packages/kbn-test/src/mocha/junit_report_generation.js @@ -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; diff --git a/src/dev/mocha/log_cache.js b/packages/kbn-test/src/mocha/log_cache.js similarity index 100% rename from src/dev/mocha/log_cache.js rename to packages/kbn-test/src/mocha/log_cache.js diff --git a/src/dev/mocha/run_mocha_cli.js b/packages/kbn-test/src/mocha/run_mocha_cli.js similarity index 95% rename from src/dev/mocha/run_mocha_cli.js rename to packages/kbn-test/src/mocha/run_mocha_cli.js index 475e1750a92b9..0fc7c762be425 100644 --- a/src/dev/mocha/run_mocha_cli.js +++ b/packages/kbn-test/src/mocha/run_mocha_cli.js @@ -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) { diff --git a/src/dev/mocha/server_junit_reporter.js b/packages/kbn-test/src/mocha/server_junit_reporter.js similarity index 95% rename from src/dev/mocha/server_junit_reporter.js rename to packages/kbn-test/src/mocha/server_junit_reporter.js index e626f693e9af1..c629f401d0580 100644 --- a/src/dev/mocha/server_junit_reporter.js +++ b/packages/kbn-test/src/mocha/server_junit_reporter.js @@ -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', diff --git a/scripts/mocha.js b/scripts/mocha.js index e8d6c31d02ef2..8d25d18a594cc 100644 --- a/scripts/mocha.js +++ b/scripts/mocha.js @@ -18,4 +18,4 @@ */ require('../src/setup_node_env'); -require('../src/dev/mocha').runMochaCli(); +require('@kbn/test').runMochaCli(); diff --git a/src/dev/index.js b/src/dev/index.js index 11c534ecc0a46..f24eee040c867 100644 --- a/src/dev/index.js +++ b/src/dev/index.js @@ -17,6 +17,6 @@ * under the License. */ -export { createAutoJUnitReporter, setupJUnitReportGeneration } from './mocha'; +export { createAutoJUnitReporter, setupJUnitReportGeneration } from '@kbn/test'; export { generateNoticeFromSource } from './notice'; diff --git a/src/dev/xml.ts b/src/dev/xml.ts deleted file mode 100644 index abd6c74d4bc2c..0000000000000 --- a/src/dev/xml.ts +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -// @ts-ignore -import regenerate from 'regenerate'; -import stripAnsi from 'strip-ansi'; - -// create a regular expression using regenerate() that selects any character that is explicitly allowed by https://www.w3.org/TR/xml/#NT-Char -const validXmlCharsRE = new RegExp( - `(?:${regenerate() - .add(0x9, 0xa, 0xd) - .addRange(0x20, 0xd7ff) - .addRange(0xe000, 0xfffd) - .addRange(0x10000, 0x10ffff) - .toString()})*`, - 'g' -); - -export function escapeCdata(input: string) { - const match = stripAnsi(input).match(validXmlCharsRE) || []; - return match.join(''); -}