Skip to content

Commit

Permalink
feat: add tests for type definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
thabarbados committed Mar 15, 2022
1 parent dfcb0a4 commit 39c52e8
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .clean-publish
@@ -1,4 +1,5 @@
{
"withoutPublish": true,
"tempDir": "package"
"tempDir": "package",
"fields": ["tsd"],
}
22 changes: 22 additions & 0 deletions .github/workflows/checks.yml
Expand Up @@ -26,3 +26,25 @@ jobs:
uses: andresz1/size-limit-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
typings:
runs-on: ubuntu-latest
name: typings
steps:
- name: Checkout the repository
uses: actions/checkout@v2
- name: Install pnpm
uses: pnpm/action-setup@v2.0.1
with:
version: 6
- name: Install Node.js
uses: actions/setup-node@v2
with:
node-version: 16
cache: 'pnpm'
- name: Install dependencies
run: pnpm install
- name: Prebuild
run: pnpm build
- name: Check typings
if: success()
run: pnpm test:typings
7 changes: 6 additions & 1 deletion package.json
Expand Up @@ -38,7 +38,7 @@
],
"sideEffects": false,
"main": "./src/index.ts",
"typings": "./dist/index.d.ts",
"types": "./dist/index.d.ts",
"publishConfig": {
"main": "./dist/index.cjs",
"module": "./dist/index.js",
Expand All @@ -52,6 +52,7 @@
"unit": "jest -c jest.config.json",
"test": "pnpm lint && pnpm unit",
"test:size": "size-limit",
"test:typings": "tsd",
"lint": "eslint 'src/**/*.ts'",
"format": "prettier --write src test",
"release": "standard-version",
Expand Down Expand Up @@ -109,10 +110,14 @@
"simple-git-hooks": "^2.7.0",
"size-limit": "^7.0.8",
"standard-version": "^9.3.2",
"tsd": "^0.19.1",
"typescript": "^4.6.2",
"vite": "^2.8.6",
"vue": "^3.2.31",
"vue-loader": "^17.0.0",
"vuepress": "^0.14.4"
},
"tsd": {
"directory": "./test"
}
}
88 changes: 88 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 55 additions & 0 deletions test/ChartsTypes.test-d.ts
@@ -0,0 +1,55 @@
import { h } from 'vue'
import { expectError } from 'tsd'
import { PluginOptionsByType } from 'chart.js'

import { Bar, Radar, Scatter, Doughnut } from '../src'

const chartData = {
datasets: []
}

/**
* Should check type-specific props
*/

h(Radar, {
chartData,
plugins: {} as PluginOptionsByType<'radar'>
})

h(Scatter, {
chartData,
plugins: {} as PluginOptionsByType<'scatter'>
})

h(Bar, {
chartData,
chartOptions: {}
})

expectError(
h(Scatter, {
chartData,
plugins: {} as PluginOptionsByType<'bubble'>
})
)

/**
* Should check type-specific options
*/

h(Doughnut, {
chartData,
chartOptions: {
cutout: '75%'
}
})

expectError(
h(Scatter, {
chartData,
chartOptions: {
cutout: '75%'
}
})
)

0 comments on commit 39c52e8

Please sign in to comment.