Skip to content

Commit

Permalink
Migrate type tests to Vitest (#367)
Browse files Browse the repository at this point in the history
  • Loading branch information
aryaemami59 authored Jul 12, 2024
1 parent c403cf7 commit bf04cf7
Show file tree
Hide file tree
Showing 18 changed files with 1,070 additions and 490 deletions.
65 changes: 56 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
name: CI

on:
push:
branches: [master]
pull_request:
branches: [master]
on: [push, pull_request, workflow_dispatch]

jobs:
build:
Expand Down Expand Up @@ -37,9 +33,6 @@ jobs:
- name: Run linter
run: yarn lint

- name: Run tests
run: yarn test

- name: Pack
run: yarn pack

Expand All @@ -48,6 +41,46 @@ jobs:
name: package
path: ./package.tgz

test-dist:
name: Test against dist
needs: [build]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node: ['20.x']
steps:
- name: Checkout repo
uses: actions/checkout@v4

- name: Use node ${{ matrix.node }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
cache: 'yarn'

- name: Install deps
run: yarn install

- name: Download build artifact
uses: actions/download-artifact@v4
with:
name: package
path: .

- run: ls -lah

- name: Install build artifact
run: yarn add ./package.tgz

- name: Erase path aliases
run: sed -i -e /@remap-prod-remove-line/d ./tsconfig.base.json

- name: Run tests, against dist
env:
TEST_DIST: true
run: yarn test

test-types:
name: Test Types with TypeScript ${{ matrix.ts }}
needs: [build]
Expand All @@ -69,16 +102,30 @@ jobs:
node-version: ${{ matrix.node }}
cache: 'yarn'

- name: Download build artifact
uses: actions/download-artifact@v4
with:
name: package
path: .

- name: Install deps
run: yarn install

- name: Install TypeScript ${{ matrix.ts }}
run: yarn add typescript@${{ matrix.ts }}

- name: Install build artifact
run: yarn add ./package.tgz

- name: Erase path aliases
run: sed -i -e /@remap-prod-remove-line/d ./tsconfig.base.json

- name: Test types
env:
TEST_DIST: true
run: |
yarn tsc --version
yarn test:typescript
yarn type-tests
test-published-artifact:
name: Test Published Artifact ${{ matrix.example }}
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ dist
es
builds/


typesversions
.cache
.yarnrc
Expand All @@ -18,3 +17,7 @@ typesversions
!.yarn/versions
.pnp.*
*.tgz

tsconfig.vitest-temp.json

.vscode
14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,18 @@
"format": "prettier --write \"{src,test,typescript_test}/**/*.{js,ts}\"",
"format:check": "prettier --check \"{src,test,typescript_test}/**/*.{js,ts}\"",
"lint": "eslint \"{src,test,typescript_test}/**/*.{js,ts}\"",
"test": "vitest run",
"test:cov": "vitest run --coverage",
"test:typescript": "tsc --noEmit -p typescript_test/tsconfig.json",
"build": "tsup",
"test": "vitest --run --typecheck",
"test:watch": "vitest --watch",
"test:cov": "vitest --run --coverage",
"type-tests": "tsc --noEmit -p tsconfig.test.json",
"build": "yarn clean && tsup",
"prepack": "yarn build"
},
"peerDependencies": {
"redux": "^5.0.0"
},
"devDependencies": {
"@types/node": "^20.11.20",
"@typescript-eslint/eslint-plugin": "^5.1.0",
"@typescript-eslint/parser": "^5.1.0",
"cross-env": "^7.0.3",
Expand All @@ -56,8 +58,8 @@
"redux": "^5",
"rimraf": "^3.0.2",
"tsup": "7.0.0",
"typescript": "^5.4.2",
"vitest": "^0.32.0"
"typescript": "^5.4.5",
"vitest": "^1.6.0"
},
"packageManager": "[email protected]"
}
6 changes: 3 additions & 3 deletions scripts/writeGitVersion.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from 'path'
import fs from 'fs'
import fs from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'

const __filename = fileURLToPath(import.meta.url)
Expand All @@ -8,7 +8,7 @@ const __dirname = path.dirname(__filename)
const gitRev = process.argv[2]

const packagePath = path.join(__dirname, '../package.json')
const pkg = JSON.parse(fs.readFileSync(packagePath))
const pkg = JSON.parse(fs.readFileSync(packagePath, 'utf8'))

pkg.version = `${pkg.version}-${gitRev}`
fs.writeFileSync(packagePath, JSON.stringify(pkg, null, 2))
3 changes: 1 addition & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import type { Action, AnyAction } from 'redux'

import type { ThunkMiddleware } from './types'

export type {
ThunkAction,
ThunkDispatch,
ThunkActionDispatch,
ThunkDispatch,
ThunkMiddleware
} from './types'

Expand Down
File renamed without changes.
9 changes: 0 additions & 9 deletions test/tsconfig.json

This file was deleted.

29 changes: 29 additions & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"declaration": true,
"downlevelIteration": false,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"importHelpers": true,
"isolatedModules": true,
"jsx": "react",
"lib": ["DOM", "ESNext"],
"module": "ESnext",
"moduleResolution": "Node",
"noErrorTruncation": true,
"noFallthroughCasesInSwitch": true,
"noUnusedLocals": false,
"noUnusedParameters": false,
"paths": {
"@internal/*": ["./src/*"],
"redux-thunk": ["./src/index.ts"] // @remap-prod-remove-line
},
"resolveJsonModule": true,
"skipLibCheck": true,
"strict": true,
"target": "ESnext",
"types": ["vitest/globals", "vitest/importMeta"]
},
"exclude": ["dist"]
}
10 changes: 10 additions & 0 deletions tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
// For building the library.
"extends": "./tsconfig.base.json",
"compilerOptions": {
"emitDeclarationOnly": true,
"outDir": "dist",
"rootDir": "./src"
},
"include": ["src"]
}
27 changes: 7 additions & 20 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,12 @@
{
// For general development and intellisense.
// Scans the entire source code against the current TS version
// we are using during development.
"extends": "./tsconfig.test.json",
"compilerOptions": {
"strict": true,
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "Node",
"esModuleInterop": true,
"skipLibCheck": true,
"allowJs": true,
"jsx": "react",
"declaration": true,
"emitDeclarationOnly": true,
"forceConsistentCasingInFileNames": true,
"experimentalDecorators": true,
"rootDirs": ["./src", "./test"],
"types": ["vitest/globals"],
"baseUrl": ".",
"paths": {
"redux-thunk": ["src/index.ts"], // @remap-prod-remove-line
"@internal/*": ["src/*"]
}
"checkJs": true,
"rootDir": "."
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist"]
"include": ["."]
}
10 changes: 10 additions & 0 deletions tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
// For runtime and type tests during CI.
"extends": "./tsconfig.base.json",
"compilerOptions": {
"noEmit": true,
"jsx": "react-jsx",
"noImplicitReturns": false
},
"include": ["typescript_test"]
}
1 change: 1 addition & 0 deletions tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default defineConfig(options => {
entry: {
'redux-thunk': 'src/index.ts'
},
tsconfig: 'tsconfig.build.json',
...options
}

Expand Down
Loading

0 comments on commit bf04cf7

Please sign in to comment.