Skip to content

Commit 2f59c6c

Browse files
[7.x] [Reporting/Test] Convert functional test code to Typescript (#64601) (#64828)
* [Reporting/Test] Convert functional test code to Typescript (#64601) * Convert the tests to typescript * remove outdated comment * fix typescript * fix "as any" Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> * fix ts Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
1 parent 042f3f0 commit 2f59c6c

File tree

6 files changed

+34
-32
lines changed

6 files changed

+34
-32
lines changed

x-pack/test/functional/apps/dashboard/reporting/index.js renamed to x-pack/test/functional/apps/dashboard/reporting/index.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,18 @@
55
*/
66

77
import expect from '@kbn/expect';
8-
import path from 'path';
98
import fs from 'fs';
9+
import path from 'path';
1010
import { promisify } from 'util';
11+
import { FtrProviderContext } from '../../../ftr_provider_context';
1112
import { checkIfPngsMatch } from './lib/compare_pngs';
1213

1314
const writeFileAsync = promisify(fs.writeFile);
1415
const mkdirAsync = promisify(fs.mkdir);
1516

1617
const REPORTS_FOLDER = path.resolve(__dirname, 'reports');
1718

18-
export default function({ getService, getPageObjects }) {
19+
export default function({ getService, getPageObjects }: FtrProviderContext) {
1920
const esArchiver = getService('esArchiver');
2021
const browser = getService('browser');
2122
const log = getService('log');
@@ -85,14 +86,14 @@ export default function({ getService, getPageObjects }) {
8586

8687
describe('Preserve Layout', () => {
8788
it('matches baseline report', async function() {
88-
const writeSessionReport = async (name, rawPdf, reportExt) => {
89+
const writeSessionReport = async (name: string, rawPdf: Buffer, reportExt: string) => {
8990
const sessionDirectory = path.resolve(REPORTS_FOLDER, 'session');
9091
await mkdirAsync(sessionDirectory, { recursive: true });
9192
const sessionReportPath = path.resolve(sessionDirectory, `${name}.${reportExt}`);
9293
await writeFileAsync(sessionReportPath, rawPdf);
9394
return sessionReportPath;
9495
};
95-
const getBaselineReportPath = (fileName, reportExt) => {
96+
const getBaselineReportPath = (fileName: string, reportExt: string) => {
9697
const baselineFolder = path.resolve(REPORTS_FOLDER, 'baseline');
9798
const fullPath = path.resolve(baselineFolder, `${fileName}.${reportExt}`);
9899
log.debug(`getBaselineReportPath (${fullPath})`);

x-pack/test/functional/apps/dashboard/reporting/lib/compare_pngs.js renamed to x-pack/test/functional/apps/dashboard/reporting/lib/compare_pngs.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,19 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import path from 'path';
8-
import fs from 'fs';
97
import { promisify } from 'bluebird';
8+
import fs from 'fs';
9+
import path from 'path';
1010
import { comparePngs } from '../../../../../../../test/functional/services/lib/compare_pngs';
1111

12-
const mkdirAsync = promisify(fs.mkdir);
12+
const mkdirAsync = promisify<void, fs.PathLike, { recursive: boolean }>(fs.mkdir);
1313

14-
export async function checkIfPngsMatch(actualpngPath, baselinepngPath, screenshotsDirectory, log) {
14+
export async function checkIfPngsMatch(
15+
actualpngPath: string,
16+
baselinepngPath: string,
17+
screenshotsDirectory: string,
18+
log: any
19+
) {
1520
log.debug(`checkIfpngsMatch: ${actualpngPath} vs ${baselinepngPath}`);
1621
// Copy the pngs into the screenshot session directory, as that's where the generated pngs will automatically be
1722
// stored.

x-pack/test/functional/apps/discover/reporting.js renamed to x-pack/test/functional/apps/discover/reporting.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
*/
66

77
import expect from '@kbn/expect';
8+
import { FtrProviderContext } from '../../ftr_provider_context';
89

9-
export default function({ getService, getPageObjects }) {
10+
export default function({ getService, getPageObjects }: FtrProviderContext) {
1011
const log = getService('log');
1112
const esArchiver = getService('esArchiver');
1213
const browser = getService('browser');

x-pack/test/functional/apps/visualize/reporting.js renamed to x-pack/test/functional/apps/visualize/reporting.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
*/
66

77
import expect from '@kbn/expect';
8+
import { FtrProviderContext } from '../../ftr_provider_context';
89

9-
export default function({ getService, getPageObjects }) {
10+
export default function({ getService, getPageObjects }: FtrProviderContext) {
1011
const esArchiver = getService('esArchiver');
1112
const browser = getService('browser');
1213
const log = getService('log');

x-pack/test/functional/page_objects/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import { GraphPageProvider } from './graph_page';
1919
import { GrokDebuggerPageProvider } from './grok_debugger_page';
2020
// @ts-ignore not ts yet
2121
import { WatcherPageProvider } from './watcher_page';
22-
// @ts-ignore not ts yet
2322
import { ReportingPageProvider } from './reporting_page';
2423
// @ts-ignore not ts yet
2524
import { AccountSettingProvider } from './accountsetting_page';

x-pack/test/functional/page_objects/reporting_page.js renamed to x-pack/test/functional/page_objects/reporting_page.ts

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,30 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7+
import http, { IncomingMessage } from 'http';
8+
import { FtrProviderContext } from 'test/functional/ftr_provider_context';
79
import { parse } from 'url';
8-
import http from 'http';
910

10-
/*
11-
* NOTE: Reporting is a service, not an app. The page objects that are
12-
* important for generating reports belong to the apps that integrate with the
13-
* Reporting service. Eventually, this file should be dissolved across the
14-
* apps that need it for testing their integration.
15-
* Issue: https://github.com/elastic/kibana/issues/52927
16-
*/
17-
export function ReportingPageProvider({ getService, getPageObjects }) {
11+
export function ReportingPageProvider({ getService, getPageObjects }: FtrProviderContext) {
1812
const retry = getService('retry');
1913
const log = getService('log');
2014
const testSubjects = getService('testSubjects');
2115
const browser = getService('browser');
22-
const PageObjects = getPageObjects(['common', 'security', 'share', 'timePicker']);
16+
const PageObjects = getPageObjects(['common', 'security' as any, 'share', 'timePicker']); // FIXME: Security PageObject is not Typescript
2317

2418
class ReportingPage {
25-
async forceSharedItemsContainerSize({ width }) {
19+
async forceSharedItemsContainerSize({ width }: { width: number }) {
2620
await browser.execute(`
2721
var el = document.querySelector('[data-shared-items-container]');
2822
el.style.flex="none";
2923
el.style.width="${width}px";
3024
`);
3125
}
3226

33-
async getReportURL(timeout) {
27+
async getReportURL(timeout: number) {
3428
log.debug('getReportURL');
3529

36-
const url = await testSubjects.getAttribute('downloadCompletedReportButton', 'href', timeout);
30+
const url = await testSubjects.getAttribute('downloadCompletedReportButton', 'href');
3731

3832
log.debug(`getReportURL got url: ${url}`);
3933

@@ -48,7 +42,7 @@ export function ReportingPageProvider({ getService, getPageObjects }) {
4842
`);
4943
}
5044

51-
getResponse(url) {
45+
getResponse(url: string): Promise<IncomingMessage> {
5246
log.debug(`getResponse for ${url}`);
5347
const auth = 'test_user:changeme'; // FIXME not sure why there is no config that can be read for this
5448
const headers = {
@@ -62,29 +56,30 @@ export function ReportingPageProvider({ getService, getPageObjects }) {
6256
hostname: parsedUrl.hostname,
6357
path: parsedUrl.path,
6458
port: parsedUrl.port,
65-
responseType: 'arraybuffer',
6659
headers,
6760
},
68-
res => {
61+
(res: IncomingMessage) => {
6962
resolve(res);
7063
}
7164
)
72-
.on('error', e => {
65+
.on('error', (e: Error) => {
7366
log.error(e);
7467
reject(e);
7568
});
7669
});
7770
}
7871

79-
async getRawPdfReportData(url) {
80-
const data = []; // List of Buffer objects
72+
async getRawPdfReportData(url: string): Promise<Buffer> {
73+
const data: Buffer[] = []; // List of Buffer objects
8174
log.debug(`getRawPdfReportData for ${url}`);
8275

8376
return new Promise(async (resolve, reject) => {
8477
const response = await this.getResponse(url).catch(reject);
8578

86-
response.on('data', chunk => data.push(chunk));
87-
response.on('end', () => resolve(Buffer.concat(data)));
79+
if (response) {
80+
response.on('data', (chunk: Buffer) => data.push(chunk));
81+
response.on('end', () => resolve(Buffer.concat(data)));
82+
}
8883
});
8984
}
9085

0 commit comments

Comments
 (0)