From 1682f5a041bf32e8671e24661eed8fa1559a6d7f Mon Sep 17 00:00:00 2001 From: Alex Krolick Date: Thu, 15 Aug 2019 12:06:56 -0700 Subject: [PATCH] fix(TS): move typings to DefinitelyTyped (#337) People should not need to make any changes to upgrade to this. We're just moving to DefinitelyTyped to improve maintenance of the typings. Co-authored-by: Kent C. Dodds --- package.json | 9 +- typings/config.d.ts | 10 -- typings/events.d.ts | 102 ----------------- typings/get-node-text.d.ts | 1 - typings/get-queries-for-element.d.ts | 33 ------ typings/index.d.ts | 20 ---- typings/matches.d.ts | 31 ------ typings/pretty-dom.d.ts | 7 -- typings/queries.d.ts | 116 -------------------- typings/query-helpers.d.ts | 62 ----------- typings/role-helpers.d.ts | 4 - typings/tsconfig.json | 14 --- typings/tslint.json | 7 -- typings/wait-for-dom-change.d.ts | 5 - typings/wait-for-element-to-be-removed.d.ts | 8 -- typings/wait-for-element.d.ts | 10 -- typings/wait.d.ts | 7 -- 17 files changed, 3 insertions(+), 443 deletions(-) delete mode 100644 typings/config.d.ts delete mode 100644 typings/events.d.ts delete mode 100644 typings/get-node-text.d.ts delete mode 100644 typings/get-queries-for-element.d.ts delete mode 100644 typings/index.d.ts delete mode 100644 typings/matches.d.ts delete mode 100644 typings/pretty-dom.d.ts delete mode 100644 typings/queries.d.ts delete mode 100644 typings/query-helpers.d.ts delete mode 100644 typings/role-helpers.d.ts delete mode 100644 typings/tsconfig.json delete mode 100644 typings/tslint.json delete mode 100644 typings/wait-for-dom-change.d.ts delete mode 100644 typings/wait-for-element-to-be-removed.d.ts delete mode 100644 typings/wait-for-element.d.ts delete mode 100644 typings/wait.d.ts diff --git a/package.json b/package.json index 5b5e91fc..001b3e3c 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,6 @@ "module": "dist/@testing-library/dom.esm.js", "umd:main": "dist/@testing-library/dom.umd.js", "source": "src/index.js", - "typings": "typings", "keywords": [ "testing", "ui", @@ -30,8 +29,7 @@ "test:update": "npm test -- --updateSnapshot --coverage", "test:debug": "node --inspect-brk ./node_modules/.bin/jest --watch --runInBand", "validate": "kcd-scripts validate", - "setup": "npm install && npm run validate -s", - "dtslint": "dtslint typings" + "setup": "npm install && npm run validate -s" }, "husky": { "hooks": { @@ -39,19 +37,18 @@ } }, "files": [ - "dist", - "typings" + "dist" ], "dependencies": { "@babel/runtime": "^7.5.5", "@sheerun/mutationobserver-shim": "^0.3.2", + "@types/testing-library__dom": "^6.0.0", "aria-query": "3.0.0", "pretty-format": "^24.8.0", "wait-for-expect": "^1.3.0" }, "devDependencies": { "@testing-library/jest-dom": "^4.0.0", - "dtslint": "^0.9.1", "jest-in-case": "^1.0.2", "jest-serializer-ansi": "^1.0.3", "jest-watch-select-projects": "^0.1.1", diff --git a/typings/config.d.ts b/typings/config.d.ts deleted file mode 100644 index 1993dfab..00000000 --- a/typings/config.d.ts +++ /dev/null @@ -1,10 +0,0 @@ -export interface IConfig { - testIdAttribute: string - asyncWrapper(cb: Function): Promise -} - -export interface IConfigFn { - (existingConfig: IConfig): Partial -} - -export function configure(configDelta: Partial | IConfigFn): void diff --git a/typings/events.d.ts b/typings/events.d.ts deleted file mode 100644 index 97d6929f..00000000 --- a/typings/events.d.ts +++ /dev/null @@ -1,102 +0,0 @@ -export type EventType = - | 'copy' - | 'cut' - | 'paste' - | 'compositionEnd' - | 'compositionStart' - | 'compositionUpdate' - | 'keyDown' - | 'keyPress' - | 'keyUp' - | 'focus' - | 'blur' - | 'focusIn' - | 'focusOut' - | 'change' - | 'input' - | 'invalid' - | 'submit' - | 'click' - | 'contextMenu' - | 'dblClick' - | 'drag' - | 'dragEnd' - | 'dragEnter' - | 'dragExit' - | 'dragLeave' - | 'dragOver' - | 'dragStart' - | 'drop' - | 'mouseDown' - | 'mouseEnter' - | 'mouseLeave' - | 'mouseMove' - | 'mouseOut' - | 'mouseOver' - | 'mouseUp' - | 'select' - | 'touchCancel' - | 'touchEnd' - | 'touchMove' - | 'touchStart' - | 'scroll' - | 'wheel' - | 'abort' - | 'canPlay' - | 'canPlayThrough' - | 'durationChange' - | 'emptied' - | 'encrypted' - | 'ended' - | 'loadedData' - | 'loadedMetadata' - | 'loadStart' - | 'pause' - | 'play' - | 'playing' - | 'progress' - | 'rateChange' - | 'seeked' - | 'seeking' - | 'stalled' - | 'suspend' - | 'timeUpdate' - | 'volumeChange' - | 'waiting' - | 'load' - | 'error' - | 'animationStart' - | 'animationEnd' - | 'animationIteration' - | 'transitionEnd' - | 'doubleClick' - | 'pointerOver' - | 'pointerEnter' - | 'pointerDown' - | 'pointerMove' - | 'pointerUp' - | 'pointerCancel' - | 'pointerOut' - | 'pointerLeave' - | 'gotPointerCapture' - | 'lostPointerCapture' - -export type FireFunction = ( - element: Document | Element | Window, - event: Event, -) => boolean -export type FireObject = { - [K in EventType]: ( - element: Document | Element | Window, - options?: {}, - ) => boolean -} -export type CreateObject = { - [K in EventType]: ( - element: Document | Element | Window, - options?: {}, - ) => Event -} - -export const createEvent: CreateObject -export const fireEvent: FireFunction & FireObject diff --git a/typings/get-node-text.d.ts b/typings/get-node-text.d.ts deleted file mode 100644 index 3f01b629..00000000 --- a/typings/get-node-text.d.ts +++ /dev/null @@ -1 +0,0 @@ -export function getNodeText(node: HTMLElement): string diff --git a/typings/get-queries-for-element.d.ts b/typings/get-queries-for-element.d.ts deleted file mode 100644 index 253d6ec4..00000000 --- a/typings/get-queries-for-element.d.ts +++ /dev/null @@ -1,33 +0,0 @@ -import {Matcher} from './matches' -import * as queries from './queries' - -export type BoundFunction = T extends ( - attribute: string, - element: HTMLElement, - text: infer P, - options: infer Q, -) => infer R - ? (text: P, options?: Q) => R - : T extends (a1: any, text: infer P, options: infer Q) => infer R - ? (text: P, options?: Q) => R - : never -export type BoundFunctions = {[P in keyof T]: BoundFunction} - -interface Query extends Function { - (container: HTMLElement, ...args: any[]): - | Error - | Promise - | Promise - | HTMLElement[] - | HTMLElement - | null -} - -interface Queries { - [T: string]: Query -} - -export function getQueriesForElement( - element: HTMLElement, - queriesToBind?: T, -): BoundFunctions diff --git a/typings/index.d.ts b/typings/index.d.ts deleted file mode 100644 index 650121b8..00000000 --- a/typings/index.d.ts +++ /dev/null @@ -1,20 +0,0 @@ -// TypeScript Version: 2.8 -import {getQueriesForElement} from './get-queries-for-element' -import * as queries from './queries' -import * as queryHelpers from './query-helpers' - -declare const within: typeof getQueriesForElement -export {queries, queryHelpers, within} - -export * from './queries' -export * from './query-helpers' -export * from './wait' -export * from './wait-for-dom-change' -export * from './wait-for-element' -export * from './wait-for-element-to-be-removed' -export * from './matches' -export * from './get-node-text' -export * from './events' -export * from './get-queries-for-element' -export * from './pretty-dom' -export * from './config' diff --git a/typings/matches.d.ts b/typings/matches.d.ts deleted file mode 100644 index 39e7b643..00000000 --- a/typings/matches.d.ts +++ /dev/null @@ -1,31 +0,0 @@ -export type MatcherFunction = (content: string, element: HTMLElement) => boolean -export type Matcher = string | RegExp | MatcherFunction - -export type NormalizerFn = (text: string) => string - -export interface MatcherOptions { - exact?: boolean - /** Use normalizer with getDefaultNormalizer instead */ - trim?: boolean - /** Use normalizer with getDefaultNormalizer instead */ - collapseWhitespace?: boolean - normalizer?: NormalizerFn -} - -export type Match = ( - textToMatch: string, - node: HTMLElement | null, - matcher: Matcher, - options?: MatcherOptions, -) => boolean - -export interface DefaultNormalizerOptions { - trim?: boolean - collapseWhitespace?: boolean -} - -export declare function getDefaultNormalizer( - options?: DefaultNormalizerOptions, -): NormalizerFn - -// N.B. Don't expose fuzzyMatches + matches here: they're not public API diff --git a/typings/pretty-dom.d.ts b/typings/pretty-dom.d.ts deleted file mode 100644 index 22b983a3..00000000 --- a/typings/pretty-dom.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -import {Options} from 'pretty-format' - -export function prettyDOM( - element: HTMLElement, - maxLength?: number, - options?: Options, -): string | false diff --git a/typings/queries.d.ts b/typings/queries.d.ts deleted file mode 100644 index 5a9ba329..00000000 --- a/typings/queries.d.ts +++ /dev/null @@ -1,116 +0,0 @@ -import {Matcher, MatcherOptions} from './matches' -import {SelectorMatcherOptions} from './query-helpers' -import {WaitForElementOptions} from './wait-for-element' - -export type QueryByBoundAttribute = ( - container: HTMLElement, - id: Matcher, - options?: MatcherOptions, -) => HTMLElement | null - -export type AllByBoundAttribute = ( - container: HTMLElement, - id: Matcher, - options?: MatcherOptions, -) => HTMLElement[] - -export type FindAllByBoundAttribute = ( - container: HTMLElement, - id: Matcher, - options?: MatcherOptions, - waitForElementOptions?: WaitForElementOptions, -) => Promise - -export type GetByBoundAttribute = ( - container: HTMLElement, - id: Matcher, - options?: MatcherOptions, -) => HTMLElement - -export type FindByBoundAttribute = ( - container: HTMLElement, - id: Matcher, - options?: MatcherOptions, - waitForElementOptions?: WaitForElementOptions, -) => Promise - -export type QueryByText = ( - container: HTMLElement, - id: Matcher, - options?: SelectorMatcherOptions, -) => HTMLElement | null - -export type AllByText = ( - container: HTMLElement, - id: Matcher, - options?: SelectorMatcherOptions, -) => HTMLElement[] - -export type FindAllByText = ( - container: HTMLElement, - id: Matcher, - options?: SelectorMatcherOptions, - waitForElementOptions?: WaitForElementOptions, -) => Promise - -export type GetByText = ( - container: HTMLElement, - id: Matcher, - options?: SelectorMatcherOptions, -) => HTMLElement - -export type FindByText = ( - container: HTMLElement, - id: Matcher, - options?: SelectorMatcherOptions, - waitForElementOptions?: WaitForElementOptions, -) => Promise - -export const getByLabelText: GetByText -export const getAllByLabelText: AllByText -export const queryByLabelText: QueryByText -export const queryAllByLabelText: AllByText -export const findByLabelText: FindByText -export const findAllByLabelText: FindAllByText -export const getByPlaceholderText: GetByBoundAttribute -export const getAllByPlaceholderText: AllByBoundAttribute -export const queryByPlaceholderText: QueryByBoundAttribute -export const queryAllByPlaceholderText: AllByBoundAttribute -export const findByPlaceholderText: FindByBoundAttribute -export const findAllByPlaceholderText: FindAllByBoundAttribute -export const getByText: GetByText -export const getAllByText: AllByText -export const queryByText: QueryByText -export const queryAllByText: AllByText -export const findByText: FindByText -export const findAllByText: FindAllByText -export const getByAltText: GetByBoundAttribute -export const getAllByAltText: AllByBoundAttribute -export const queryByAltText: QueryByBoundAttribute -export const queryAllByAltText: AllByBoundAttribute -export const findByAltText: FindByBoundAttribute -export const findAllByAltText: FindAllByBoundAttribute -export const getByTitle: GetByBoundAttribute -export const getAllByTitle: AllByBoundAttribute -export const queryByTitle: QueryByBoundAttribute -export const queryAllByTitle: AllByBoundAttribute -export const findByTitle: FindByBoundAttribute -export const findAllByTitle: FindAllByBoundAttribute -export const getByDisplayValue: GetByBoundAttribute -export const getAllByDisplayValue: AllByBoundAttribute -export const queryByDisplayValue: QueryByBoundAttribute -export const queryAllByDisplayValue: AllByBoundAttribute -export const findByDisplayValue: FindByBoundAttribute -export const findAllByDisplayValue: FindAllByBoundAttribute -export const getByRole: GetByBoundAttribute -export const getAllByRole: AllByBoundAttribute -export const queryByRole: QueryByBoundAttribute -export const queryAllByRole: AllByBoundAttribute -export const findByRole: FindByBoundAttribute -export const findAllByRole: FindAllByBoundAttribute -export const getByTestId: GetByBoundAttribute -export const getAllByTestId: AllByBoundAttribute -export const queryByTestId: QueryByBoundAttribute -export const queryAllByTestId: AllByBoundAttribute -export const findByTestId: FindByBoundAttribute -export const findAllByTestId: FindAllByBoundAttribute diff --git a/typings/query-helpers.d.ts b/typings/query-helpers.d.ts deleted file mode 100644 index 032b8059..00000000 --- a/typings/query-helpers.d.ts +++ /dev/null @@ -1,62 +0,0 @@ -import {Matcher, MatcherOptions} from './matches' - -export interface SelectorMatcherOptions extends MatcherOptions { - selector?: string -} - -export type QueryByAttribute = ( - attribute: string, - container: HTMLElement, - id: Matcher, - options?: MatcherOptions, -) => HTMLElement | null - -export type AllByAttribute = ( - attribute: string, - container: HTMLElement, - id: Matcher, - options?: MatcherOptions, -) => HTMLElement[] - -export const queryByAttribute: QueryByAttribute -export const queryAllByAttribute: AllByAttribute -export const logDOM: (htmlElement: HTMLElement) => void -export const getElementError: (message: string, container: HTMLElement) => Error - -/** - * query methods have a common call signature. Only the return type differs. - */ -type QueryMethod = ( - container: HTMLElement, - ...args: Arguments -) => Return -export type QueryBy = QueryMethod< - Arguments, - HTMLElement | null -> -export type GetAllBy = QueryMethod< - Arguments, - HTMLElement[] -> -export type FindAllBy = QueryMethod< - Arguments, - Promise -> -export type GetBy = QueryMethod -export type FindBy = QueryMethod< - Arguments, - Promise -> - -export type BuiltQueryMethods = [ - QueryBy, - GetAllBy, - GetBy, - FindAllBy, - FindBy, -] -export const buildQueries: ( - queryByAll: GetAllBy, - getMultipleError: (container: HTMLElement, ...args: Arguments) => string, - getMissingError: (container: HTMLElement, ...args: Arguments) => string, -) => BuiltQueryMethods diff --git a/typings/role-helpers.d.ts b/typings/role-helpers.d.ts deleted file mode 100644 index 6083f9c6..00000000 --- a/typings/role-helpers.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -export function logRoles(container: HTMLElement): string -export function getRoles( - container: HTMLElement, -): {[index: string]: HTMLElement[]} diff --git a/typings/tsconfig.json b/typings/tsconfig.json deleted file mode 100644 index 81e4f72b..00000000 --- a/typings/tsconfig.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "compilerOptions": { - "module": "commonjs", - "lib": ["es6", "dom"], - "noImplicitAny": true, - "noImplicitThis": true, - "strictFunctionTypes": true, - "strictNullChecks": true, - "noEmit": true, - - "baseUrl": ".", - "paths": {"dom-testing-library": ["."]} - } -} diff --git a/typings/tslint.json b/typings/tslint.json deleted file mode 100644 index 286a004f..00000000 --- a/typings/tslint.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "extends": "dtslint/dtslint.json", - "rules": { - "semicolon": [true, "never"], - "whitespace": [false] - } -} diff --git a/typings/wait-for-dom-change.d.ts b/typings/wait-for-dom-change.d.ts deleted file mode 100644 index 849cb69e..00000000 --- a/typings/wait-for-dom-change.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -export function waitForDomChange(options?: { - container?: HTMLElement - timeout?: number - mutationObserverOptions?: MutationObserverInit -}): Promise diff --git a/typings/wait-for-element-to-be-removed.d.ts b/typings/wait-for-element-to-be-removed.d.ts deleted file mode 100644 index 7a353286..00000000 --- a/typings/wait-for-element-to-be-removed.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -export function waitForElementToBeRemoved( - callback: () => T, - options?: { - container?: HTMLElement - timeout?: number - mutationObserverOptions?: MutationObserverInit - }, -): Promise diff --git a/typings/wait-for-element.d.ts b/typings/wait-for-element.d.ts deleted file mode 100644 index fa9f5100..00000000 --- a/typings/wait-for-element.d.ts +++ /dev/null @@ -1,10 +0,0 @@ -export interface WaitForElementOptions { - container?: HTMLElement - timeout?: number - mutationObserverOptions?: MutationObserverInit -} - -export function waitForElement( - callback: () => T, - options?: WaitForElementOptions, -): Promise diff --git a/typings/wait.d.ts b/typings/wait.d.ts deleted file mode 100644 index cb102637..00000000 --- a/typings/wait.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -export function wait( - callback?: () => void, - options?: { - timeout?: number - interval?: number - }, -): Promise