Skip to content

Commit

Permalink
types: add types to test utils (#1083)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianMurphy committed May 21, 2020
1 parent e2eb4ee commit a3d8f08
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 3 deletions.
12 changes: 10 additions & 2 deletions packages/test-util/package.json
Expand Up @@ -11,11 +11,14 @@
},
"author": "John Otander <johnotander@gmail.com> (http://johnotander.com)",
"contributors": [
"JounQin <admin@1stg.me> (https://www.1stg.me)"
"JounQin <admin@1stg.me> (https://www.1stg.me)",
"Christian Murphy <christian.murphy.42@gmail.com>"
],
"license": "MIT",
"types": "types/index.d.ts",
"files": [
"index.js"
"index.js",
"types/index.d.ts"
],
"keywords": [
"mdx",
Expand All @@ -25,12 +28,17 @@
"remark",
"mdxast"
],
"scripts": {
"test-types": "dtslint types"
},
"dependencies": {
"@babel/core": "7.9.6",
"@babel/plugin-proposal-object-rest-spread": "7.9.6",
"@babel/plugin-transform-react-jsx": "7.9.4",
"@mdx-js/mdx": "^2.0.0-next.0",
"@mdx-js/react": "^2.0.0-next.0",
"@types/babel__core": "7.1.7",
"@types/react": "16.9.35",
"babel-plugin-remove-export-keywords": "^2.0.0-next.0",
"react": "16.13.1",
"react-dom": "16.13.1"
Expand Down
13 changes: 13 additions & 0 deletions packages/test-util/types/index.d.ts
@@ -0,0 +1,13 @@
// TypeScript Version: 3.4

import {ParseResult} from '@babel/core'
import {ComponentType} from 'react'

export function parse(code: string): ParseResult
export function tranform(code: string): string
export function renderWithReact(
code: string,
components?: {
[name: string]: ComponentType<any>
}
): Promise<string>
7 changes: 7 additions & 0 deletions packages/test-util/types/mdx-js-test-util-test.tsx
@@ -0,0 +1,7 @@
import * as React from 'react'
import {parse, tranform, renderWithReact} from '@mdx-js/test-util'

parse('') // $ExpectType ParseResult
tranform('') // $ExpectType string
renderWithReact('') // $ExpectType Promise<string>
renderWithReact('', {a: () => <></>}) // $ExpectType Promise<string>
13 changes: 13 additions & 0 deletions packages/test-util/types/tsconfig.json
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": ["dom", "es6"],
"strict": true,
"skipLibCheck": true,
"baseUrl": ".",
"jsx": "react",
"paths": {
"@mdx-js/test-util": ["index.d.ts"]
}
}
}
7 changes: 7 additions & 0 deletions packages/test-util/types/tslint.json
@@ -0,0 +1,7 @@
{
"extends": "dtslint/dtslint.json",
"rules": {
"whitespace": false,
"semicolon": false
}
}
2 changes: 1 addition & 1 deletion yarn.lock
Expand Up @@ -3444,7 +3444,7 @@
resolved "https://registry.yarnpkg.com/@types/babel-types/-/babel-types-7.0.7.tgz#667eb1640e8039436028055737d2b9986ee336e3"
integrity sha512-dBtBbrc+qTHy1WdfHYjBwRln4+LWqASWakLHsWHR2NWHIFkv4W3O070IGoGLEBrJBvct3r0L1BUPuvURi7kYUQ==

"@types/babel__core@^7.1.0", "@types/babel__core@^7.1.7":
"@types/babel__core@7.1.7", "@types/babel__core@^7.1.0", "@types/babel__core@^7.1.7":
version "7.1.7"
resolved "https://registry.yarnpkg.com/@types/babel__core/-/babel__core-7.1.7.tgz#1dacad8840364a57c98d0dd4855c6dd3752c6b89"
integrity sha512-RL62NqSFPCDK2FM1pSDH0scHpJvsXtZNiYlMB73DgPBaG1E38ZYVL+ei5EkWRbr+KC4YNiAUNBnRj+bgwpgjMw==
Expand Down

0 comments on commit a3d8f08

Please sign in to comment.