Skip to content

Commit

Permalink
test: add type test
Browse files Browse the repository at this point in the history
  • Loading branch information
uetchy committed Aug 5, 2020
1 parent 0f36e3c commit 215748a
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 8 deletions.
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"Daniel Perez Alvarez <[email protected]>",
"TANIGUCHI Masaya <[email protected]>"
],
"dependencies": {},
"devDependencies": {
"dtslint": "^3.6.12",
"lerna": "^3.0.0",
Expand All @@ -39,8 +38,12 @@
"format": "remark . -qfo && prettier . --write && xo --fix",
"test-api": "tape \"packages/*/test.js\" \"packages/*/test/**/*.js\"",
"test-coverage": "nyc --reporter lcov tape \"packages/*/test.js\" \"packages/*/test/**/*.js\"",
"test-types": "dtslint packages/rehype-katex/types && dtslint packages/rehype-mathjax && dtslint packages/remark-html-katex/types && dtslint packages/remark-math/types",
"test": "run-s format test-types test-coverage"
"test:types": "run-p test:types:rehype-katex test:types:rehype-mathjax test:types:remark-html-katex test:types:remark-math",
"test:types:rehype-katex": "dtslint packages/rehype-katex/types",
"test:types:rehype-mathjax": "dtslint packages/rehype-mathjax",
"test:types:remark-html-katex": "dtslint packages/remark-html-katex/types",
"test:types:remark-math": "dtslint packages/remark-math/types",
"test": "run-s format test:types test-coverage"
},
"nyc": {
"check-coverage": true,
Expand Down
9 changes: 9 additions & 0 deletions packages/rehype-katex/types/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import unified from 'unified'
import katex from 'rehype-katex'

// $ExpectType Processor<Settings>
unified().use(katex)
// $ExpectType Processor<Settings>
unified().use(katex, {output: 'html'})
// $ExpectError
unified().use(katex, {invalidProp: true})
4 changes: 3 additions & 1 deletion packages/rehype-katex/types/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
"compilerOptions": {
"lib": ["es2015", "dom"],
"strict": true,
"baseUrl": "."
"baseUrl": ".",
"paths": { "rehype-katex": ["."] },
"esModuleInterop": true
}
}
2 changes: 1 addition & 1 deletion packages/rehype-mathjax/chtml.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ interface MathJaxCHtmlOptions {
adaptiveCSS?: boolean
}

declare const renderCHtml: Plugin<[MathJaxCHtmlOptions?]>
declare const renderCHtml: Plugin<[MathJaxCHtmlOptions]>

export = renderCHtml
1 change: 1 addition & 0 deletions packages/rehype-mathjax/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Minimum TypeScript Version: 3.2
import {Plugin} from 'unified'

// Should be ported back to MathJax repo
Expand Down
38 changes: 38 additions & 0 deletions packages/rehype-mathjax/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import unified from 'unified'
import mathjax from 'rehype-mathjax'
import chtml from 'rehype-mathjax/chtml'
import browser from 'rehype-mathjax/browser'

// $ExpectType Processor<Settings>
unified().use(mathjax)
// $ExpectType Processor<Settings>
unified().use(mathjax, {minScale: 3})
// $ExpectError
unified().use(mathjax, {invalidProp: true})

// $ExpectType Processor<Settings>
unified().use(chtml, {fontURL: 'url'})
// $ExpectError
unified().use(chtml)
// $ExpectError
unified().use(chtml, {})
// $ExpectError
unified().use(chtml, {adaptiveCSS: true})
// $ExpectError
unified().use(chtml, {fontURL: 'url', invalidProp: true})

// $ExpectType Processor<Settings>
unified().use(browser)
// $ExpectType Processor<Settings>
unified().use(browser, {displayMath: ['$$', '$$']})
// $ExpectType Processor<Settings>
unified().use(browser, {
displayMath: [
['$$', '$$'],
['((', '))']
]
})
// $ExpectError
unified().use(browser, {displayMath: ['$$']})
// $ExpectError
unified().use(browser, {invalidProp: true})
8 changes: 7 additions & 1 deletion packages/rehype-mathjax/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
"compilerOptions": {
"lib": ["es2015", "dom"],
"strict": true,
"baseUrl": "."
"baseUrl": ".",
"paths": {
"rehype-mathjax": ["."],
"rehype-mathjax/chtml": ["./chtml"],
"rehype-mathjax/browser": ["./browser"]
},
"esModuleInterop": true
}
}
11 changes: 11 additions & 0 deletions packages/remark-html-katex/types/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import unified from 'unified'
import html from 'remark-html-katex'

// $ExpectType Processor<Settings>
unified().use(html)
// $ExpectType Processor<Settings>
unified().use(html, {output: 'mathml'})
// $ExpectError
unified().use(html, {output: true})
// $ExpectError
unified().use(html, {invalidProp: true})
4 changes: 3 additions & 1 deletion packages/remark-html-katex/types/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
"compilerOptions": {
"lib": ["es2015", "dom"],
"strict": true,
"baseUrl": "."
"baseUrl": ".",
"paths": {"remark-html-katex": ["."]},
"esModuleInterop": true
}
}
11 changes: 11 additions & 0 deletions packages/remark-math/types/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import unified from 'unified'
import math from 'remark-math'

// $ExpectType Processor<Settings>
unified().use(math)
// $ExpectType Processor<Settings>
unified().use(math, {inlineMathDouble: true})
// $ExpectError
unified().use(math, {inlineMathDouble: 3})
// $ExpectError
unified().use(math, {invalidProp: true})
4 changes: 3 additions & 1 deletion packages/remark-math/types/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
"compilerOptions": {
"lib": ["es2015", "dom"],
"strict": true,
"baseUrl": "."
"baseUrl": ".",
"paths": {"remark-math": ["."]},
"esModuleInterop": true
}
}

0 comments on commit 215748a

Please sign in to comment.