From 516ae4d3aede71c5a73908d06e2a9c303d3300b2 Mon Sep 17 00:00:00 2001 From: Michael Kreil Date: Thu, 23 Nov 2023 16:56:44 +0100 Subject: [PATCH] test: fix typescript testing --- .github/workflows/ci.yml | 2 +- .github/workflows/release.yml | 3 +++ jest.config.typescript.ts | 14 ++++++++++++++ package.json | 3 ++- 4 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 jest.config.typescript.ts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6a1d0b9..71d722f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -40,7 +40,7 @@ jobs: run: npm audit - name: Run tests - run: npm run test-node + run: npm run test - name: Generate test coverage run: npm run test-coverage diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2432cde..b4f15cd 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -32,6 +32,9 @@ jobs: if: steps.cache-node-modules.outputs.cache-hit != 'true' run: npm ci + - name: Run tests + run: npm run test + - name: Build styles run: npm run build-styles diff --git a/jest.config.typescript.ts b/jest.config.typescript.ts new file mode 100644 index 0000000..35e5601 --- /dev/null +++ b/jest.config.typescript.ts @@ -0,0 +1,14 @@ +import type { Config } from 'jest'; + +const config: Config = { + testEnvironment: 'node', + transform: { + '^.+\\.ts$': ['ts-jest', { tsconfig: 'tsconfig.node.json', useESM: true }] + }, + testRegex: 'src/.*\\.test\\.ts', + extensionsToTreatAsEsm: ['.ts'], + collectCoverage: false, + resolver: 'jest-ts-webcompat-resolver', +} + +export default config; diff --git a/package.json b/package.json index 516533d..cb30c08 100644 --- a/package.json +++ b/package.json @@ -13,10 +13,11 @@ "doc": "vrt ts2md src/index.ts tsconfig.node.json | vrt insertmd README.md '### Node.js API'", "lint": "eslint --color .", "release": "tsx scripts/release.ts", - "test": "npm run test-node && npm run test-coverage && npm run test-browser", + "test": "npm run test-typescript && npm run test-node && npm run test-browser", "test-browser": "npm run build-browser && echo 'add browser test'", "test-coverage": "NODE_OPTIONS=--experimental-vm-modules jest -c=jest.config.coverage.ts", "test-node": "npm run build-node && NODE_OPTIONS=--experimental-vm-modules jest -c=jest.config.node.ts", + "test-typescript": "NODE_OPTIONS=--experimental-vm-modules jest -c=jest.config.typescript.ts", "upgrade": "npm-check-updates -u && rm -f package-lock.json && rm -rf node_modules; npm i" }, "repository": {