From 2f160e45ccb527622c4b05a457ba96e070efdcb9 Mon Sep 17 00:00:00 2001 From: James Amner Date: Fri, 24 May 2024 11:35:09 +0100 Subject: [PATCH] Add Type Coverage Checker --- .github/workflows/tests-js.yml | 2 ++ package-lock.json | 32 ++++++++++++++++++- package.json | 3 +- packages/iconography/package.json | 6 ++-- .../iconography/src/IconToolbarButton.tsx | 2 +- packages/iconography/src/tests/utils.test.ts | 4 +-- packages/iconography/src/utils.ts | 4 +-- turbo.json | 3 +- 8 files changed, 46 insertions(+), 10 deletions(-) diff --git a/.github/workflows/tests-js.yml b/.github/workflows/tests-js.yml index b6efa64..abf0a73 100644 --- a/.github/workflows/tests-js.yml +++ b/.github/workflows/tests-js.yml @@ -30,5 +30,7 @@ jobs: run: npm run lint - name: Unit Test run: npm run test + - name: Type Coverage + run: npm run type-coverage - name: Build run: npm run build diff --git a/package-lock.json b/package-lock.json index 97e523d..afd9b91 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19943,6 +19943,35 @@ "node": ">= 0.8.0" } }, + "node_modules/type-coverage": { + "version": "2.28.2", + "resolved": "https://registry.npmjs.org/type-coverage/-/type-coverage-2.28.2.tgz", + "integrity": "sha512-mTANnzAeuH7ldrg0fzPnhh+aCCSVAO7V7hlBoVg4XxuUtQyD3ogir/R7Z6Q7W0H1JREtDIY4I91SGHAgEPi6Bw==", + "dev": true, + "dependencies": { + "minimist": "1", + "type-coverage-core": "^2.28.1" + }, + "bin": { + "type-coverage": "bin/type-coverage" + } + }, + "node_modules/type-coverage-core": { + "version": "2.28.1", + "resolved": "https://registry.npmjs.org/type-coverage-core/-/type-coverage-core-2.28.1.tgz", + "integrity": "sha512-NniLJtLiDg0+dhrf/9ACGwi3OAhIfvd20f1CB0yxIUBMECwmJp7e7me3lM8djkrDBJtqSY+uXA6PRs+yv3HTnA==", + "dev": true, + "dependencies": { + "fast-glob": "3", + "minimatch": "6 || 7 || 8 || 9", + "normalize-path": "3", + "tslib": "1 || 2", + "tsutils": "3" + }, + "peerDependencies": { + "typescript": "2 || 3 || 4 || 5" + } + }, "node_modules/type-detect": { "version": "4.0.8", "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz", @@ -21439,7 +21468,8 @@ "@wordpress/icons": "^9.44.0", "@wordpress/interface": "^5.30.0", "@wordpress/scripts": "^27.4.0", - "react": "^18.2.0" + "react": "^18.2.0", + "type-coverage": "^2.28.2" } } } diff --git a/package.json b/package.json index e9bf0cd..a2b0398 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,8 @@ "lint:js:fix": "turbo run lint:js:fix", "test": "turbo run test", "test:unit": "turbo run test:unit", - "test:snapshots": "turbo run test:snapshots" + "test:snapshots": "turbo run test:snapshots", + "type-coverage": "turbo run type-coverage" }, "devDependencies": { "turbo": "^1.13.3" diff --git a/packages/iconography/package.json b/packages/iconography/package.json index 56002c5..d3eb8de 100644 --- a/packages/iconography/package.json +++ b/packages/iconography/package.json @@ -14,7 +14,8 @@ "test": "wp-scripts test-unit-js", "test:snapshots": "wp-scripts test-unit-js --updateSnapshot", "packages-update": "wp-scripts packages-update", - "start": "wp-scripts start" + "start": "wp-scripts start", + "type-coverage": "type-coverage --strict --at-least 99.83" }, "author": "", "license": "ISC", @@ -26,6 +27,7 @@ "@wordpress/icons": "^9.44.0", "@wordpress/interface": "^5.30.0", "@wordpress/scripts": "^27.4.0", - "react": "^18.2.0" + "react": "^18.2.0", + "type-coverage": "^2.28.2" } } diff --git a/packages/iconography/src/IconToolbarButton.tsx b/packages/iconography/src/IconToolbarButton.tsx index bdb729a..eb30722 100644 --- a/packages/iconography/src/IconToolbarButton.tsx +++ b/packages/iconography/src/IconToolbarButton.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { ComponentProps } from 'react'; /* WordPress Dependencies */ import { __ } from '@wordpress/i18n'; diff --git a/packages/iconography/src/tests/utils.test.ts b/packages/iconography/src/tests/utils.test.ts index 59317cb..4f1d2f0 100644 --- a/packages/iconography/src/tests/utils.test.ts +++ b/packages/iconography/src/tests/utils.test.ts @@ -25,7 +25,7 @@ describe( 'Should generate a rich-text format from icon', () => { text: 'zoom_out', formats: new Array( 8 ).fill( [ { type: 'content-only/ms-outlined' }, - ] ), + ] ) as { type: 'content-only/ms-outlined' }[], start: 0, end: 8, replacements: [], @@ -43,7 +43,7 @@ describe( 'Should generate a rich-text format from icon', () => { text: 'something_else', formats: new Array( 14 ).fill( [ { type: 'content-only/ms-outlined' }, - ] ), + ] ) as { type: 'content-only/ms-outlined' }[], start: 0, end: 14, replacements: [], diff --git a/packages/iconography/src/utils.ts b/packages/iconography/src/utils.ts index cedfe1d..cadaf1f 100644 --- a/packages/iconography/src/utils.ts +++ b/packages/iconography/src/utils.ts @@ -37,11 +37,11 @@ export function generateRichTextFormat( * @return {IconGroupIcon[]} Array of { name, value } objects. */ export const getIconOptions = ( suffix: string ): IconGroupIcon[] => { - const iconNames = IconData.filter( ( iconName ) => + const iconNames = IconData.filter( ( iconName: string ) => iconName.endsWith( suffix ) ); - return iconNames.map( ( name ) => { + return iconNames.map( ( name: string ) => { const value = snakeCase( name.replace( suffix, '' ) ); return { name, value }; } ); diff --git a/turbo.json b/turbo.json index 09aef84..90d7e0c 100644 --- a/turbo.json +++ b/turbo.json @@ -23,6 +23,7 @@ }, "test": {}, "test:unit": {}, - "test:snapshots": {} + "test:snapshots": {}, + "type-coverage": {} } } \ No newline at end of file