Skip to content

Commit 49e56b3

Browse files
authored
feat: native typescript support (#246)
1 parent 17787f3 commit 49e56b3

Some content is hidden

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

62 files changed

+677
-338
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ dist
77
# when working with contributors
88
package-lock.json
99
yarn.lock
10+
yarn-error.log

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ cache: npm
55
notifications:
66
email: false
77
node_js:
8-
- 10.14
8+
- 10.18
99
- 12
1010
- node
1111
install: npm install

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"typescript.tsdk": "node_modules/typescript/lib"
3+
}

extend-expect.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import './dist/typings'

matchers.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './dist/typings/matchers'

package.json

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
"version": "0.0.0-semantically-released",
44
"description": "Custom jest matchers to test the state of the DOM",
55
"main": "dist/index.js",
6+
"types": "dist/index.d.ts",
67
"engines": {
78
"node": ">=8",
89
"npm": ">=6",
910
"yarn": ">=1"
1011
},
1112
"scripts": {
12-
"build": "kcd-scripts build",
13+
"build": "npm run build:source && npm run build:types",
14+
"build:source": "kcd-scripts build",
15+
"build:types": "tsc -p tsconfig.build.json --emitDeclarationOnly",
1316
"format": "kcd-scripts format",
1417
"lint": "kcd-scripts lint",
1518
"setup": "npm install && npm run validate -s",
@@ -20,7 +23,9 @@
2023
"files": [
2124
"dist",
2225
"extend-expect.js",
23-
"matchers.js"
26+
"extend-expect.d.ts",
27+
"matchers.js",
28+
"matchers.d.ts"
2429
],
2530
"keywords": [
2631
"testing",
@@ -32,7 +37,6 @@
3237
"license": "MIT",
3338
"dependencies": {
3439
"@babel/runtime": "^7.9.2",
35-
"@types/testing-library__jest-dom": "^5.0.2",
3640
"chalk": "^3.0.0",
3741
"css": "^2.2.4",
3842
"css.escape": "^1.5.1",
@@ -42,11 +46,16 @@
4246
"redent": "^3.0.0"
4347
},
4448
"devDependencies": {
49+
"@types/css": "^0.0.31",
50+
"@types/jsdom": "^16.2.1",
51+
"@types/lodash": "^4.14.150",
4552
"jest-environment-jsdom-sixteen": "^1.0.3",
4653
"jest-watch-select-projects": "^2.0.0",
4754
"jsdom": "^16.2.1",
4855
"kcd-scripts": "^5.6.0",
49-
"pretty-format": "^25.1.0"
56+
"pretty-format": "^25.1.0",
57+
"ts-jest": "^25.5.0",
58+
"typescript": "^3.8.3"
5059
},
5160
"eslintConfig": {
5261
"extends": "./node_modules/kcd-scripts/eslint.js",

src/__tests__/helpers/document.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/__tests__/helpers/document.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import * as extensions from '../../matchers'
2+
3+
let document: Document
4+
5+
const globalWithDocument = global as {
6+
document?: Document
7+
}
8+
9+
if (globalWithDocument.document) {
10+
document = globalWithDocument.document
11+
} else {
12+
const {JSDOM} = require('jsdom')
13+
const {window} = new JSDOM()
14+
document = window.document
15+
}
16+
17+
export default document
18+
19+
type Extensions = typeof extensions
20+
21+
declare global {
22+
namespace jest {
23+
interface Matchers<R, T> extends Extensions {}
24+
}
25+
}

src/__tests__/helpers/test-utils.js renamed to src/__tests__/helpers/test-utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import document from './document'
22

3-
function render(html) {
3+
function render(html: string) {
44
const container = document.createElement('div')
55
container.innerHTML = html
6-
const queryByTestId = testId =>
6+
const queryByTestId = (testId: string) =>
77
container.querySelector(`[data-testid="${testId}"]`)
88

99
// Some tests need to look up global ids with document.getElementById()
File renamed without changes.

0 commit comments

Comments
 (0)