tests typescript migration (#31234)

* add typescript support for functional tests
This commit is contained in:
Vitali Haradkou 2019-02-22 04:38:54 +03:00 committed by Matthew Kime
parent f6770b117f
commit 75e49e667c
15 changed files with 210 additions and 93 deletions

View file

@ -289,6 +289,7 @@
"@types/listr": "^0.13.0",
"@types/lodash": "^3.10.1",
"@types/minimatch": "^2.0.29",
"@types/mocha": "^5.2.6",
"@types/moment-timezone": "^0.5.8",
"@types/mustache": "^0.8.31",
"@types/node": "^10.12.12",
@ -400,6 +401,7 @@
"ts-jest": "^23.1.4",
"ts-loader": "^5.2.2",
"ts-node": "^7.0.1",
"tsconfig-paths": "^3.8.0",
"tslint": "^5.11.0",
"tslint-config-prettier": "^1.15.0",
"tslint-microsoft-contrib": "^6.0.0",

View file

@ -1,17 +1,21 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"declaration": true,
"declarationDir": "./target/types",
"outDir": "./target/out",
"stripInternal": true,
"declarationMap": true
},
"include": [
"./types/joi.d.ts",
"./src/**/*.ts"
],
"exclude": [
"target"
]
}
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"declaration": true,
"declarationDir": "./target/types",
"outDir": "./target/out",
"stripInternal": true,
"declarationMap": true,
"types": [
"jest",
"node"
]
},
"include": [
"./types/joi.d.ts",
"./src/**/*.ts"
],
"exclude": [
"target"
]
}

View file

@ -1,16 +1,20 @@
{
"extends": "../../tsconfig.json",
"include": [
"src/**/*.ts",
"src/**/*.tsx",
"types/intl_format_cache.d.ts",
"types/intl_relativeformat.d.ts"
],
"exclude": [
"target"
],
"compilerOptions": {
"declaration": true,
"declarationDir": "./target/types",
}
}
{
"extends": "../../tsconfig.json",
"include": [
"src/**/*.ts",
"src/**/*.tsx",
"types/intl_format_cache.d.ts",
"types/intl_relativeformat.d.ts"
],
"exclude": [
"target"
],
"compilerOptions": {
"declaration": true,
"declarationDir": "./target/types",
"types": [
"jest",
"node"
]
}
}

View file

@ -1,10 +1,16 @@
{
"extends": "../../tsconfig.json",
"exclude": [
"dist"
],
"include": [
"./src/**/*.ts",
"./types/index.d.ts"
]
}
{
"extends": "../../tsconfig.json",
"exclude": [
"dist"
],
"include": [
"./src/**/*.ts",
"./types/index.d.ts"
],
"compilerOptions": {
"types": [
"jest",
"node"
]
}
}

View file

