Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Reporting/Test] Convert functional test code to Typescript #64601

Merged
merged 6 commits into from
Apr 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@
*/

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

const writeFileAsync = promisify(fs.writeFile);
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 @@ -4,14 +4,19 @@
* you may not use this file except in compliance with the Elastic License.
*/

import path from 'path';
import fs from 'fs';
import { promisify } from 'bluebird';
import fs from 'fs';
import path from 'path';
import { comparePngs } from '../../../../../../../test/functional/services/lib/compare_pngs';

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

export async function checkIfPngsMatch(actualpngPath, baselinepngPath, screenshotsDirectory, log) {
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 '../../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 '../../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,33 +4,27 @@
* 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
* important for generating reports belong to the apps that integrate with the
* Reporting service. Eventually, this file should be dissolved across the
* apps that need it for testing their integration.
* Issue: https://github.com/elastic/kibana/issues/52927
*/
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this comment is obsolete as of #64368

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', 'security' as any, 'share', 'timePicker']); // FIXME: Security PageObject is not Typescript

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 +42,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 +56,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): Promise<Buffer> {
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
Loading