Skip to content

Commit

Permalink
tests typescript migration (elastic#31234)
Browse files Browse the repository at this point in the history
* add typescript support for functional tests
  • Loading branch information
vitalics authored and mattkime committed Feb 22, 2019
1 parent e93f9da commit fd0687f
Show file tree
Hide file tree
Showing 15 changed files with 210 additions and 93 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
38 changes: 21 additions & 17 deletions packages/kbn-config-schema/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
36 changes: 20 additions & 16 deletions packages/kbn-i18n/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
}
26 changes: 16 additions & 10 deletions packages/kbn-pm/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
}
1 change: 1 addition & 0 deletions src/dev/typescript/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/functional_test_runner/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/functional_test_runner/lib/config/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,41 +17,50 @@
* 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();
expect(actualCount).to.be('156');
});
});

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();
const actualCount = await PageObjects.visualBuilder.getRhythmChartLegendValue();
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();
Expand All @@ -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', () => {
Expand All @@ -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', () => {
Expand All @@ -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
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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 () => {
Expand All @@ -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();
});
Expand All @@ -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');
});

Expand All @@ -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);
Expand All @@ -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();
Expand Down
21 changes: 21 additions & 0 deletions test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"allowJs": true,
"outDir": "target",
"baseUrl": "./",
"paths": {
"*":[
"*"
]
},
"types": [
"node",
"mocha"
]
},
"include": [
"**/*.ts"
]
}
20 changes: 20 additions & 0 deletions test/typings/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Loading

0 comments on commit fd0687f

Please sign in to comment.