Skip to content

Commit a2b9e44

Browse files
committed
Squashed commit of the following:
commit 6563b96 Author: eps1lon <silbermann.sebastian@gmail.com> Date: Fri Dec 11 14:33:36 2020 +0100 Remove .ts extensions commit 6c08f92 Author: eps1lon <silbermann.sebastian@gmail.com> Date: Fri Dec 11 14:17:30 2020 +0100 Polish - revert most runtime changes - test over exec because semantics
1 parent 03f20e1 commit a2b9e44

22 files changed

+39
-38
lines changed

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@
5757
"typescript": "^4.1.2"
5858
},
5959
"eslintConfig": {
60-
"extends": "./node_modules/kcd-scripts/eslint.js",
60+
"extends": [
61+
"./node_modules/kcd-scripts/eslint.js",
62+
"plugin:import/typescript"
63+
],
6164
"rules": {
6265
"import/prefer-default-export": "off",
6366
"import/no-unassigned-import": "off",

src/__tests__/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {configure, getConfig} from '../config.ts'
1+
import {configure, getConfig} from '../config'
22

33
describe('configuration API', () => {
44
let originalConfig

src/__tests__/element-queries.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {configure} from '../config.ts'
1+
import {configure} from '../config'
22
import {render, renderIntoDocument} from './helpers/test-utils'
33

44
beforeEach(() => {

src/__tests__/get-by-errors.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import cases from 'jest-in-case'
22
import {screen} from '../'
3-
import {configure, getConfig} from '../config.ts'
3+
import {configure, getConfig} from '../config'
44
import {render} from './helpers/test-utils'
55

66
const originalConfig = getConfig()

src/__tests__/label-helpers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {getRealLabels} from '../label-helpers.ts'
1+
import {getRealLabels} from '../label-helpers'
22

33
test('hidden inputs are not labelable', () => {
44
const element = document.createElement('input')

src/__tests__/matches.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {fuzzyMatches, matches} from '../matches.ts'
1+
import {fuzzyMatches, matches} from '../matches'
22

33
// unit tests for text match utils
44

src/__tests__/query-helper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as queryHelpers from '../query-helpers'
2-
import {configure, getConfig} from '../config.ts'
2+
import {configure, getConfig} from '../config'
33

44
const originalConfig = getConfig()
55
beforeEach(() => {

src/__tests__/role.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {configure, getConfig} from '../config.ts'
1+
import {configure, getConfig} from '../config'
22
import {getQueriesForElement} from '../get-queries-for-element'
33
import {render, renderIntoDocument} from './helpers/test-utils'
44

src/__tests__/suggestions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {configure} from '../config.ts'
1+
import {configure} from '../config'
22
import {screen, getSuggestedQuery} from '..'
33
import {renderIntoDocument, render} from './helpers/test-utils'
44

src/__tests__/wait-for.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {waitFor} from '../'
2-
import {configure, getConfig} from '../config.ts'
2+
import {configure, getConfig} from '../config'
33
import {renderIntoDocument} from './helpers/test-utils'
44

55
function deferred() {

src/events.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {getConfig} from './config.ts'
1+
import {getConfig} from './config'
22
import {getWindowFromNode} from './helpers'
33
import {eventMap, eventAliasMap} from './event-map'
44

src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ export * from './wait-for'
77
export * from './wait-for-element'
88
export * from './wait-for-element-to-be-removed'
99
export * from './wait-for-dom-change'
10-
export {getDefaultNormalizer} from './matches.ts'
10+
export {getDefaultNormalizer} from './matches'
1111
export * from './get-node-text'
1212
export * from './events'
1313
export * from './get-queries-for-element'
1414
export * from './screen'
1515
export * from './query-helpers'
1616
export {getRoles, logRoles, isInaccessible} from './role-helpers'
1717
export * from './pretty-dom'
18-
export {configure, getConfig} from './config.ts'
18+
export {configure, getConfig} from './config'
1919
export * from './suggestions'
2020

2121
export {

src/label-helpers.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,22 @@ function getTextContent(
2424
.join('')
2525
}
2626

27-
function getLabelContent(element: Element | HTMLInputElement) {
28-
let textContent
27+
function getLabelContent(element: Element): string | null {
28+
let textContent: string | null
2929
if (element.tagName.toLowerCase() === 'label') {
3030
textContent = getTextContent(element)
31-
} else if ('value' in element) {
32-
return element.value
3331
} else {
34-
textContent = element.textContent
32+
textContent = (element as HTMLInputElement).value || element.textContent
3533
}
3634
return textContent
3735
}
3836

3937
// Based on https://github.com/eps1lon/dom-accessibility-api/pull/352
40-
function getRealLabels(element: Element | HTMLInputElement) {
41-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
42-
if ('labels' in element && element.labels !== undefined)
43-
return element.labels ?? []
38+
function getRealLabels(element: Element) {
39+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- types are not aware of older browsers that don't implement `labels`
40+
if ((element as HTMLInputElement).labels !== undefined) {
41+
return (element as HTMLInputElement).labels ?? []
42+
}
4443

4544
if (!isLabelable(element)) return []
4645

@@ -49,9 +48,8 @@ function getRealLabels(element: Element | HTMLInputElement) {
4948
}
5049

5150
function isLabelable(element: Element) {
52-
const labelableRegex = /BUTTON|METER|OUTPUT|PROGRESS|SELECT|TEXTAREA/
5351
return (
54-
labelableRegex.test(element.tagName) ||
52+
/BUTTON|METER|OUTPUT|PROGRESS|SELECT|TEXTAREA/.test(element.tagName) ||
5553
(element.tagName === 'INPUT' && element.getAttribute('type') !== 'hidden')
5654
)
5755
}

src/matches.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function assertNotNullOrUndefined<T>(
1212
): asserts matcher is NonNullable<T> {
1313
if (matcher === null || matcher === undefined) {
1414
throw new Error(
15-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
15+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions -- implicitly converting `T` to `string`
1616
`It looks like ${matcher} was passed instead of a matcher. Did you do something like getByText(${matcher})?`,
1717
)
1818
}

src/queries/all-utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export * from '../matches.ts'
1+
export * from '../matches'
22
export * from '../get-node-text'
33
export * from '../query-helpers'
4-
export * from '../config.ts'
4+
export * from '../config'

src/queries/label-text.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import {getConfig} from '../config.ts'
1+
import {getConfig} from '../config'
22
import {checkContainerType} from '../helpers'
3-
import {getLabels, getRealLabels, getLabelContent} from '../label-helpers.ts'
3+
import {getLabels, getRealLabels, getLabelContent} from '../label-helpers'
44
import {
55
fuzzyMatches,
66
matches,

src/queries/text.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {wrapAllByQueryWithSuggestion} from '../query-helpers'
22
import {checkContainerType} from '../helpers'
3-
import {DEFAULT_IGNORE_TAGS} from '../config.ts'
3+
import {DEFAULT_IGNORE_TAGS} from '../config'
44
import {
55
fuzzyMatches,
66
matches,

src/query-helpers.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {getSuggestedQuery} from './suggestions'
2-
import {fuzzyMatches, matches, makeNormalizer} from './matches.ts'
2+
import {fuzzyMatches, matches, makeNormalizer} from './matches'
33
import {waitFor} from './wait-for'
4-
import {getConfig} from './config.ts'
4+
import {getConfig} from './config'
55

66
function getElementError(message, container) {
77
return getConfig().getElementError(message, container)

src/role-helpers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {elementRoles} from 'aria-query'
22
import {computeAccessibleName} from 'dom-accessibility-api'
33
import {prettyDOM} from './pretty-dom'
4-
import {getConfig} from './config.ts'
4+
import {getConfig} from './config'
55

66
const elementRoleList = buildElementRoleList(elementRoles)
77

src/suggestions.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import {computeAccessibleName} from 'dom-accessibility-api'
2-
import {getDefaultNormalizer} from './matches.ts'
2+
import {getDefaultNormalizer} from './matches'
33
import {getNodeText} from './get-node-text'
4-
import {DEFAULT_IGNORE_TAGS, getConfig} from './config.ts'
4+
import {DEFAULT_IGNORE_TAGS, getConfig} from './config'
55
import {getImplicitAriaRoles, isInaccessible} from './role-helpers'
6-
import {getLabels} from './label-helpers.ts'
6+
import {getLabels} from './label-helpers'
77

88
const normalize = getDefaultNormalizer()
99

src/wait-for-dom-change.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
clearTimeout,
77
runWithRealTimers,
88
} from './helpers'
9-
import {getConfig} from './config.ts'
9+
import {getConfig} from './config'
1010

1111
let hasWarned = false
1212

src/wait-for.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
setTimeout,
1010
clearTimeout,
1111
} from './helpers'
12-
import {getConfig, runWithExpensiveErrorDiagnosticsDisabled} from './config.ts'
12+
import {getConfig, runWithExpensiveErrorDiagnosticsDisabled} from './config'
1313

1414
// This is so the stack trace the developer sees is one that's
1515
// closer to their code (because async stack traces are hard to follow).

0 commit comments

Comments
 (0)