From f215937622137d06b62e7b065e50eaeb3ad5967a Mon Sep 17 00:00:00 2001 From: marcosvega91 Date: Thu, 10 Dec 2020 12:44:20 +0100 Subject: [PATCH 1/9] feat: enable typescript and disable type generation --- package.json | 4 ++-- tsconfig.json | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 tsconfig.json diff --git a/package.json b/package.json index 7559bbde..57335f4f 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "node": ">=10" }, "scripts": { - "build": "kcd-scripts build --ignore \"**/__tests__/**,**/__node_tests__/**,**/__mocks__/**\" && kcd-scripts build --bundle --no-clean", + "build": "kcd-scripts build --ignore \"**/__tests__/**,**/__node_tests__/**,**/__mocks__/**\" && kcd-scripts build --no-ts-defs --bundle --no-clean", "lint": "kcd-scripts lint", "setup": "npm install && npm run validate -s", "test": "kcd-scripts test", @@ -53,7 +53,7 @@ "jest-serializer-ansi": "^1.0.3", "jest-watch-select-projects": "^2.0.0", "jsdom": "^16.4.0", - "kcd-scripts": "^7.5.1", + "kcd-scripts": "^7.5.2", "typescript": "^4.1.2" }, "eslintConfig": { diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 00000000..9fdd876b --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,6 @@ +{ + "extends": "./node_modules/kcd-scripts/shared-tsconfig.json", + "compilerOptions": { + "allowJs": true + } +} From 61214fca21e8555a054d880e816156d324b8a5aa Mon Sep 17 00:00:00 2001 From: marcosvega91 Date: Thu, 10 Dec 2020 18:02:59 +0100 Subject: [PATCH 2/9] chore: update kcd-script and skip types generation --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 57335f4f..aed90c63 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "node": ">=10" }, "scripts": { - "build": "kcd-scripts build --ignore \"**/__tests__/**,**/__node_tests__/**,**/__mocks__/**\" && kcd-scripts build --no-ts-defs --bundle --no-clean", + "build": "kcd-scripts build --no-ts-defs --ignore \"**/__tests__/**,**/__node_tests__/**,**/__mocks__/**\" && kcd-scripts build --no-ts-defs --bundle --no-clean", "lint": "kcd-scripts lint", "setup": "npm install && npm run validate -s", "test": "kcd-scripts test", @@ -53,7 +53,7 @@ "jest-serializer-ansi": "^1.0.3", "jest-watch-select-projects": "^2.0.0", "jsdom": "^16.4.0", - "kcd-scripts": "^7.5.2", + "kcd-scripts": "^7.5.3", "typescript": "^4.1.2" }, "eslintConfig": { From b71dccd39f8dafd5b40aa4141e82a4b1ff3d7925 Mon Sep 17 00:00:00 2001 From: marcosvega91 Date: Thu, 10 Dec 2020 18:05:54 +0100 Subject: [PATCH 3/9] chore: extend types tsconfig from parent --- tsconfig.json | 3 ++- types/tsconfig.json | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tsconfig.json b/tsconfig.json index 9fdd876b..17bcf90d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,5 +2,6 @@ "extends": "./node_modules/kcd-scripts/shared-tsconfig.json", "compilerOptions": { "allowJs": true - } + }, + "include": ["./src", "./types"] } diff --git a/types/tsconfig.json b/types/tsconfig.json index a7829065..3c43903c 100644 --- a/types/tsconfig.json +++ b/types/tsconfig.json @@ -1,4 +1,3 @@ { - "extends": "../node_modules/kcd-scripts/shared-tsconfig.json", - "include": ["."] + "extends": "../tsconfig.json" } From c3b9704ea35af3ef36038579bd81f2c39c2ee053 Mon Sep 17 00:00:00 2001 From: marcosvega91 Date: Thu, 10 Dec 2020 18:07:14 +0100 Subject: [PATCH 4/9] chore: convert config.js to typescript --- src/__tests__/config.js | 2 +- src/__tests__/element-queries.js | 2 +- src/__tests__/get-by-errors.js | 2 +- src/__tests__/query-helper.js | 2 +- src/__tests__/role.js | 2 +- src/__tests__/suggestions.js | 2 +- src/__tests__/wait-for.js | 2 +- src/{config.js => config.ts} | 31 ++++++++++++++++++++++++++++--- src/events.js | 17 ++++++++++------- src/index.js | 2 +- src/queries/all-utils.js | 2 +- src/queries/label-text.js | 2 +- src/queries/text.js | 2 +- src/query-helpers.js | 2 +- src/role-helpers.js | 2 +- src/suggestions.js | 2 +- src/types.ts | 1 + src/wait-for-dom-change.js | 2 +- src/wait-for.js | 2 +- 19 files changed, 55 insertions(+), 26 deletions(-) rename src/{config.js => config.ts} (68%) create mode 100644 src/types.ts diff --git a/src/__tests__/config.js b/src/__tests__/config.js index 40123a53..dbbd01b9 100644 --- a/src/__tests__/config.js +++ b/src/__tests__/config.js @@ -1,4 +1,4 @@ -import {configure, getConfig} from '../config' +import {configure, getConfig} from '../config.ts' describe('configuration API', () => { let originalConfig diff --git a/src/__tests__/element-queries.js b/src/__tests__/element-queries.js index 3e3ee6de..6ce359ff 100644 --- a/src/__tests__/element-queries.js +++ b/src/__tests__/element-queries.js @@ -1,4 +1,4 @@ -import {configure} from '../config' +import {configure} from '../config.ts' import {render, renderIntoDocument} from './helpers/test-utils' beforeEach(() => { diff --git a/src/__tests__/get-by-errors.js b/src/__tests__/get-by-errors.js index c7e8cadf..9ff56f23 100644 --- a/src/__tests__/get-by-errors.js +++ b/src/__tests__/get-by-errors.js @@ -1,6 +1,6 @@ import cases from 'jest-in-case' import {screen} from '../' -import {configure, getConfig} from '../config' +import {configure, getConfig} from '../config.ts' import {render} from './helpers/test-utils' const originalConfig = getConfig() diff --git a/src/__tests__/query-helper.js b/src/__tests__/query-helper.js index 7e53ab03..db536c6d 100644 --- a/src/__tests__/query-helper.js +++ b/src/__tests__/query-helper.js @@ -1,5 +1,5 @@ import * as queryHelpers from '../query-helpers' -import {configure, getConfig} from '../config' +import {configure, getConfig} from '../config.ts' const originalConfig = getConfig() beforeEach(() => { diff --git a/src/__tests__/role.js b/src/__tests__/role.js index 109d2e62..3da485f6 100644 --- a/src/__tests__/role.js +++ b/src/__tests__/role.js @@ -1,4 +1,4 @@ -import {configure, getConfig} from '../config' +import {configure, getConfig} from '../config.ts' import {getQueriesForElement} from '../get-queries-for-element' import {render, renderIntoDocument} from './helpers/test-utils' diff --git a/src/__tests__/suggestions.js b/src/__tests__/suggestions.js index 3bb5364d..d82d40ce 100644 --- a/src/__tests__/suggestions.js +++ b/src/__tests__/suggestions.js @@ -1,4 +1,4 @@ -import {configure} from '../config' +import {configure} from '../config.ts' import {screen, getSuggestedQuery} from '..' import {renderIntoDocument, render} from './helpers/test-utils' diff --git a/src/__tests__/wait-for.js b/src/__tests__/wait-for.js index 7235f6a5..e1eb3665 100644 --- a/src/__tests__/wait-for.js +++ b/src/__tests__/wait-for.js @@ -1,5 +1,5 @@ import {waitFor} from '../' -import {configure, getConfig} from '../config' +import {configure, getConfig} from '../config.ts' import {renderIntoDocument} from './helpers/test-utils' function deferred() { diff --git a/src/config.js b/src/config.ts similarity index 68% rename from src/config.js rename to src/config.ts index 2472a3fe..88414b82 100644 --- a/src/config.js +++ b/src/config.ts @@ -1,9 +1,32 @@ import {prettyDOM} from './pretty-dom' +import {Callback} from './types' + +export interface Config { + testIdAttribute: string + // eslint-disable-next-line @typescript-eslint/no-explicit-any + asyncWrapper(cb: (...args: any[]) => any): Promise + // eslint-disable-next-line @typescript-eslint/no-explicit-any + eventWrapper(cb: (...args: any[]) => any): void + asyncUtilTimeout: number + computedStyleSupportsPseudoElements: boolean + defaultHidden: boolean + showOriginalStackTrace: boolean + throwSuggestions: boolean + getElementError: (message: string | null, container: Element) => Error +} + +export interface ConfigFn { + (existingConfig: Config): Partial +} + +interface InternalConfig { + _disableExpensiveErrorDiagnostics: boolean +} // It would be cleaner for this to live inside './queries', but // other parts of the code assume that all exports from // './queries' are query functions. -let config = { +let config: Config & InternalConfig = { testIdAttribute: 'data-testid', asyncUtilTimeout: 1000, // this is to support React's async `act` function. @@ -36,7 +59,9 @@ let config = { } export const DEFAULT_IGNORE_TAGS = 'script, style' -export function runWithExpensiveErrorDiagnosticsDisabled(callback) { +export function runWithExpensiveErrorDiagnosticsDisabled( + callback: Callback, +) { try { config._disableExpensiveErrorDiagnostics = true return callback() @@ -45,7 +70,7 @@ export function runWithExpensiveErrorDiagnosticsDisabled(callback) { } } -export function configure(newConfig) { +export function configure(newConfig: Partial | ConfigFn) { if (typeof newConfig === 'function') { // Pass the existing config out to the provided function // and accept a delta in return diff --git a/src/events.js b/src/events.js index 53ebaabb..acf77119 100644 --- a/src/events.js +++ b/src/events.js @@ -1,4 +1,4 @@ -import {getConfig} from './config' +import {getConfig} from './config.ts' import {getWindowFromNode} from './helpers' import {eventMap, eventAliasMap} from './event-map' @@ -71,12 +71,15 @@ function createEvent( /* istanbul ignore if */ if (typeof window.DataTransfer === 'function') { Object.defineProperty(event, dataTransferKey, { - value: Object - .getOwnPropertyNames(dataTransferValue) - .reduce((acc, propName) => { - Object.defineProperty(acc, propName, {value: dataTransferValue[propName]}); - return acc; - }, new window.DataTransfer()) + value: Object.getOwnPropertyNames(dataTransferValue).reduce( + (acc, propName) => { + Object.defineProperty(acc, propName, { + value: dataTransferValue[propName], + }) + return acc + }, + new window.DataTransfer(), + ), }) } else { Object.defineProperty(event, dataTransferKey, { diff --git a/src/index.js b/src/index.js index 2a279383..b247bb54 100644 --- a/src/index.js +++ b/src/index.js @@ -15,7 +15,7 @@ export * from './screen' export * from './query-helpers' export {getRoles, logRoles, isInaccessible} from './role-helpers' export * from './pretty-dom' -export {configure, getConfig} from './config' +export {configure, getConfig} from './config.ts' export * from './suggestions' export { diff --git a/src/queries/all-utils.js b/src/queries/all-utils.js index c4ce9c43..c24a51d6 100644 --- a/src/queries/all-utils.js +++ b/src/queries/all-utils.js @@ -1,4 +1,4 @@ export * from '../matches' export * from '../get-node-text' export * from '../query-helpers' -export * from '../config' +export * from '../config.ts' diff --git a/src/queries/label-text.js b/src/queries/label-text.js index 083cd263..aba17645 100644 --- a/src/queries/label-text.js +++ b/src/queries/label-text.js @@ -1,4 +1,4 @@ -import {getConfig} from '../config' +import {getConfig} from '../config.ts' import {checkContainerType} from '../helpers' import {getLabels, getRealLabels, getLabelContent} from '../label-helpers' import { diff --git a/src/queries/text.js b/src/queries/text.js index 903bba25..7406d41f 100644 --- a/src/queries/text.js +++ b/src/queries/text.js @@ -1,6 +1,6 @@ import {wrapAllByQueryWithSuggestion} from '../query-helpers' import {checkContainerType} from '../helpers' -import {DEFAULT_IGNORE_TAGS} from '../config' +import {DEFAULT_IGNORE_TAGS} from '../config.ts' import { fuzzyMatches, matches, diff --git a/src/query-helpers.js b/src/query-helpers.js index 48ff176d..16395e7e 100644 --- a/src/query-helpers.js +++ b/src/query-helpers.js @@ -1,7 +1,7 @@ import {getSuggestedQuery} from './suggestions' import {fuzzyMatches, matches, makeNormalizer} from './matches' import {waitFor} from './wait-for' -import {getConfig} from './config' +import {getConfig} from './config.ts' function getElementError(message, container) { return getConfig().getElementError(message, container) diff --git a/src/role-helpers.js b/src/role-helpers.js index c7d64076..48f632e3 100644 --- a/src/role-helpers.js +++ b/src/role-helpers.js @@ -1,7 +1,7 @@ import {elementRoles} from 'aria-query' import {computeAccessibleName} from 'dom-accessibility-api' import {prettyDOM} from './pretty-dom' -import {getConfig} from './config' +import {getConfig} from './config.ts' const elementRoleList = buildElementRoleList(elementRoles) diff --git a/src/suggestions.js b/src/suggestions.js index ba5a1f29..b1e11985 100644 --- a/src/suggestions.js +++ b/src/suggestions.js @@ -1,7 +1,7 @@ import {computeAccessibleName} from 'dom-accessibility-api' import {getDefaultNormalizer} from './matches' import {getNodeText} from './get-node-text' -import {DEFAULT_IGNORE_TAGS, getConfig} from './config' +import {DEFAULT_IGNORE_TAGS, getConfig} from './config.ts' import {getImplicitAriaRoles, isInaccessible} from './role-helpers' import {getLabels} from './label-helpers' diff --git a/src/types.ts b/src/types.ts new file mode 100644 index 00000000..78441a79 --- /dev/null +++ b/src/types.ts @@ -0,0 +1 @@ +export type Callback = () => T diff --git a/src/wait-for-dom-change.js b/src/wait-for-dom-change.js index 1344db9d..dc427501 100644 --- a/src/wait-for-dom-change.js +++ b/src/wait-for-dom-change.js @@ -6,7 +6,7 @@ import { clearTimeout, runWithRealTimers, } from './helpers' -import {getConfig} from './config' +import {getConfig} from './config.ts' let hasWarned = false diff --git a/src/wait-for.js b/src/wait-for.js index a1a49f5b..66d12ac3 100644 --- a/src/wait-for.js +++ b/src/wait-for.js @@ -9,7 +9,7 @@ import { setTimeout, clearTimeout, } from './helpers' -import {getConfig, runWithExpensiveErrorDiagnosticsDisabled} from './config' +import {getConfig, runWithExpensiveErrorDiagnosticsDisabled} from './config.ts' // This is so the stack trace the developer sees is one that's // closer to their code (because async stack traces are hard to follow). From 8c829919050274251bc2dcfd0be53576b06bbd4f Mon Sep 17 00:00:00 2001 From: marcosvega91 Date: Thu, 10 Dec 2020 18:51:03 +0100 Subject: [PATCH 5/9] chore: migrate matches.js to typescript --- src/__tests__/matches.js | 2 +- src/index.js | 2 +- src/{matches.js => matches.ts} | 69 ++++++++++++++++++++++++++++++---- src/queries/all-utils.js | 2 +- src/query-helpers.js | 2 +- src/suggestions.js | 2 +- src/types.ts | 2 + 7 files changed, 69 insertions(+), 12 deletions(-) rename src/{matches.js => matches.ts} (60%) diff --git a/src/__tests__/matches.js b/src/__tests__/matches.js index 3f5e6b3e..10bfc48a 100644 --- a/src/__tests__/matches.js +++ b/src/__tests__/matches.js @@ -1,4 +1,4 @@ -import {fuzzyMatches, matches} from '../matches' +import {fuzzyMatches, matches} from '../matches.ts' // unit tests for text match utils diff --git a/src/index.js b/src/index.js index b247bb54..87cd66e0 100644 --- a/src/index.js +++ b/src/index.js @@ -7,7 +7,7 @@ export * from './wait-for' export * from './wait-for-element' export * from './wait-for-element-to-be-removed' export * from './wait-for-dom-change' -export {getDefaultNormalizer} from './matches' +export {getDefaultNormalizer} from './matches.ts' export * from './get-node-text' export * from './events' export * from './get-queries-for-element' diff --git a/src/matches.js b/src/matches.ts similarity index 60% rename from src/matches.js rename to src/matches.ts index d9672e42..1c78594a 100644 --- a/src/matches.js +++ b/src/matches.ts @@ -1,19 +1,61 @@ -function assertNotNullOrUndefined(matcher) { - if (matcher == null) { +import {ARIARole} from 'aria-query' +import {Nullish} from './types' + +export type ByRoleMatcher = ARIARole | MatcherFunction | {} + +export type Matcher = MatcherFunction | RegExp | string + +export type MatcherFunction = ( + content: string, + element: Nullish, +) => boolean + +export type NormalizerFn = (text: string) => string + +export interface DefaultNormalizerOptions { + trim?: boolean + collapseWhitespace?: boolean +} + +export interface MatcherOptions { + exact?: boolean + /** Use normalizer with getDefaultNormalizer instead */ + trim?: boolean + /** Use normalizer with getDefaultNormalizer instead */ + collapseWhitespace?: boolean + normalizer?: NormalizerFn + /** suppress suggestions for a specific query */ + suggest?: boolean +} + +export type NormalizerOptions = DefaultNormalizerOptions & { + normalizer?: NormalizerFn +} + +function assertNotNullOrUndefined( + matcher: T, +): asserts matcher is NonNullable { + if (matcher === null || matcher === undefined) { throw new Error( + // eslint-disable-next-line @typescript-eslint/restrict-template-expressions `It looks like ${matcher} was passed instead of a matcher. Did you do something like getByText(${matcher})?`, ) } } -function fuzzyMatches(textToMatch, node, matcher, normalizer) { +function fuzzyMatches( + textToMatch: Nullish, + node: Nullish, + matcher: Nullish, + normalizer: NormalizerFn, +) { if (typeof textToMatch !== 'string') { return false } - assertNotNullOrUndefined(matcher) const normalizedText = normalizer(textToMatch) + if (typeof matcher === 'string') { return normalizedText.toLowerCase().includes(matcher.toLowerCase()) } else if (typeof matcher === 'function') { @@ -23,7 +65,12 @@ function fuzzyMatches(textToMatch, node, matcher, normalizer) { } } -function matches(textToMatch, node, matcher, normalizer) { +function matches( + textToMatch: Nullish, + node: Nullish, + matcher: Nullish, + normalizer: NormalizerFn, +) { if (typeof textToMatch !== 'string') { return false } @@ -40,7 +87,10 @@ function matches(textToMatch, node, matcher, normalizer) { } } -function getDefaultNormalizer({trim = true, collapseWhitespace = true} = {}) { +function getDefaultNormalizer({ + trim = true, + collapseWhitespace = true, +}: DefaultNormalizerOptions = {}): NormalizerFn { return text => { let normalizedText = text normalizedText = trim ? normalizedText.trim() : normalizedText @@ -60,7 +110,12 @@ function getDefaultNormalizer({trim = true, collapseWhitespace = true} = {}) { * @param {Function|undefined} normalizer The user-specified normalizer * @returns {Function} A normalizer */ -function makeNormalizer({trim, collapseWhitespace, normalizer}) { + +function makeNormalizer({ + trim, + collapseWhitespace, + normalizer, +}: NormalizerOptions) { if (normalizer) { // User has specified a custom normalizer if ( diff --git a/src/queries/all-utils.js b/src/queries/all-utils.js index c24a51d6..7c19b216 100644 --- a/src/queries/all-utils.js +++ b/src/queries/all-utils.js @@ -1,4 +1,4 @@ -export * from '../matches' +export * from '../matches.ts' export * from '../get-node-text' export * from '../query-helpers' export * from '../config.ts' diff --git a/src/query-helpers.js b/src/query-helpers.js index 16395e7e..c6c9868a 100644 --- a/src/query-helpers.js +++ b/src/query-helpers.js @@ -1,5 +1,5 @@ import {getSuggestedQuery} from './suggestions' -import {fuzzyMatches, matches, makeNormalizer} from './matches' +import {fuzzyMatches, matches, makeNormalizer} from './matches.ts' import {waitFor} from './wait-for' import {getConfig} from './config.ts' diff --git a/src/suggestions.js b/src/suggestions.js index b1e11985..0fe678c0 100644 --- a/src/suggestions.js +++ b/src/suggestions.js @@ -1,5 +1,5 @@ import {computeAccessibleName} from 'dom-accessibility-api' -import {getDefaultNormalizer} from './matches' +import {getDefaultNormalizer} from './matches.ts' import {getNodeText} from './get-node-text' import {DEFAULT_IGNORE_TAGS, getConfig} from './config.ts' import {getImplicitAriaRoles, isInaccessible} from './role-helpers' diff --git a/src/types.ts b/src/types.ts index 78441a79..1ae25051 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1 +1,3 @@ +export type Nullish = T | null | undefined + export type Callback = () => T From 2da06c8c1e2a5c9d98195b4de8f64f3516e5f8bc Mon Sep 17 00:00:00 2001 From: marcosvega91 Date: Thu, 10 Dec 2020 19:25:51 +0100 Subject: [PATCH 6/9] chore: use types from old folder --- src/config.ts | 21 ++------------------ src/matches.ts | 40 +++++++-------------------------------- src/types.ts | 3 --- tests/jest.config.dom.js | 2 ++ tests/jest.config.node.js | 2 ++ types/config.d.ts | 4 +++- types/matches.d.ts | 12 ++++++++++-- types/utils.d.ts | 7 +++++++ 8 files changed, 33 insertions(+), 58 deletions(-) delete mode 100644 src/types.ts create mode 100644 types/utils.d.ts diff --git a/src/config.ts b/src/config.ts index 88414b82..a13f4b3e 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,23 +1,6 @@ +import {Config, ConfigFn} from '../types/config' +import {Callback} from '../types/utils' import {prettyDOM} from './pretty-dom' -import {Callback} from './types' - -export interface Config { - testIdAttribute: string - // eslint-disable-next-line @typescript-eslint/no-explicit-any - asyncWrapper(cb: (...args: any[]) => any): Promise - // eslint-disable-next-line @typescript-eslint/no-explicit-any - eventWrapper(cb: (...args: any[]) => any): void - asyncUtilTimeout: number - computedStyleSupportsPseudoElements: boolean - defaultHidden: boolean - showOriginalStackTrace: boolean - throwSuggestions: boolean - getElementError: (message: string | null, container: Element) => Error -} - -export interface ConfigFn { - (existingConfig: Config): Partial -} interface InternalConfig { _disableExpensiveErrorDiagnostics: boolean diff --git a/src/matches.ts b/src/matches.ts index 1c78594a..8e132724 100644 --- a/src/matches.ts +++ b/src/matches.ts @@ -1,36 +1,10 @@ -import {ARIARole} from 'aria-query' -import {Nullish} from './types' - -export type ByRoleMatcher = ARIARole | MatcherFunction | {} - -export type Matcher = MatcherFunction | RegExp | string - -export type MatcherFunction = ( - content: string, - element: Nullish, -) => boolean - -export type NormalizerFn = (text: string) => string - -export interface DefaultNormalizerOptions { - trim?: boolean - collapseWhitespace?: boolean -} - -export interface MatcherOptions { - exact?: boolean - /** Use normalizer with getDefaultNormalizer instead */ - trim?: boolean - /** Use normalizer with getDefaultNormalizer instead */ - collapseWhitespace?: boolean - normalizer?: NormalizerFn - /** suppress suggestions for a specific query */ - suggest?: boolean -} - -export type NormalizerOptions = DefaultNormalizerOptions & { - normalizer?: NormalizerFn -} +import { + Matcher, + NormalizerFn, + NormalizerOptions, + DefaultNormalizerOptions, +} from '../types' +import {Nullish} from '../types/utils' function assertNotNullOrUndefined( matcher: T, diff --git a/src/types.ts b/src/types.ts deleted file mode 100644 index 1ae25051..00000000 --- a/src/types.ts +++ /dev/null @@ -1,3 +0,0 @@ -export type Nullish = T | null | undefined - -export type Callback = () => T diff --git a/tests/jest.config.dom.js b/tests/jest.config.dom.js index 72b3b24b..56d2c0dc 100644 --- a/tests/jest.config.dom.js +++ b/tests/jest.config.dom.js @@ -3,6 +3,8 @@ const baseConfig = require('kcd-scripts/jest') module.exports = { ...baseConfig, + moduleFileExtensions: [...baseConfig.moduleFileExtensions, 'd.ts'], + moduleDirectories: [...baseConfig.moduleDirectories, 'types'], rootDir: path.join(__dirname, '..'), displayName: 'dom', coveragePathIgnorePatterns: [ diff --git a/tests/jest.config.node.js b/tests/jest.config.node.js index bf37b60b..3bc350ab 100644 --- a/tests/jest.config.node.js +++ b/tests/jest.config.node.js @@ -3,6 +3,8 @@ const baseConfig = require('kcd-scripts/jest') module.exports = { ...baseConfig, + moduleFileExtensions: [...baseConfig.moduleFileExtensions, 'd.ts'], + moduleDirectories: [...baseConfig.moduleDirectories, 'types'], rootDir: path.join(__dirname, '..'), displayName: 'node', testEnvironment: 'jest-environment-node', diff --git a/types/config.d.ts b/types/config.d.ts index c93237a2..c8e239b6 100644 --- a/types/config.d.ts +++ b/types/config.d.ts @@ -1,13 +1,15 @@ export interface Config { testIdAttribute: string + // eslint-disable-next-line @typescript-eslint/no-explicit-any asyncWrapper(cb: (...args: any[]) => any): Promise + // eslint-disable-next-line @typescript-eslint/no-explicit-any eventWrapper(cb: (...args: any[]) => any): void asyncUtilTimeout: number computedStyleSupportsPseudoElements: boolean defaultHidden: boolean showOriginalStackTrace: boolean throwSuggestions: boolean - getElementError: (message: string, container: HTMLElement) => Error + getElementError: (message: string | null, container: Element) => Error } export interface ConfigFn { diff --git a/types/matches.d.ts b/types/matches.d.ts index d4da667b..f858686c 100644 --- a/types/matches.d.ts +++ b/types/matches.d.ts @@ -1,7 +1,11 @@ import {ARIARole} from 'aria-query' +import {Nullish} from './utils' -export type MatcherFunction = (content: string, element: HTMLElement) => boolean -export type Matcher = MatcherFunction | {} +export type MatcherFunction = ( + content: string, + element: Nullish, +) => boolean +export type Matcher = MatcherFunction | RegExp | string // Get autocomplete for ARIARole union types, while still supporting another string // Ref: https://github.com/microsoft/TypeScript/issues/29729#issuecomment-505826972 @@ -9,6 +13,10 @@ export type ByRoleMatcher = ARIARole | MatcherFunction | {} export type NormalizerFn = (text: string) => string +export type NormalizerOptions = DefaultNormalizerOptions & { + normalizer?: NormalizerFn +} + export interface MatcherOptions { exact?: boolean /** Use normalizer with getDefaultNormalizer instead */ diff --git a/types/utils.d.ts b/types/utils.d.ts new file mode 100644 index 00000000..cf679f80 --- /dev/null +++ b/types/utils.d.ts @@ -0,0 +1,7 @@ +export type Nullish = T | null | undefined + +export type Callback = () => T + +export function isNotNull(arg: T): arg is NonNullable { + return arg !== null +} From 99424348b7903629ecd218ec21bcba9c09d7fc00 Mon Sep 17 00:00:00 2001 From: marcosvega91 Date: Thu, 10 Dec 2020 19:48:21 +0100 Subject: [PATCH 7/9] chore: migrate label-helpers to typescript --- src/__tests__/label-helpers.js | 2 +- src/{label-helpers.js => label-helpers.ts} | 37 ++++++++++++++-------- src/queries/label-text.js | 2 +- src/suggestions.js | 2 +- src/utils.ts | 3 ++ types/utils.d.ts | 4 --- 6 files changed, 30 insertions(+), 20 deletions(-) rename src/{label-helpers.js => label-helpers.ts} (62%) create mode 100644 src/utils.ts diff --git a/src/__tests__/label-helpers.js b/src/__tests__/label-helpers.js index 4fd2448f..47d6700b 100644 --- a/src/__tests__/label-helpers.js +++ b/src/__tests__/label-helpers.js @@ -1,4 +1,4 @@ -import {getRealLabels} from '../label-helpers' +import {getRealLabels} from '../label-helpers.ts' test('hidden inputs are not labelable', () => { const element = document.createElement('input') diff --git a/src/label-helpers.js b/src/label-helpers.ts similarity index 62% rename from src/label-helpers.js rename to src/label-helpers.ts index d71b4f8e..1965a8ee 100644 --- a/src/label-helpers.js +++ b/src/label-helpers.ts @@ -1,3 +1,4 @@ +import {isNotNull} from './utils' import {TEXT_NODE} from './helpers' const labelledNodeNames = [ @@ -10,7 +11,9 @@ const labelledNodeNames = [ 'input', ] -function getTextContent(node) { +function getTextContent( + node: Node | Element | HTMLInputElement, +): string | null { if (labelledNodeNames.includes(node.nodeName.toLowerCase())) { return '' } @@ -22,19 +25,24 @@ function getTextContent(node) { .join('') } -function getLabelContent(node) { +function getLabelContent(node: Node | Element | HTMLInputElement) { let textContent - if (node.tagName.toLowerCase() === 'label') { + if ('tagName' in node && node.tagName.toLowerCase() === 'label') { textContent = getTextContent(node) + } else if ('value' in node) { + textContent = node.value } else { - textContent = node.value || node.textContent + textContent = node.textContent } return textContent } // Based on https://github.com/eps1lon/dom-accessibility-api/pull/352 -function getRealLabels(element) { - if (element.labels !== undefined) return element.labels ?? [] +function getRealLabels(element: Element | HTMLInputElement) { + // for old browsers + // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition + if ('labels' in element && element.labels !== undefined) + return element.labels ?? [] if (!isLabelable(element)) return [] @@ -42,17 +50,21 @@ function getRealLabels(element) { return Array.from(labels).filter(label => label.control === element) } -function isLabelable(element) { +function isLabelable(element: Element) { + const labelableRegex = /BUTTON|METER|OUTPUT|PROGRESS|SELECT|TEXTAREA/ return ( - element.tagName.match(/BUTTON|METER|OUTPUT|PROGRESS|SELECT|TEXTAREA/) || + labelableRegex.test(element.tagName) || (element.tagName === 'INPUT' && element.getAttribute('type') !== 'hidden') ) } -function getLabels(container, element, {selector = '*'} = {}) { - const labelsId = element.getAttribute('aria-labelledby') - ? element.getAttribute('aria-labelledby').split(' ') - : [] +function getLabels( + container: Element, + element: Element, + {selector = '*'} = {}, +) { + const ariaLabelledBy = element.getAttribute('aria-labelledby') + const labelsId = isNotNull(ariaLabelledBy) ? ariaLabelledBy.split(' ') : [] return labelsId.length ? labelsId.map(labelId => { const labellingElement = container.querySelector(`[id="${labelId}"]`) @@ -67,7 +79,6 @@ function getLabels(container, element, {selector = '*'} = {}) { const labelledFormControl = Array.from( label.querySelectorAll(formControlSelector), ).filter(formControlElement => formControlElement.matches(selector))[0] - return {content: textToMatch, formControl: labelledFormControl} }) } diff --git a/src/queries/label-text.js b/src/queries/label-text.js index aba17645..cebf990b 100644 --- a/src/queries/label-text.js +++ b/src/queries/label-text.js @@ -1,6 +1,6 @@ import {getConfig} from '../config.ts' import {checkContainerType} from '../helpers' -import {getLabels, getRealLabels, getLabelContent} from '../label-helpers' +import {getLabels, getRealLabels, getLabelContent} from '../label-helpers.ts' import { fuzzyMatches, matches, diff --git a/src/suggestions.js b/src/suggestions.js index 0fe678c0..27b6d716 100644 --- a/src/suggestions.js +++ b/src/suggestions.js @@ -3,7 +3,7 @@ import {getDefaultNormalizer} from './matches.ts' import {getNodeText} from './get-node-text' import {DEFAULT_IGNORE_TAGS, getConfig} from './config.ts' import {getImplicitAriaRoles, isInaccessible} from './role-helpers' -import {getLabels} from './label-helpers' +import {getLabels} from './label-helpers.ts' const normalize = getDefaultNormalizer() diff --git a/src/utils.ts b/src/utils.ts new file mode 100644 index 00000000..7af44d68 --- /dev/null +++ b/src/utils.ts @@ -0,0 +1,3 @@ +export function isNotNull(arg: T): arg is NonNullable { + return arg !== null +} diff --git a/types/utils.d.ts b/types/utils.d.ts index cf679f80..1ae25051 100644 --- a/types/utils.d.ts +++ b/types/utils.d.ts @@ -1,7 +1,3 @@ export type Nullish = T | null | undefined export type Callback = () => T - -export function isNotNull(arg: T): arg is NonNullable { - return arg !== null -} From 03f20e1b6bbadda182669692456ffddc1812b755 Mon Sep 17 00:00:00 2001 From: marcosvega91 Date: Fri, 11 Dec 2020 09:44:36 +0100 Subject: [PATCH 8/9] fix: apply review suggestions --- src/config.ts | 6 +++--- src/label-helpers.ts | 16 +++++++--------- src/matches.ts | 3 ++- src/utils.ts | 3 --- tests/jest.config.dom.js | 2 -- tests/jest.config.node.js | 2 -- types/matches.d.ts | 5 +++-- types/utils.d.ts | 3 --- 8 files changed, 15 insertions(+), 25 deletions(-) delete mode 100644 src/utils.ts delete mode 100644 types/utils.d.ts diff --git a/src/config.ts b/src/config.ts index a13f4b3e..d37e46d0 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,15 +1,15 @@ import {Config, ConfigFn} from '../types/config' -import {Callback} from '../types/utils' import {prettyDOM} from './pretty-dom' -interface InternalConfig { +type Callback = () => T +interface InternalConfig extends Config { _disableExpensiveErrorDiagnostics: boolean } // It would be cleaner for this to live inside './queries', but // other parts of the code assume that all exports from // './queries' are query functions. -let config: Config & InternalConfig = { +let config: InternalConfig = { testIdAttribute: 'data-testid', asyncUtilTimeout: 1000, // this is to support React's async `act` function. diff --git a/src/label-helpers.ts b/src/label-helpers.ts index 1965a8ee..2e5a9a39 100644 --- a/src/label-helpers.ts +++ b/src/label-helpers.ts @@ -1,4 +1,3 @@ -import {isNotNull} from './utils' import {TEXT_NODE} from './helpers' const labelledNodeNames = [ @@ -25,21 +24,20 @@ function getTextContent( .join('') } -function getLabelContent(node: Node | Element | HTMLInputElement) { +function getLabelContent(element: Element | HTMLInputElement) { let textContent - if ('tagName' in node && node.tagName.toLowerCase() === 'label') { - textContent = getTextContent(node) - } else if ('value' in node) { - textContent = node.value + if (element.tagName.toLowerCase() === 'label') { + textContent = getTextContent(element) + } else if ('value' in element) { + return element.value } else { - textContent = node.textContent + textContent = element.textContent } return textContent } // Based on https://github.com/eps1lon/dom-accessibility-api/pull/352 function getRealLabels(element: Element | HTMLInputElement) { - // for old browsers // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition if ('labels' in element && element.labels !== undefined) return element.labels ?? [] @@ -64,7 +62,7 @@ function getLabels( {selector = '*'} = {}, ) { const ariaLabelledBy = element.getAttribute('aria-labelledby') - const labelsId = isNotNull(ariaLabelledBy) ? ariaLabelledBy.split(' ') : [] + const labelsId = ariaLabelledBy ? ariaLabelledBy.split(' ') : [] return labelsId.length ? labelsId.map(labelId => { const labellingElement = container.querySelector(`[id="${labelId}"]`) diff --git a/src/matches.ts b/src/matches.ts index 8e132724..b56b0cfc 100644 --- a/src/matches.ts +++ b/src/matches.ts @@ -4,7 +4,8 @@ import { NormalizerOptions, DefaultNormalizerOptions, } from '../types' -import {Nullish} from '../types/utils' + +type Nullish = T | null | undefined function assertNotNullOrUndefined( matcher: T, diff --git a/src/utils.ts b/src/utils.ts deleted file mode 100644 index 7af44d68..00000000 --- a/src/utils.ts +++ /dev/null @@ -1,3 +0,0 @@ -export function isNotNull(arg: T): arg is NonNullable { - return arg !== null -} diff --git a/tests/jest.config.dom.js b/tests/jest.config.dom.js index 56d2c0dc..72b3b24b 100644 --- a/tests/jest.config.dom.js +++ b/tests/jest.config.dom.js @@ -3,8 +3,6 @@ const baseConfig = require('kcd-scripts/jest') module.exports = { ...baseConfig, - moduleFileExtensions: [...baseConfig.moduleFileExtensions, 'd.ts'], - moduleDirectories: [...baseConfig.moduleDirectories, 'types'], rootDir: path.join(__dirname, '..'), displayName: 'dom', coveragePathIgnorePatterns: [ diff --git a/tests/jest.config.node.js b/tests/jest.config.node.js index 3bc350ab..bf37b60b 100644 --- a/tests/jest.config.node.js +++ b/tests/jest.config.node.js @@ -3,8 +3,6 @@ const baseConfig = require('kcd-scripts/jest') module.exports = { ...baseConfig, - moduleFileExtensions: [...baseConfig.moduleFileExtensions, 'd.ts'], - moduleDirectories: [...baseConfig.moduleDirectories, 'types'], rootDir: path.join(__dirname, '..'), displayName: 'node', testEnvironment: 'jest-environment-node', diff --git a/types/matches.d.ts b/types/matches.d.ts index f858686c..03f9a4b8 100644 --- a/types/matches.d.ts +++ b/types/matches.d.ts @@ -1,5 +1,6 @@ import {ARIARole} from 'aria-query' -import {Nullish} from './utils' + +type Nullish = T | null | undefined export type MatcherFunction = ( content: string, @@ -13,7 +14,7 @@ export type ByRoleMatcher = ARIARole | MatcherFunction | {} export type NormalizerFn = (text: string) => string -export type NormalizerOptions = DefaultNormalizerOptions & { +export interface NormalizerOptions extends DefaultNormalizerOptions { normalizer?: NormalizerFn } diff --git a/types/utils.d.ts b/types/utils.d.ts deleted file mode 100644 index 1ae25051..00000000 --- a/types/utils.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -export type Nullish = T | null | undefined - -export type Callback = () => T From a2b9e44767ce35d84d3613b80f9557f4dfcdcac0 Mon Sep 17 00:00:00 2001 From: eps1lon Date: Fri, 11 Dec 2020 14:54:37 +0100 Subject: [PATCH 9/9] Squashed commit of the following: commit 6563b9644463e671c931472f7cff06e700f1ba48 Author: eps1lon Date: Fri Dec 11 14:33:36 2020 +0100 Remove .ts extensions commit 6c08f92ca9d8f13919ef34e73582710a51dd84d7 Author: eps1lon Date: Fri Dec 11 14:17:30 2020 +0100 Polish - revert most runtime changes - test over exec because semantics --- package.json | 5 ++++- src/__tests__/config.js | 2 +- src/__tests__/element-queries.js | 2 +- src/__tests__/get-by-errors.js | 2 +- src/__tests__/label-helpers.js | 2 +- src/__tests__/matches.js | 2 +- src/__tests__/query-helper.js | 2 +- src/__tests__/role.js | 2 +- src/__tests__/suggestions.js | 2 +- src/__tests__/wait-for.js | 2 +- src/events.js | 2 +- src/index.js | 4 ++-- src/label-helpers.ts | 20 +++++++++----------- src/matches.ts | 2 +- src/queries/all-utils.js | 4 ++-- src/queries/label-text.js | 4 ++-- src/queries/text.js | 2 +- src/query-helpers.js | 4 ++-- src/role-helpers.js | 2 +- src/suggestions.js | 6 +++--- src/wait-for-dom-change.js | 2 +- src/wait-for.js | 2 +- 22 files changed, 39 insertions(+), 38 deletions(-) diff --git a/package.json b/package.json index aed90c63..27747f6e 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,10 @@ "typescript": "^4.1.2" }, "eslintConfig": { - "extends": "./node_modules/kcd-scripts/eslint.js", + "extends": [ + "./node_modules/kcd-scripts/eslint.js", + "plugin:import/typescript" + ], "rules": { "import/prefer-default-export": "off", "import/no-unassigned-import": "off", diff --git a/src/__tests__/config.js b/src/__tests__/config.js index dbbd01b9..40123a53 100644 --- a/src/__tests__/config.js +++ b/src/__tests__/config.js @@ -1,4 +1,4 @@ -import {configure, getConfig} from '../config.ts' +import {configure, getConfig} from '../config' describe('configuration API', () => { let originalConfig diff --git a/src/__tests__/element-queries.js b/src/__tests__/element-queries.js index 6ce359ff..3e3ee6de 100644 --- a/src/__tests__/element-queries.js +++ b/src/__tests__/element-queries.js @@ -1,4 +1,4 @@ -import {configure} from '../config.ts' +import {configure} from '../config' import {render, renderIntoDocument} from './helpers/test-utils' beforeEach(() => { diff --git a/src/__tests__/get-by-errors.js b/src/__tests__/get-by-errors.js index 9ff56f23..c7e8cadf 100644 --- a/src/__tests__/get-by-errors.js +++ b/src/__tests__/get-by-errors.js @@ -1,6 +1,6 @@ import cases from 'jest-in-case' import {screen} from '../' -import {configure, getConfig} from '../config.ts' +import {configure, getConfig} from '../config' import {render} from './helpers/test-utils' const originalConfig = getConfig() diff --git a/src/__tests__/label-helpers.js b/src/__tests__/label-helpers.js index 47d6700b..4fd2448f 100644 --- a/src/__tests__/label-helpers.js +++ b/src/__tests__/label-helpers.js @@ -1,4 +1,4 @@ -import {getRealLabels} from '../label-helpers.ts' +import {getRealLabels} from '../label-helpers' test('hidden inputs are not labelable', () => { const element = document.createElement('input') diff --git a/src/__tests__/matches.js b/src/__tests__/matches.js index 10bfc48a..3f5e6b3e 100644 --- a/src/__tests__/matches.js +++ b/src/__tests__/matches.js @@ -1,4 +1,4 @@ -import {fuzzyMatches, matches} from '../matches.ts' +import {fuzzyMatches, matches} from '../matches' // unit tests for text match utils diff --git a/src/__tests__/query-helper.js b/src/__tests__/query-helper.js index db536c6d..7e53ab03 100644 --- a/src/__tests__/query-helper.js +++ b/src/__tests__/query-helper.js @@ -1,5 +1,5 @@ import * as queryHelpers from '../query-helpers' -import {configure, getConfig} from '../config.ts' +import {configure, getConfig} from '../config' const originalConfig = getConfig() beforeEach(() => { diff --git a/src/__tests__/role.js b/src/__tests__/role.js index 3da485f6..109d2e62 100644 --- a/src/__tests__/role.js +++ b/src/__tests__/role.js @@ -1,4 +1,4 @@ -import {configure, getConfig} from '../config.ts' +import {configure, getConfig} from '../config' import {getQueriesForElement} from '../get-queries-for-element' import {render, renderIntoDocument} from './helpers/test-utils' diff --git a/src/__tests__/suggestions.js b/src/__tests__/suggestions.js index d82d40ce..3bb5364d 100644 --- a/src/__tests__/suggestions.js +++ b/src/__tests__/suggestions.js @@ -1,4 +1,4 @@ -import {configure} from '../config.ts' +import {configure} from '../config' import {screen, getSuggestedQuery} from '..' import {renderIntoDocument, render} from './helpers/test-utils' diff --git a/src/__tests__/wait-for.js b/src/__tests__/wait-for.js index e1eb3665..7235f6a5 100644 --- a/src/__tests__/wait-for.js +++ b/src/__tests__/wait-for.js @@ -1,5 +1,5 @@ import {waitFor} from '../' -import {configure, getConfig} from '../config.ts' +import {configure, getConfig} from '../config' import {renderIntoDocument} from './helpers/test-utils' function deferred() { diff --git a/src/events.js b/src/events.js index acf77119..57446bf8 100644 --- a/src/events.js +++ b/src/events.js @@ -1,4 +1,4 @@ -import {getConfig} from './config.ts' +import {getConfig} from './config' import {getWindowFromNode} from './helpers' import {eventMap, eventAliasMap} from './event-map' diff --git a/src/index.js b/src/index.js index 87cd66e0..2a279383 100644 --- a/src/index.js +++ b/src/index.js @@ -7,7 +7,7 @@ export * from './wait-for' export * from './wait-for-element' export * from './wait-for-element-to-be-removed' export * from './wait-for-dom-change' -export {getDefaultNormalizer} from './matches.ts' +export {getDefaultNormalizer} from './matches' export * from './get-node-text' export * from './events' export * from './get-queries-for-element' @@ -15,7 +15,7 @@ export * from './screen' export * from './query-helpers' export {getRoles, logRoles, isInaccessible} from './role-helpers' export * from './pretty-dom' -export {configure, getConfig} from './config.ts' +export {configure, getConfig} from './config' export * from './suggestions' export { diff --git a/src/label-helpers.ts b/src/label-helpers.ts index 2e5a9a39..e8010a1b 100644 --- a/src/label-helpers.ts +++ b/src/label-helpers.ts @@ -24,23 +24,22 @@ function getTextContent( .join('') } -function getLabelContent(element: Element | HTMLInputElement) { - let textContent +function getLabelContent(element: Element): string | null { + let textContent: string | null if (element.tagName.toLowerCase() === 'label') { textContent = getTextContent(element) - } else if ('value' in element) { - return element.value } else { - textContent = element.textContent + textContent = (element as HTMLInputElement).value || element.textContent } return textContent } // Based on https://github.com/eps1lon/dom-accessibility-api/pull/352 -function getRealLabels(element: Element | HTMLInputElement) { - // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition - if ('labels' in element && element.labels !== undefined) - return element.labels ?? [] +function getRealLabels(element: Element) { + // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- types are not aware of older browsers that don't implement `labels` + if ((element as HTMLInputElement).labels !== undefined) { + return (element as HTMLInputElement).labels ?? [] + } if (!isLabelable(element)) return [] @@ -49,9 +48,8 @@ function getRealLabels(element: Element | HTMLInputElement) { } function isLabelable(element: Element) { - const labelableRegex = /BUTTON|METER|OUTPUT|PROGRESS|SELECT|TEXTAREA/ return ( - labelableRegex.test(element.tagName) || + /BUTTON|METER|OUTPUT|PROGRESS|SELECT|TEXTAREA/.test(element.tagName) || (element.tagName === 'INPUT' && element.getAttribute('type') !== 'hidden') ) } diff --git a/src/matches.ts b/src/matches.ts index b56b0cfc..5aecb416 100644 --- a/src/matches.ts +++ b/src/matches.ts @@ -12,7 +12,7 @@ function assertNotNullOrUndefined( ): asserts matcher is NonNullable { if (matcher === null || matcher === undefined) { throw new Error( - // eslint-disable-next-line @typescript-eslint/restrict-template-expressions + // eslint-disable-next-line @typescript-eslint/restrict-template-expressions -- implicitly converting `T` to `string` `It looks like ${matcher} was passed instead of a matcher. Did you do something like getByText(${matcher})?`, ) } diff --git a/src/queries/all-utils.js b/src/queries/all-utils.js index 7c19b216..c4ce9c43 100644 --- a/src/queries/all-utils.js +++ b/src/queries/all-utils.js @@ -1,4 +1,4 @@ -export * from '../matches.ts' +export * from '../matches' export * from '../get-node-text' export * from '../query-helpers' -export * from '../config.ts' +export * from '../config' diff --git a/src/queries/label-text.js b/src/queries/label-text.js index cebf990b..083cd263 100644 --- a/src/queries/label-text.js +++ b/src/queries/label-text.js @@ -1,6 +1,6 @@ -import {getConfig} from '../config.ts' +import {getConfig} from '../config' import {checkContainerType} from '../helpers' -import {getLabels, getRealLabels, getLabelContent} from '../label-helpers.ts' +import {getLabels, getRealLabels, getLabelContent} from '../label-helpers' import { fuzzyMatches, matches, diff --git a/src/queries/text.js b/src/queries/text.js index 7406d41f..903bba25 100644 --- a/src/queries/text.js +++ b/src/queries/text.js @@ -1,6 +1,6 @@ import {wrapAllByQueryWithSuggestion} from '../query-helpers' import {checkContainerType} from '../helpers' -import {DEFAULT_IGNORE_TAGS} from '../config.ts' +import {DEFAULT_IGNORE_TAGS} from '../config' import { fuzzyMatches, matches, diff --git a/src/query-helpers.js b/src/query-helpers.js index c6c9868a..48ff176d 100644 --- a/src/query-helpers.js +++ b/src/query-helpers.js @@ -1,7 +1,7 @@ import {getSuggestedQuery} from './suggestions' -import {fuzzyMatches, matches, makeNormalizer} from './matches.ts' +import {fuzzyMatches, matches, makeNormalizer} from './matches' import {waitFor} from './wait-for' -import {getConfig} from './config.ts' +import {getConfig} from './config' function getElementError(message, container) { return getConfig().getElementError(message, container) diff --git a/src/role-helpers.js b/src/role-helpers.js index 48f632e3..c7d64076 100644 --- a/src/role-helpers.js +++ b/src/role-helpers.js @@ -1,7 +1,7 @@ import {elementRoles} from 'aria-query' import {computeAccessibleName} from 'dom-accessibility-api' import {prettyDOM} from './pretty-dom' -import {getConfig} from './config.ts' +import {getConfig} from './config' const elementRoleList = buildElementRoleList(elementRoles) diff --git a/src/suggestions.js b/src/suggestions.js index 27b6d716..ba5a1f29 100644 --- a/src/suggestions.js +++ b/src/suggestions.js @@ -1,9 +1,9 @@ import {computeAccessibleName} from 'dom-accessibility-api' -import {getDefaultNormalizer} from './matches.ts' +import {getDefaultNormalizer} from './matches' import {getNodeText} from './get-node-text' -import {DEFAULT_IGNORE_TAGS, getConfig} from './config.ts' +import {DEFAULT_IGNORE_TAGS, getConfig} from './config' import {getImplicitAriaRoles, isInaccessible} from './role-helpers' -import {getLabels} from './label-helpers.ts' +import {getLabels} from './label-helpers' const normalize = getDefaultNormalizer() diff --git a/src/wait-for-dom-change.js b/src/wait-for-dom-change.js index dc427501..1344db9d 100644 --- a/src/wait-for-dom-change.js +++ b/src/wait-for-dom-change.js @@ -6,7 +6,7 @@ import { clearTimeout, runWithRealTimers, } from './helpers' -import {getConfig} from './config.ts' +import {getConfig} from './config' let hasWarned = false diff --git a/src/wait-for.js b/src/wait-for.js index 66d12ac3..a1a49f5b 100644 --- a/src/wait-for.js +++ b/src/wait-for.js @@ -9,7 +9,7 @@ import { setTimeout, clearTimeout, } from './helpers' -import {getConfig, runWithExpensiveErrorDiagnosticsDisabled} from './config.ts' +import {getConfig, runWithExpensiveErrorDiagnosticsDisabled} from './config' // This is so the stack trace the developer sees is one that's // closer to their code (because async stack traces are hard to follow).