Skip to content

Commit 090d0ab

Browse files
Spencerspalger
andauthored
[ts] migrate root test dir to project refs (#99148)
Co-authored-by: spalger <spalger@users.noreply.github.com>
1 parent 081cf98 commit 090d0ab

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+5581
-5632
lines changed

packages/kbn-test/src/functional_test_runner/public_types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ export interface GenericFtrProviderContext<
7474
getService(serviceName: 'failureMetadata'): FailureMetadata;
7575
getService<T extends keyof ServiceMap>(serviceName: T): ServiceMap[T];
7676

77+
/**
78+
* Get the instance of a page object
79+
* @param pageObjectName
80+
*/
81+
getPageObject<K extends keyof PageObjectMap>(pageObjectName: K): PageObjectMap[K];
82+
7783
/**
7884
* Get a map of PageObjects
7985
* @param pageObjects

test/accessibility/ftr_provider_context.d.ts renamed to test/accessibility/ftr_provider_context.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
* Side Public License, v 1.
77
*/
88

9-
import { GenericFtrProviderContext } from '@kbn/test';
9+
import { GenericFtrProviderContext, GenericFtrService } from '@kbn/test';
1010

1111
import { pageObjects } from './page_objects';
1212
import { services } from './services';
1313

1414
export type FtrProviderContext = GenericFtrProviderContext<typeof services, typeof pageObjects>;
15+
export class FtrService extends GenericFtrService<FtrProviderContext> {}

test/accessibility/services/a11y/a11y.ts

Lines changed: 67 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import chalk from 'chalk';
1010
import testSubjectToCss from '@kbn/test-subj-selector';
1111

12-
import { FtrProviderContext } from '../../ftr_provider_context';
12+
import { FtrService } from '../../ftr_provider_context';
1313
import { AxeReport, printResult } from './axe_report';
1414
// @ts-ignore JS that is run in browser as is
1515
import { analyzeWithAxe, analyzeWithAxeWithClient } from './analyze_with_axe';
@@ -33,86 +33,84 @@ export const normalizeResult = (report: any) => {
3333
return report.result as false | AxeReport;
3434
};
3535

36-
export function A11yProvider({ getService }: FtrProviderContext) {
37-
const browser = getService('browser');
38-
const Wd = getService('__webdriver__');
39-
40-
/**
41-
* Accessibility testing service using the Axe (https://www.deque.com/axe/)
42-
* toolset to validate a11y rules similar to ESLint. In order to test against
43-
* the rules we must load up the UI and feed a full HTML snapshot into Axe.
44-
*/
45-
return new (class Accessibility {
46-
public async testAppSnapshot(options: TestOptions = {}) {
47-
const context = this.getAxeContext(true, options.excludeTestSubj);
48-
const report = await this.captureAxeReport(context);
49-
await this.testAxeReport(report);
50-
}
36+
/**
37+
* Accessibility testing service using the Axe (https://www.deque.com/axe/)
38+
* toolset to validate a11y rules similar to ESLint. In order to test against
39+
* the rules we must load up the UI and feed a full HTML snapshot into Axe.
40+
*/
41+
export class AccessibilityService extends FtrService {
42+
private readonly browser = this.ctx.getService('browser');
43+
private readonly Wd = this.ctx.getService('__webdriver__');
44+
45+
public async testAppSnapshot(options: TestOptions = {}) {
46+
const context = this.getAxeContext(true, options.excludeTestSubj);
47+
const report = await this.captureAxeReport(context);
48+
this.assertValidAxeReport(report);
49+
}
5150

52-
public async testGlobalSnapshot(options: TestOptions = {}) {
53-
const context = this.getAxeContext(false, options.excludeTestSubj);
54-
const report = await this.captureAxeReport(context);
55-
await this.testAxeReport(report);
56-
}
51+
public async testGlobalSnapshot(options: TestOptions = {}) {
52+
const context = this.getAxeContext(false, options.excludeTestSubj);
53+
const report = await this.captureAxeReport(context);
54+
this.assertValidAxeReport(report);
55+
}
5756

58-
private getAxeContext(global: boolean, excludeTestSubj?: string | string[]): AxeContext {
59-
return {
60-
include: global ? undefined : [testSubjectToCss('appA11yRoot')],
61-
exclude: ([] as string[])
62-
.concat(excludeTestSubj || [])
63-
.map((ts) => [testSubjectToCss(ts)])
64-
.concat([['[role="graphics-document"][aria-roledescription="visualization"]']]),
65-
};
66-
}
57+
private getAxeContext(global: boolean, excludeTestSubj?: string | string[]): AxeContext {
58+
return {
59+
include: global ? undefined : [testSubjectToCss('appA11yRoot')],
60+
exclude: ([] as string[])
61+
.concat(excludeTestSubj || [])
62+
.map((ts) => [testSubjectToCss(ts)])
63+
.concat([['[role="graphics-document"][aria-roledescription="visualization"]']]),
64+
};
65+
}
6766

68-
private testAxeReport(report: AxeReport) {
69-
const errorMsgs = [];
67+
private assertValidAxeReport(report: AxeReport) {
68+
const errorMsgs = [];
7069

71-
for (const result of report.violations) {
72-
errorMsgs.push(printResult(chalk.red('VIOLATION'), result));
73-
}
70+
for (const result of report.violations) {
71+
errorMsgs.push(printResult(chalk.red('VIOLATION'), result));
72+
}
7473

75-
if (errorMsgs.length) {
76-
throw new Error(`a11y report:\n${errorMsgs.join('\n')}`);
77-
}
74+
if (errorMsgs.length) {
75+
throw new Error(`a11y report:\n${errorMsgs.join('\n')}`);
7876
}
77+
}
7978

80-
private async captureAxeReport(context: AxeContext): Promise<AxeReport> {
81-
const axeOptions = {
82-
reporter: 'v2',
83-
runOnly: ['wcag2a', 'wcag2aa'],
84-
rules: {
85-
'color-contrast': {
86-
enabled: false, // disabled because we have too many failures
87-
},
88-
bypass: {
89-
enabled: false, // disabled because it's too flaky
90-
},
79+
private async captureAxeReport(context: AxeContext): Promise<AxeReport> {
80+
const axeOptions = {
81+
reporter: 'v2',
82+
runOnly: ['wcag2a', 'wcag2aa'],
83+
rules: {
84+
'color-contrast': {
85+
enabled: false, // disabled because we have too many failures
9186
},
92-
};
93-
94-
await (Wd.driver.manage() as any).setTimeouts({
95-
...(await (Wd.driver.manage() as any).getTimeouts()),
96-
script: 600000,
97-
});
87+
bypass: {
88+
enabled: false, // disabled because it's too flaky
89+
},
90+
},
91+
};
9892

99-
const report = normalizeResult(
100-
await browser.executeAsync(analyzeWithAxe, context, axeOptions)
101-
);
93+
await this.Wd.driver.manage().setTimeouts({
94+
...(await this.Wd.driver.manage().getTimeouts()),
95+
script: 600000,
96+
});
10297

103-
if (report !== false) {
104-
return report;
105-
}
98+
const report = normalizeResult(
99+
await this.browser.executeAsync(analyzeWithAxe, context, axeOptions)
100+
);
106101

107-
const withClientReport = normalizeResult(
108-
await browser.executeAsync(analyzeWithAxeWithClient, context, axeOptions)
109-
);
102+
if (report !== false) {
103+
return report;
104+
}
110105

111-
if (withClientReport === false) {
112-
throw new Error('Attempted to analyze with axe but failed to load axe client');
113-
}
106+
const withClientReport = normalizeResult(
107+
await this.browser.executeAsync(analyzeWithAxeWithClient, context, axeOptions)
108+
);
114109

115-
return withClientReport;
110+
if (withClientReport === false) {
111+
throw new Error('Attempted to analyze with axe but failed to load axe client');
116112
}
117-
})();
113+
114+
return withClientReport;
115+
}
118116
}

test/accessibility/services/a11y/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
* Side Public License, v 1.
77
*/
88

9-
export { A11yProvider } from './a11y';
9+
export * from './a11y';

test/accessibility/services/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
*/
88

99
import { services as kibanaFunctionalServices } from '../../functional/services';
10-
import { A11yProvider } from './a11y';
10+
import { AccessibilityService } from './a11y';
1111

1212
export const services = {
1313
...kibanaFunctionalServices,
14-
a11y: A11yProvider,
14+
a11y: AccessibilityService,
1515
};

0 commit comments

Comments
 (0)