Skip to content
This repository has been archived by the owner on Mar 31, 2024. It is now read-only.

Commit

Permalink
[ftr] convert remaining JS to TS (elastic#35110) (elastic#35319)
Browse files Browse the repository at this point in the history
  • Loading branch information
Spencer authored Apr 18, 2019
1 parent ed98a87 commit 239f604
Show file tree
Hide file tree
Showing 26 changed files with 488 additions and 440 deletions.
2 changes: 1 addition & 1 deletion packages/kbn-dev-utils/src/tooling_log/tooling_log.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class ToolingLog {
public warning(...args: any[]): void;
public error(errOrMsg: string | Error): void;
public write(...args: any[]): void;
public indent(spaces: number): void;
public indent(spaces?: number): void;
public getWriters(): ToolingLogWriter[];
public setWriters(reporters: ToolingLogWriter[]): void;
public getWritten$(): Rx.Observable<LogMessage>;
Expand Down
18 changes: 7 additions & 11 deletions packages/kbn-test/src/functional_tests/lib/run_ftr.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,17 @@
* under the License.
*/

import * as FunctionalTestRunner from '../../../../../src/functional_test_runner';
import { FunctionalTestRunner } from '../../../../../src/functional_test_runner';
import { CliError } from './run_cli';

function createFtr({ configPath, options: { log, bail, grep, updateBaselines, suiteTags } }) {
return FunctionalTestRunner.createFunctionalTestRunner({
log,
configFile: configPath,
configOverrides: {
mochaOpts: {
bail: !!bail,
grep,
},
updateBaselines,
suiteTags,
return new FunctionalTestRunner(log, configPath, {
mochaOpts: {
bail: !!bail,
grep,
},
updateBaselines,
suiteTags,
});
}

Expand Down
128 changes: 0 additions & 128 deletions src/functional_test_runner/cli.js

This file was deleted.

106 changes: 106 additions & 0 deletions src/functional_test_runner/cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* 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.
*/

import { resolve } from 'path';

import { run } from '../dev/run';
import { FunctionalTestRunner } from './functional_test_runner';

run(
async ({ flags, log }) => {
const resolveConfigPath = (v: string) => resolve(process.cwd(), v);
const toArray = (v: string | string[]) => ([] as string[]).concat(v || []);

const functionalTestRunner = new FunctionalTestRunner(
log,
resolveConfigPath(flags.config as string),
{
mochaOpts: {
bail: flags.bail,
grep: flags.grep || undefined,
invert: flags.invert,
},
suiteTags: {
include: toArray(flags['include-tag'] as string | string[]),
exclude: toArray(flags['exclude-tag'] as string | string[]),
},
updateBaselines: flags.updateBaselines,
excludeTestFiles: flags.exclude || undefined,
}
);

let teardownRun = false;
const teardown = async (err?: Error) => {
if (teardownRun) return;

teardownRun = true;
if (err) {
log.indent(-log.indent());
log.error(err);
process.exitCode = 1;
}

try {
await functionalTestRunner.close();
} finally {
process.exit();
}
};

process.on('unhandledRejection', err => teardown(err));
process.on('SIGTERM', () => teardown());
process.on('SIGINT', () => teardown());

try {
if (flags['test-stats']) {
process.stderr.write(
JSON.stringify(await functionalTestRunner.getTestStats(), null, 2) + '\n'
);
} else {
const failureCount = await functionalTestRunner.run();
process.exitCode = failureCount ? 1 : 0;
}
} catch (err) {
await teardown(err);
} finally {
await teardown();
}
},
{
flags: {
string: ['config', 'grep', 'exclude', 'include-tag', 'exclude-tag'],
boolean: ['bail', 'invert', 'test-stats', 'updateBaselines'],
default: {
config: 'test/functional/config.js',
debug: true,
},
help: `
--config=path path to a config file
--bail stop tests after the first failure
--grep <pattern> pattern used to select which tests to run
--invert invert grep to exclude tests
--exclude=file path to a test file that should not be loaded
--include-tag=tag a tag to be included, pass multiple times for multiple tags
--exclude-tag=tag a tag to be excluded, pass multiple times for multiple tags
--test-stats print the number of tests (included and excluded) to STDERR
--updateBaselines replace baseline screenshots with whatever is generated from the test
`,
},
}
);
44 changes: 44 additions & 0 deletions src/functional_test_runner/fake_mocha_types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* 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.
*/

/**
* The real mocha types conflict with the global jest types, because
* globals are terrible. So instead of using any for everything this
* tries to mock out simple versions of the Mocha types
*/

import EventEmitter from 'events';

export interface Suite {
suites: Suite[];
tests: Test[];
}

export interface Test {
fullTitle(): string;
}

export interface Runner extends EventEmitter {
abort(): void;
failures: any[];
}

export interface Mocha {
run(cb: () => void): Runner;
}
Loading

0 comments on commit 239f604

Please sign in to comment.