Skip to content

Commit

Permalink
Convert the tests to typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
tsullivan committed Apr 27, 2020
1 parent 54dc148 commit 44f14bd
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
*/

import expect from '@kbn/expect';
import path from 'path';
import fs from 'fs';
import path from 'path';
import { FtrProviderContext } from 'test/functional/ftr_provider_context';
import { promisify } from 'util';
import { checkIfPngsMatch } from './lib/compare_pngs';

Expand All @@ -15,7 +16,7 @@ const mkdirAsync = promisify(fs.mkdir);

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

export default function({ getService, getPageObjects }) {
export default function({ getService, getPageObjects }: FtrProviderContext) {
const esArchiver = getService('esArchiver');
const browser = getService('browser');
const log = getService('log');
Expand Down Expand Up @@ -85,14 +86,14 @@ export default function({ getService, getPageObjects }) {

describe('Preserve Layout', () => {
it('matches baseline report', async function() {
const writeSessionReport = async (name, rawPdf, reportExt) => {
const writeSessionReport = async (name: string, rawPdf: Buffer, reportExt: string) => {
const sessionDirectory = path.resolve(REPORTS_FOLDER, 'session');
await mkdirAsync(sessionDirectory, { recursive: true });
const sessionReportPath = path.resolve(sessionDirectory, `${name}.${reportExt}`);
await writeFileAsync(sessionReportPath, rawPdf);
return sessionReportPath;
};
const getBaselineReportPath = (fileName, reportExt) => {
const getBaselineReportPath = (fileName: string, reportExt: string) => {
const baselineFolder = path.resolve(REPORTS_FOLDER, 'baseline');
const fullPath = path.resolve(baselineFolder, `${fileName}.${reportExt}`);
log.debug(`getBaselineReportPath (${fullPath})`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ import fs from 'fs';
import { promisify } from 'bluebird';
import { comparePngs } from '../../../../../../../test/functional/services/lib/compare_pngs';

const mkdirAsync = promisify(fs.mkdir);

export async function checkIfPngsMatch(actualpngPath, baselinepngPath, screenshotsDirectory, log) {
const mkdirAsync = promisify<void, fs.PathLike, { recursive: boolean }>(fs.mkdir);

export async function checkIfPngsMatch(
actualpngPath: string,
baselinepngPath: string,
screenshotsDirectory: string,
log: any
) {
log.debug(`checkIfpngsMatch: ${actualpngPath} vs ${baselinepngPath}`);
// Copy the pngs into the screenshot session directory, as that's where the generated pngs will automatically be
// stored.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
*/

import expect from '@kbn/expect';
import { FtrProviderContext } from 'test/functional/ftr_provider_context';

export default function({ getService, getPageObjects }) {
export default function({ getService, getPageObjects }: FtrProviderContext) {
const log = getService('log');
const esArchiver = getService('esArchiver');
const browser = getService('browser');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
*/

import expect from '@kbn/expect';
import { FtrProviderContext } from 'test/functional/ftr_provider_context';

export default function({ getService, getPageObjects }) {
export default function({ getService, getPageObjects }: FtrProviderContext) {
const esArchiver = getService('esArchiver');
const browser = getService('browser');
const log = getService('log');
Expand Down
1 change: 0 additions & 1 deletion x-pack/test/functional/page_objects/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { GraphPageProvider } from './graph_page';
import { GrokDebuggerPageProvider } from './grok_debugger_page';
// @ts-ignore not ts yet
import { WatcherPageProvider } from './watcher_page';
// @ts-ignore not ts yet
import { ReportingPageProvider } from './reporting_page';
// @ts-ignore not ts yet
import { AccountSettingProvider } from './accountsetting_page';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/

import http, { IncomingMessage } from 'http';
import { FtrProviderContext } from 'test/functional/ftr_provider_context';
import { parse } from 'url';
import http from 'http';

/*
* NOTE: Reporting is a service, not an app. The page objects that are
Expand All @@ -14,23 +15,23 @@ import http from 'http';
* apps that need it for testing their integration.
* Issue: https://github.com/elastic/kibana/issues/52927
*/
export function ReportingPageProvider({ getService, getPageObjects }) {
export function ReportingPageProvider({ getService, getPageObjects }: FtrProviderContext) {
const retry = getService('retry');
const log = getService('log');
const testSubjects = getService('testSubjects');
const browser = getService('browser');
const PageObjects = getPageObjects(['common', 'security', 'share', 'timePicker']);
const PageObjects = getPageObjects(['common' as any, 'security', 'share', 'timePicker']);

class ReportingPage {
async forceSharedItemsContainerSize({ width }) {
async forceSharedItemsContainerSize({ width }: { width: number }) {
await browser.execute(`
var el = document.querySelector('[data-shared-items-container]');
el.style.flex="none";
el.style.width="${width}px";
`);
}

async getReportURL(timeout) {
async getReportURL(timeout: number) {
log.debug('getReportURL');

const url = await testSubjects.getAttribute('downloadCompletedReportButton', 'href', timeout);
Expand All @@ -48,7 +49,7 @@ export function ReportingPageProvider({ getService, getPageObjects }) {
`);
}

getResponse(url) {
getResponse(url: string): Promise<IncomingMessage> {
log.debug(`getResponse for ${url}`);
const auth = 'test_user:changeme'; // FIXME not sure why there is no config that can be read for this
const headers = {
Expand All @@ -62,29 +63,30 @@ export function ReportingPageProvider({ getService, getPageObjects }) {
hostname: parsedUrl.hostname,
path: parsedUrl.path,
port: parsedUrl.port,
responseType: 'arraybuffer',
headers,
},
res => {
(res: IncomingMessage) => {
resolve(res);
}
)
.on('error', e => {
.on('error', (e: Error) => {
log.error(e);
reject(e);
});
});
}

async getRawPdfReportData(url) {
const data = []; // List of Buffer objects
async getRawPdfReportData(url: string) {
const data: Buffer[] = []; // List of Buffer objects
log.debug(`getRawPdfReportData for ${url}`);

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

response.on('data', chunk => data.push(chunk));
response.on('end', () => resolve(Buffer.concat(data)));
if (response) {
response.on('data', (chunk: Buffer) => data.push(chunk));
response.on('end', () => resolve(Buffer.concat(data)));
}
});
}

Expand Down

0 comments on commit 44f14bd

Please sign in to comment.