Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.1] FTR support mocha dry run (#125915) #126234

Merged
merged 4 commits into from
Feb 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@
"@types/mime-types": "^2.1.0",
"@types/minimatch": "^2.0.29",
"@types/minimist": "^1.2.1",
"@types/mocha": "^8.2.0",
"@types/mocha": "^9.1.0",
"@types/mock-fs": "^4.13.1",
"@types/moment-timezone": "^0.5.12",
"@types/mustache": "^0.8.31",
Expand Down Expand Up @@ -769,7 +769,7 @@
"eslint-plugin-import": "^2.24.2",
"eslint-plugin-jest": "^24.5.0",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-mocha": "^9.0.0",
"eslint-plugin-mocha": "^10.0.3",
"eslint-plugin-no-unsanitized": "^3.1.5",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prefer-object-spread": "^1.2.1",
Expand Down Expand Up @@ -826,10 +826,10 @@
"micromatch": "3.1.10",
"minimist": "^1.2.5",
"mkdirp": "0.5.1",
"mocha": "^8.2.1",
"mocha-junit-reporter": "^2.0.0",
"mochawesome": "^6.2.1",
"mochawesome-merge": "^4.2.0",
"mocha": "^9.1.0",
"mocha-junit-reporter": "^2.0.2",
"mochawesome": "^7.0.1",
"mochawesome-merge": "^4.2.1",
"mock-fs": "^5.1.2",
"mock-http-server": "1.3.0",
"ms-chromium-edge-driver": "^0.4.3",
Expand Down
34 changes: 12 additions & 22 deletions packages/kbn-pm/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18596,7 +18596,6 @@ function pauseStreams (streams, options) {

module.exports = glob

var fs = __webpack_require__(132)
var rp = __webpack_require__(245)
var minimatch = __webpack_require__(247)
var Minimatch = minimatch.Minimatch
Expand All @@ -18607,8 +18606,6 @@ var assert = __webpack_require__(162)
var isAbsolute = __webpack_require__(253)
var globSync = __webpack_require__(254)
var common = __webpack_require__(255)
var alphasort = common.alphasort
var alphasorti = common.alphasorti
var setopts = common.setopts
var ownProp = common.ownProp
var inflight = __webpack_require__(256)
Expand Down Expand Up @@ -19059,7 +19056,7 @@ Glob.prototype._readdirInGlobStar = function (abs, cb) {
var lstatcb = inflight(lstatkey, lstatcb_)

if (lstatcb)
fs.lstat(abs, lstatcb)
self.fs.lstat(abs, lstatcb)

function lstatcb_ (er, lstat) {
if (er && er.code === 'ENOENT')
Expand Down Expand Up @@ -19100,7 +19097,7 @@ Glob.prototype._readdir = function (abs, inGlobStar, cb) {
}

var self = this
fs.readdir(abs, readdirCb(this, abs, cb))
self.fs.readdir(abs, readdirCb(this, abs, cb))
}

function readdirCb (self, abs, cb) {
Expand Down Expand Up @@ -19304,13 +19301,13 @@ Glob.prototype._stat = function (f, cb) {
var self = this
var statcb = inflight('stat\0' + abs, lstatcb_)
if (statcb)
fs.lstat(abs, statcb)
self.fs.lstat(abs, statcb)

function lstatcb_ (er, lstat) {
if (lstat && lstat.isSymbolicLink()) {
// If it's a symlink, then treat it as the target, unless
// the target does not exist, then treat it as a file.
return fs.stat(abs, function (er, stat) {
return self.fs.stat(abs, function (er, stat) {
if (er)
self._stat2(f, abs, null, lstat, cb)
else
Expand Down Expand Up @@ -21030,7 +21027,6 @@ module.exports.win32 = win32;
module.exports = globSync
globSync.GlobSync = GlobSync

var fs = __webpack_require__(132)
var rp = __webpack_require__(245)
var minimatch = __webpack_require__(247)
var Minimatch = minimatch.Minimatch
Expand All @@ -21040,8 +21036,6 @@ var path = __webpack_require__(4)
var assert = __webpack_require__(162)
var isAbsolute = __webpack_require__(253)
var common = __webpack_require__(255)
var alphasort = common.alphasort
var alphasorti = common.alphasorti
var setopts = common.setopts
var ownProp = common.ownProp
var childrenIgnored = common.childrenIgnored
Expand Down Expand Up @@ -21277,7 +21271,7 @@ GlobSync.prototype._readdirInGlobStar = function (abs) {
var lstat
var stat
try {
lstat = fs.lstatSync(abs)
lstat = this.fs.lstatSync(abs)
} catch (er) {
if (er.code === 'ENOENT') {
// lstat failed, doesn't exist
Expand Down Expand Up @@ -21314,7 +21308,7 @@ GlobSync.prototype._readdir = function (abs, inGlobStar) {
}

try {
return this._readdirEntries(abs, fs.readdirSync(abs))
return this._readdirEntries(abs, this.fs.readdirSync(abs))
} catch (er) {
this._readdirError(abs, er)
return null
Expand Down Expand Up @@ -21473,7 +21467,7 @@ GlobSync.prototype._stat = function (f) {
if (!stat) {
var lstat
try {
lstat = fs.lstatSync(abs)
lstat = this.fs.lstatSync(abs)
} catch (er) {
if (er && (er.code === 'ENOENT' || er.code === 'ENOTDIR')) {
this.statCache[abs] = false
Expand All @@ -21483,7 +21477,7 @@ GlobSync.prototype._stat = function (f) {

if (lstat && lstat.isSymbolicLink()) {
try {
stat = fs.statSync(abs)
stat = this.fs.statSync(abs)
} catch (er) {
stat = lstat
}
Expand Down Expand Up @@ -21519,8 +21513,6 @@ GlobSync.prototype._makeAbs = function (f) {
/* 255 */
/***/ (function(module, exports, __webpack_require__) {

exports.alphasort = alphasort
exports.alphasorti = alphasorti
exports.setopts = setopts
exports.ownProp = ownProp
exports.makeAbs = makeAbs
Expand All @@ -21533,17 +21525,14 @@ function ownProp (obj, field) {
return Object.prototype.hasOwnProperty.call(obj, field)
}

var fs = __webpack_require__(132)
var path = __webpack_require__(4)
var minimatch = __webpack_require__(247)
var isAbsolute = __webpack_require__(253)
var Minimatch = minimatch.Minimatch

function alphasorti (a, b) {
return a.toLowerCase().localeCompare(b.toLowerCase())
}

function alphasort (a, b) {
return a.localeCompare(b)
return a.localeCompare(b, 'en')
}

function setupIgnores (self, options) {
Expand Down Expand Up @@ -21602,6 +21591,7 @@ function setopts (self, pattern, options) {
self.stat = !!options.stat
self.noprocess = !!options.noprocess
self.absolute = !!options.absolute
self.fs = options.fs || fs

self.maxLength = options.maxLength || Infinity
self.cache = options.cache || Object.create(null)
Expand Down Expand Up @@ -21671,7 +21661,7 @@ function finish (self) {
all = Object.keys(all)

if (!self.nosort)
all = all.sort(self.nocase ? alphasorti : alphasort)
all = all.sort(alphasort)

// at *some* point we statted all of these
if (self.mark) {
Expand Down
3 changes: 3 additions & 0 deletions packages/kbn-test/src/functional_test_runner/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export function runFtrCli() {
{
mochaOpts: {
bail: flags.bail,
dryRun: flags['dry-run'],
grep: flags.grep || undefined,
invert: flags.invert,
},
Expand Down Expand Up @@ -148,6 +149,7 @@ export function runFtrCli() {
'u',
'throttle',
'headless',
'dry-run',
],
default: {
config: 'test/functional/config.js',
Expand All @@ -174,6 +176,7 @@ export function runFtrCli() {
--kibana-install-dir directory where the Kibana install being tested resides
--throttle enable network throttling in Chrome browser
--headless run browser in headless mode
--dry-run report tests without executing them
`,
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
* Side Public License, v 1.
*/

import Path from 'path';
import { ToolingLog } from '@kbn/dev-utils';
import { REPO_ROOT } from '@kbn/utils';

import { Suite, Test } from './fake_mocha_types';
import {
Expand Down Expand Up @@ -74,7 +76,28 @@ export class FunctionalTestRunner {
return (await providers.invokeProviderFn(customTestRunner)) || 0;
}

const mocha = await setupMocha(this.lifecycle, this.log, config, providers, this.esVersion);
let reporter;
let reporterOptions;
if (config.get('mochaOpts.dryRun')) {
// override default reporter for dryRun results
const targetFile = Path.resolve(REPO_ROOT, 'target/functional-tests/dryRunOutput.json');
reporter = 'json';
reporterOptions = {
output: targetFile,
};
this.log.info(`Dry run results will be stored in ${targetFile}`);
}

const mocha = await setupMocha(
this.lifecycle,
this.log,
config,
providers,
this.esVersion,
reporter,
reporterOptions
);

await this.lifecycle.beforeTests.trigger(mocha.suite);
this.log.info('Starting tests');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export const schema = Joi.object()
mochaOpts: Joi.object()
.keys({
bail: Joi.boolean().default(false),
dryRun: Joi.boolean().default(false),
grep: Joi.string(),
invert: Joi.boolean().default(false),
slow: Joi.number().default(30000),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,21 @@ import { validateCiGroupTags } from './validate_ci_group_tags';
* @param {EsVersion} esVersion
* @return {Promise<Mocha>}
*/
export async function setupMocha(lifecycle, log, config, providers, esVersion) {
export async function setupMocha(
lifecycle,
log,
config,
providers,
esVersion,
reporter,
reporterOptions
) {
// configure mocha
const mocha = new Mocha({
...config.get('mochaOpts'),
reporter: await providers.loadExternalService('mocha reporter', MochaReporterProvider),
reporter:
reporter || (await providers.loadExternalService('mocha reporter', MochaReporterProvider)),
reporterOptions,
});

// global beforeEach hook in root suite triggers before all others
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions packages/kbn-test/src/functional_tests/cli/run_tests/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const options = {
debug: { desc: 'Run in debug mode.' },
quiet: { desc: 'Only log errors.' },
silent: { desc: 'Log nothing.' },
'dry-run': { desc: 'Report tests without executing them.' },
};

export function displayHelp() {
Expand Down Expand Up @@ -136,6 +137,11 @@ export function processOptions(userOptions, defaultConfigPaths) {
userOptions.assertNoneExcluded = !!userOptions['assert-none-excluded'];
delete userOptions['assert-none-excluded'];

if (userOptions['dry-run']) {
userOptions.dryRun = userOptions['dry-run'];
delete userOptions['dry-run'];
}

function createLogger() {
return new ToolingLog({
level: pickLevelFromFlags(userOptions),
Expand Down
3 changes: 3 additions & 0 deletions packages/kbn-test/src/functional_tests/lib/run_ftr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface CreateFtrOptions {
};
updateSnapshots?: boolean;
esVersion: EsVersion;
dryRun?: boolean;
}

export interface CreateFtrParams {
Expand All @@ -45,6 +46,7 @@ async function createFtr({
suiteTags,
updateSnapshots,
esVersion,
dryRun,
},
}: CreateFtrParams) {
const config = await readConfigFile(log, esVersion, configPath);
Expand All @@ -58,6 +60,7 @@ async function createFtr({
mochaOpts: {
bail: !!bail,
grep,
dryRun: !!dryRun,
},
kbnTestServer: {
installDir,
Expand Down
Loading