@ -27,6 +27,7 @@ export const PROJECTS = [
new Project(resolve(REPO_ROOT, 'tsconfig.json')),
new Project(resolve(REPO_ROOT, 'x-pack/tsconfig.json')),
new Project(resolve(REPO_ROOT, 'x-pack/test/tsconfig.json'), 'x-pack/test'),
new Project(resolve(REPO_ROOT, 'test/tsconfig.json')),
// NOTE: using glob.sync rather than glob-all or globby
// because it takes less than 10 ms, while the other modules

View file

@ -75,6 +75,7 @@ const functionalTestRunner = createFunctionalTestRunner({
bail: cmd.bail,
grep: cmd.grep,
invert: cmd.invert,
require: `ts-node/register --project tests/tsconfig.json -r tsconfig-paths/register -T "test/**/*.{ts,js}"`
},
suiteTags: {
include: cmd.includeTag,

View file

@ -108,6 +108,7 @@ export const schema = Joi.object().keys({
slow: Joi.number().default(30000),
timeout: Joi.number().default(INSPECTING ? Infinity : 360000),
ui: Joi.string().default('bdd'),
require: Joi.string().default('')
}).default(),
updateBaselines: Joi.boolean().default(false),

View file

@ -17,25 +17,34 @@
* under the License.
*/
// @ts-ignore
import expect from 'expect.js';
import { TestWrapper } from 'typings';
export default function ({ getService, getPageObjects }) {
// tslint:disable-next-line:no-default-export
export default function({ getService, getPageObjects }: TestWrapper) {
const esArchiver = getService('esArchiver');
const log = getService('log');
const inspector = getService('inspector');
const retry = getService('retry');
const kibanaServer = getService('kibanaServer');
const testSubjects = getService('testSubjects');
const PageObjects = getPageObjects(['common', 'visualize', 'header', 'settings', 'visualBuilder', 'timePicker']);
const PageObjects = getPageObjects([
'common',
'visualize',
'header',
'settings',
'visualBuilder',
'timePicker',
]);
describe('visual builder', function describeIndexTests() {
describe('Time Series', function () {
describe('Time Series', () => {
before(async () => {
await PageObjects.visualBuilder.resetPage();
});
it('should show the correct count in the legend', async function () {
it('should show the correct count in the legend', async () => {
await retry.try(async () => {
await PageObjects.header.waitUntilLoadingHasFinished();
const actualCount = await PageObjects.visualBuilder.getRhythmChartLegendValue();
@ -43,7 +52,7 @@ export default function ({ getService, getPageObjects }) {
});
});
it('should show the correct count in the legend with 2h offset', async function () {
it('should show the correct count in the legend with 2h offset', async () => {
await PageObjects.visualBuilder.clickSeriesOption();
await PageObjects.visualBuilder.enterOffsetSeries('2h');
await PageObjects.header.waitUntilLoadingHasFinished();
@ -51,7 +60,7 @@ export default function ({ getService, getPageObjects }) {
expect(actualCount).to.be('293');
});
it('should show the correct count in the legend with -2h offset', async function () {
it('should show the correct count in the legend with -2h offset', async () => {
await PageObjects.visualBuilder.enterOffsetSeries('-2h');
await PageObjects.header.waitUntilLoadingHasFinished();
const actualCount = await PageObjects.visualBuilder.getRhythmChartLegendValue();
@ -62,7 +71,6 @@ export default function ({ getService, getPageObjects }) {
// set back to no offset for the next test, an empty string didn't seem to work here
await PageObjects.visualBuilder.enterOffsetSeries('0h');
});
});
describe('Math Aggregation', () => {
@ -75,18 +83,17 @@ export default function ({ getService, getPageObjects }) {
await PageObjects.visualBuilder.fillInExpression('params.test + 1');
});
it('should not have inspector enabled', async function () {
it('should not have inspector enabled', async () => {
await inspector.expectIsNotEnabled();
});
it('should show correct data', async function () {
const expectedMetricValue = '157';
it('should show correct data', async () => {
const expectedMetricValue = '157';
const value = await PageObjects.visualBuilder.getMetricValue();
log.debug(`metric value: ${JSON.stringify(value)}`);
log.debug(`metric value: ${value}`);
expect(value).to.eql(expectedMetricValue);
});
});
describe('metric', () => {
@ -95,18 +102,17 @@ export default function ({ getService, getPageObjects }) {
await PageObjects.visualBuilder.clickMetric();
});
it('should not have inspector enabled', async function () {
it('should not have inspector enabled', async () => {
await inspector.expectIsNotEnabled();
});
it('should show correct data', async function () {
const expectedMetricValue = '156';
it('should show correct data', async () => {
const expectedMetricValue = '156';
await PageObjects.visualize.waitForVisualization();
const value = await PageObjects.visualBuilder.getMetricValue();
log.debug(`metric value: ${value}`);
expect(value).to.eql(expectedMetricValue);
});
});
// add a gauge test
@ -117,7 +123,7 @@ export default function ({ getService, getPageObjects }) {
log.debug('clicked on Gauge');
});
it('should verify gauge label and count display', async function () {
it('should verify gauge label and count display', async () => {
await retry.try(async () => {
await PageObjects.visualize.waitForVisualization();
const labelString = await PageObjects.visualBuilder.getGaugeLabel();
@ -136,7 +142,7 @@ export default function ({ getService, getPageObjects }) {
log.debug('clicked on TopN');
});
it('should verify topN label and count display', async function () {
it('should verify topN label and count display', async () => {
await retry.try(async () => {
await PageObjects.visualize.waitForVisualization();
const labelString = await PageObjects.visualBuilder.getTopNLabel();
@ -147,14 +153,14 @@ export default function ({ getService, getPageObjects }) {
});
});
describe('markdown', () => {
before(async () => {
await PageObjects.visualBuilder.resetPage();
await PageObjects.visualBuilder.clickMarkdown();
await PageObjects.timePicker.setAbsoluteRange('2015-09-22 06:00:00.000', '2015-09-22 11:00:00.000');
await PageObjects.timePicker.setAbsoluteRange(
'2015-09-22 06:00:00.000',
'2015-09-22 11:00:00.000'
);
});
it('should allow printing raw timestamp of data', async () => {
@ -173,7 +179,9 @@ export default function ({ getService, getPageObjects }) {
describe('allow time offsets', () => {
before(async () => {
await PageObjects.visualBuilder.enterMarkdown('{{ count.data.raw.[0].[0] }}#{{ count.data.raw.[0].[1] }}');
await PageObjects.visualBuilder.enterMarkdown(
'{{ count.data.raw.[0].[0] }}#{{ count.data.raw.[0].[1] }}'
);
await PageObjects.visualBuilder.clickMarkdownData();
await PageObjects.visualBuilder.clickSeriesOption();
});
@ -196,14 +204,16 @@ export default function ({ getService, getPageObjects }) {
expect(value).to.be('23');
});
});
});
// add a table sanity timestamp
describe('table', () => {
before(async () => {
await PageObjects.visualBuilder.resetPage();
await PageObjects.visualBuilder.clickTable();
await PageObjects.timePicker.setAbsoluteRange('2015-09-22 06:00:00.000', '2015-09-22 11:00:00.000');
await PageObjects.timePicker.setAbsoluteRange(
'2015-09-22 06:00:00.000',
'2015-09-22 11:00:00.000'
);
log.debug('clicked on Table');
});
@ -223,17 +233,20 @@ export default function ({ getService, getPageObjects }) {
});
describe.skip('switch index patterns', () => {
before(async function () {
before(async () => {
log.debug('Load kibana_sample_data_flights data');
await esArchiver.loadIfNeeded('kibana_sample_data_flights');
await PageObjects.visualBuilder.resetPage('2015-09-19 06:31:44.000', '2018-10-31 00:0:00.000');
await PageObjects.visualBuilder.resetPage(
'2015-09-19 06:31:44.000',
'2018-10-31 00:0:00.000'
);
await PageObjects.visualBuilder.clickMetric();
});
after(async function () {
after(async () => {
await esArchiver.unload('kibana_sample_data_flights');
});
it('should be able to switch between index patterns', async () => {
const expectedMetricValue = '156';
const expectedMetricValue = '156';
const value = await PageObjects.visualBuilder.getMetricValue();
log.debug(`metric value: ${value}`);
expect(value).to.eql(expectedMetricValue);
@ -252,7 +265,7 @@ export default function ({ getService, getPageObjects }) {
describe.skip('dark mode', () => {
it('uses dark mode flag', async () => {
await kibanaServer.uiSettings.update({
'theme:darkMode': true
'theme:darkMode': true,
});
await PageObjects.visualBuilder.resetPage();

21
test/tsconfig.json Normal file
View file

@ -0,0 +1,21 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"allowJs": true,
"outDir": "target",
"baseUrl": "./",
"paths": {
"*":[
"*"
]
},
"types": [
"node",
"mocha"
]
},
"include": [
"**/*.ts"
]
}

20
test/typings/index.ts Normal file
View file

@ -0,0 +1,20 @@
/*
* 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.
*/
export * from './wrapper';

23
test/typings/wrapper.ts Normal file
View file

@ -0,0 +1,23 @@
/*
* 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.
*/
export interface TestWrapper {
getService(service: string): any;
getPageObjects(pages: string[]): { [name: string]: any };
}

View file

@ -46,7 +46,8 @@
// Provide full support for iterables in for..of, spread and destructuring when targeting ES5 or ES3.
"downlevelIteration": true,
// import tslib helpers rather than inlining helpers for iteration or spreading, for instance
"importHelpers": true
"importHelpers": true,
"skipLibCheck": true
},
"include": [
"kibana.d.ts",

View file

@ -1,13 +1,17 @@
{
"extends": "./tsconfig",
"compilerOptions": {
"declaration": true,
"declarationDir": "./target/types",
"stripInternal": true,
"emitDeclarationOnly": true,
"declarationMap": true
},
"include": [
"./src/type_exports.ts"
]
}
{
"extends": "./tsconfig",
"compilerOptions": {
"declaration": true,
"declarationDir": "./target/types",
"stripInternal": true,
"emitDeclarationOnly": true,
"declarationMap": true,
"types": [
"node",
"jest"
]
},
"include": [
"./src/type_exports.ts"
]
}

View file

@ -50,7 +50,7 @@
"@types/joi": "^13.4.2",
"@types/jsonwebtoken": "^7.2.7",
"@types/lodash": "^3.10.1",
"@types/mocha": "^5.2.5",
"@types/mocha": "^5.2.6",
"@types/pngjs": "^3.3.1",
"@types/prop-types": "^15.5.3",
"@types/react": "^16.8.0",

View file

@ -2046,6 +2046,11 @@
resolved "https://registry.yarnpkg.com/@types/json-stable-stringify/-/json-stable-stringify-1.0.32.tgz#121f6917c4389db3923640b2e68de5fa64dda88e"
integrity sha512-q9Q6+eUEGwQkv4Sbst3J4PNgDOvpuVuKj79Hl/qnmBMEIPzB5QoFRUtjcgcg2xNUZyYUGXBk5wYIBKHt0A+Mxw==
"@types/json5@^0.0.29":
version "0.0.29"
resolved "https://registry.yarnpkg.com/@types/json5/-/json5-0.0.29.tgz#ee28707ae94e11d2b827bcbe5270bcea7f3e71ee"
integrity sha1-7ihweulOEdK4J7y+UnC86n8+ce4=
"@types/json5@^0.0.30":
version "0.0.30"
resolved "https://registry.yarnpkg.com/@types/json5/-/json5-0.0.30.tgz#44cb52f32a809734ca562e685c6473b5754a7818"
@ -2138,10 +2143,10 @@
dependencies:
"@types/node" "*"
"@types/mocha@^5.2.5":
version "5.2.5"
resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-5.2.5.tgz#8a4accfc403c124a0bafe8a9fc61a05ec1032073"
integrity sha512-lAVp+Kj54ui/vLUFxsJTMtWvZraZxum3w3Nwkble2dNuV5VnPA+Mi2oGX9XYJAaIvZi3tn3cbjS/qcJXRb6Bww==
"@types/mocha@^5.2.6":
version "5.2.6"
resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-5.2.6.tgz#b8622d50557dd155e9f2f634b7d68fd38de5e94b"
integrity sha512-1axi39YdtBI7z957vdqXI4Ac25e7YihYQtJa+Clnxg1zTJEaIRbndt71O3sP4GAMgiAm0pY26/b9BrY4MR/PMw==
"@types/moment-timezone@^0.5.8":
version "0.5.8"
@ -8073,7 +8078,7 @@ deep-is@~0.1.3:
resolved "https://registry.yarnpkg.com/deep-is/-/deep-is-0.1.3.tgz#b369d6fb5dbc13eecf524f91b070feedc357cf34"
integrity sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ=
deepmerge@2.2.1:
deepmerge@2.2.1, deepmerge@^2.0.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/deepmerge/-/deepmerge-2.2.1.tgz#5d3ff22a01c00f645405a2fbc17d0778a1801170"
integrity sha512-R9hc1Xa/NOBi9WRVUWg19rl1UB7Tt4kuPd+thNJgFZoxXsTz7ncaPaeIm+40oSGuP33DfMb4sZt1QIGiJzC4EA==
@ -22869,6 +22874,17 @@ ts-node@^7.0.1:
source-map-support "^0.5.6"
yn "^2.0.0"
tsconfig-paths@^3.8.0:
version "3.8.0"
resolved "https://registry.yarnpkg.com/tsconfig-paths/-/tsconfig-paths-3.8.0.tgz#4e34202d5b41958f269cf56b01ed95b853d59f72"
integrity sha512-zZEYFo4sjORK8W58ENkRn9s+HmQFkkwydDG7My5s/fnfr2YYCaiyXe/HBUcIgU8epEKOXwiahOO+KZYjiXlWyQ==
dependencies:
"@types/json5" "^0.0.29"
deepmerge "^2.0.1"
json5 "^1.0.1"
minimist "^1.2.0"
strip-bom "^3.0.0"
tslib@1.9.3, tslib@^1.7.1, tslib@^1.8.0, tslib@^1.8.1, tslib@^1.9.0, tslib@^1.9.2, tslib@^1.9.3:
version "1.9.3"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.3.tgz#d7e4dd79245d85428c4d7e4822a79917954ca286"