Skip to content

Commit

Permalink
[Tests] Fix osd-test-subj-selector tsconfig
Browse files Browse the repository at this point in the history
Convert to ts, set the tsconfig correctly, update imports

Signed-off-by: Josh Romero <rmerqg@amazon.com>
  • Loading branch information
joshuarrrr committed May 26, 2022
1 parent 111a61f commit baf3fcc
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 48 deletions.
32 changes: 0 additions & 32 deletions packages/osd-test-subj-selector/index.d.ts

This file was deleted.

6 changes: 5 additions & 1 deletion packages/osd-test-subj-selector/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@
"name": "@osd/test-subj-selector",
"version": "0.2.1",
"description": "",
"main": "index.js",
"main": "./target/index.js",
"keywords": [],
"author": "Spencer Alger <email@spalger.com>",
"license": "Apache-2.0",
"scripts": {
"build": "tsc",
"osd:bootstrap": "yarn build"
},
"opensearchDashboards": {
"devOnly": true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
* under the License.
*/

const testSubjSelector = require('../');
const expect = require('@osd/expect');
import { testSubjSelector } from '.';
import expect from '@osd/expect';

describe('testSubjSelector()', function () {
it('converts subjectSelectors to cssSelectors', function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@
* under the License.
*/

function selectorToTerms(selector) {
function selectorToTerms(selector: string) {
return selector
.replace(/\s*~\s*/g, '~') // css locator with '~' operator cannot contain spaces
.replace(/\s*>\s*/g, '>') // remove all whitespace around joins >
.replace(/\s*&\s*/g, '&') // remove all whitespace around joins &
.split(/>+/);
}

function termToCssSelector(term) {
function termToCssSelector(term: string) {
if (term) {
return term.startsWith('~')
? '[data-test-subj~="' + term.substring(1).replace(/\s/g, '') + '"]'
Expand All @@ -46,15 +46,17 @@ function termToCssSelector(term) {
}
}

module.exports = function testSubjSelector(selector) {
export function testSubjSelector(selector: string) {
const cssSelectors = [];
const terms = selectorToTerms(selector);

while (terms.length) {
const term = terms.shift();
// split each term by joins/& and map to css selectors
cssSelectors.push(term.split('&').map(termToCssSelector).join(''));
if (term) {
cssSelectors.push(term.split('&').map(termToCssSelector).join(''));
}
}

return cssSelectors.join(' ');
};
}
10 changes: 8 additions & 2 deletions packages/osd-test-subj-selector/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"tsBuildInfoFile": "../../build/tsbuildinfo/packages/osd-test-subj-selector"
"outDir": "./target",
"declaration": true,
"sourceMap": true,
"types": [
"jest",
"node"
]
},
"include": [
"index.d.ts"
"src"
]
}
2 changes: 1 addition & 1 deletion src/core/public/fatal_errors/fatal_errors_screen.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*/

import { EuiCallOut } from '@elastic/eui';
import testSubjSelector from '@osd/test-subj-selector';
import { testSubjSelector } from '@osd/test-subj-selector';
import React from 'react';
import * as Rx from 'rxjs';
import { mountWithIntl, shallowWithIntl } from 'test_utils/enzyme_helpers';
Expand Down
2 changes: 1 addition & 1 deletion test/functional/services/common/test_subjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* under the License.
*/

import testSubjSelector from '@osd/test-subj-selector';
import { testSubjSelector } from '@osd/test-subj-selector';
import { map as mapAsync } from 'bluebird';
import { ProvidedType } from '@osd/test/types/ftr';
import { WebElementWrapper } from '../lib/web_element_wrapper';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { WebElement, WebDriver, By, Key } from 'selenium-webdriver';
import { PNG } from 'pngjs';
// @ts-ignore not supported yet
import cheerio from 'cheerio';
import testSubjSelector from '@osd/test-subj-selector';
import { testSubjSelector } from '@osd/test-subj-selector';
import { ToolingLog } from '@osd/dev-utils';
import { CustomCheerio, CustomCheerioStatic } from './custom_cheerio_api';
// @ts-ignore not supported yet
Expand Down Expand Up @@ -131,15 +131,16 @@ export class WebElementWrapper {
try {
return await fn(this);
} catch (err) {
const { name, message } = err as Error;
if (
!RETRY_CLICK_RETRY_ON_ERRORS.includes(err.name) ||
!RETRY_CLICK_RETRY_ON_ERRORS.includes(name) ||
this.locator === null ||
attemptsRemaining === 0
) {
throw err;
}

this.logger.warning(`WebElementWrapper.${fn.name}: ${err.message}`);
this.logger.warning(`WebElementWrapper.${fn.name}: ${message}`);
this.logger.debug(
`finding element '${this.locator.toString()}' again, ${attemptsRemaining - 1} attempts left`
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import { postSnapshot } from '@percy/sdk-utils';
import { Test } from 'mocha';

import testSubjSelector from '@osd/test-subj-selector';
import { testSubjSelector } from '@osd/test-subj-selector';

import { pkg } from '../../../../src/core/server/utils';
import { FtrProviderContext } from '../../ftr_provider_context';
Expand Down

0 comments on commit baf3fcc

Please sign in to comment.