From 868364287d9414b008e846da7a9bfa1da4645d50 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Tue, 19 Nov 2024 23:48:44 -0600 Subject: [PATCH] Add basic type tests --- .github/workflows/ci.yml | 5 ++++- package.json | 4 +++- tests/types/configs.test-d.cts | 18 ++++++++++++++++++ tests/types/configs.test-d.mts | 15 +++++++++++++++ tsconfig.json | 3 +-- 5 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 tests/types/configs.test-d.cts create mode 100644 tests/types/configs.test-d.mts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 469497a..8befe18 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -112,8 +112,11 @@ jobs: - name: 📥 Install dependencies run: npm install --legacy-peer-deps + - name: ▶️ Run check-exports script + run: npm run check-exports -- --format=table + - name: ▶️ Run test:types script - run: npm run test:types -- --format=table + run: npm run test:types release: name: 🚀 Release diff --git a/package.json b/package.json index 596cfd7..08fa02b 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,7 @@ "cross-spawn": "^7.0.3", "esbuild": "^0.19.3", "eslint": "^8.46.0", + "expect-type": "^1.1.0", "fs-extra": "^10.1.0", "mocha": "^10.4.0", "monaco-editor": "^0.47.0", @@ -68,7 +69,8 @@ "docs:watch": "vitepress dev docs", "lint": "eslint lib scripts tests", "test": "nyc mocha \"tests/lib/**/*.js\" --reporter dot --timeout 8000", - "test:types": "attw --pack", + "test:types": "tsc -p tsconfig.json", + "check-exports": "attw --pack", "coverage": "nyc report --reporter lcov && opener coverage/lcov-report/index.html", "watch": "npm run -s test -- --watch --growl" }, diff --git a/tests/types/configs.test-d.cts b/tests/types/configs.test-d.cts new file mode 100644 index 0000000..540bd48 --- /dev/null +++ b/tests/types/configs.test-d.cts @@ -0,0 +1,18 @@ +import configs = require("@eslint-community/eslint-plugin-eslint-comments/configs") +import expectTypeModule = require("expect-type") + +import type { Linter } from "eslint" + +import expectTypeOf = expectTypeModule.expectTypeOf + +expectTypeOf(configs) + .toHaveProperty("recommended") + .toMatchTypeOf() + +expectTypeOf([configs.recommended]).toMatchTypeOf() + +expectTypeOf(configs.recommended).toMatchTypeOf() + +expectTypeOf(configs) + .toHaveProperty("recommended") + .toMatchTypeOf() diff --git a/tests/types/configs.test-d.mts b/tests/types/configs.test-d.mts new file mode 100644 index 0000000..9e9ff73 --- /dev/null +++ b/tests/types/configs.test-d.mts @@ -0,0 +1,15 @@ +import configs from "@eslint-community/eslint-plugin-eslint-comments/configs" +import type { Linter } from "eslint" +import { expectTypeOf } from "expect-type" + +expectTypeOf(configs) + .toHaveProperty("recommended") + .toMatchTypeOf() + +expectTypeOf([configs.recommended]).toMatchTypeOf() + +expectTypeOf(configs.recommended).toMatchTypeOf() + +expectTypeOf(configs) + .toHaveProperty("recommended") + .toMatchTypeOf() diff --git a/tsconfig.json b/tsconfig.json index fff2a40..99d54ef 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,7 +2,6 @@ "compilerOptions": { "allowSyntheticDefaultImports": false, "esModuleInterop": false, - "exactOptionalPropertyTypes": true, "forceConsistentCasingInFileNames": true, "isolatedModules": true, "lib": ["ESNext"], @@ -10,7 +9,7 @@ "moduleResolution": "NodeNext", "noEmit": true, "resolveJsonModule": true, - "skipLibCheck": false, + "skipLibCheck": true, "strict": true, "target": "ESNext", "useDefineForClassFields": true,