Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:

# Read existing version, reuse that, add a Git short hash
- name: Set build version to Git commit
run: node scripts/writeGitVersion.js $(git rev-parse --short HEAD)
run: node scripts/writeGitVersion.mjs $(git rev-parse --short HEAD)

- name: Check updated version
run: jq .version package.json
Expand Down Expand Up @@ -143,3 +143,10 @@ jobs:
- name: Run test step
working-directory: ./redux-toolkit/examples/publish-ci/${{ matrix.example }}
run: yarn test
if: matrix.example != 'are-the-types-wrong'

- name: Run test step
working-directory: ./redux-toolkit/examples/publish-ci/${{ matrix.example }}
# Ignore "FalseCJS" errors in the `attw` job
run: yarn test -n FalseCJS
if: matrix.example == 'are-the-types-wrong'
14 changes: 0 additions & 14 deletions jest.config.js

This file was deleted.

51 changes: 16 additions & 35 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@
"flux"
],
"author": "Dan Abramov <dan.abramov@me.com>",
"type": "module",
"main": "lib/index.js",
"module": "es/index.js",
"types": "es/index.d.ts",
"main": "dist/cjs/index.cjs",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"exports": {
"./package.json": "./package.json",
".": {
"types": "./es/index.d.ts",
"import": "./es/index.js",
"default": "./lib/index.js"
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"default": "./dist/cjs/index.cjs"
},
"./extend-redux": {
"types": "./extend-redux.d.ts"
}
},
"sideEffects": false,
"files": [
"lib",
"es",
"src",
"dist",
"src",
"extend-redux.d.ts"
],
"scripts": {
Expand All @@ -40,47 +40,28 @@
"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": "jest",
"test:cov": "jest --coverage",
"test": "vitest run",
"test:cov": "vitest run --coverage",
"test:typescript": "yarn test:typescript:main && yarn test:typescript:extended",
"test:typescript:main": "tsc --noEmit -p typescript_test/tsconfig.json",
"test:typescript:extended": "tsc --noEmit -p typescript_test/typescript_extended/tsconfig.json",
"build:commonjs": "cross-env BABEL_ENV=commonjs babel src/*.ts --ignore src/types.ts --extensions .ts --out-dir lib ",
"build:es": "babel src/*.ts --ignore src/types.ts --extensions .ts --out-dir es",
"build:umd": "cross-env NODE_ENV=development rollup -c -o dist/redux-thunk.js",
"build:umd:min": "cross-env NODE_ENV=production rollup -c -o dist/redux-thunk.min.js",
"build:types": "tsc",
"build": "rimraf dist lib es && yarn build:types && yarn build:commonjs && yarn build:es && yarn build:umd && yarn build:umd:min",
"api-types": "api-extractor run --local",
"build": "tsup",
"prepack": "yarn build"
},
"peerDependencies": {
"redux": "^4"
},
"devDependencies": {
"@babel/cli": "^7.15.7",
"@babel/core": "^7.15.8",
"@babel/preset-env": "^7.15.8",
"@babel/preset-typescript": "^7.15.0",
"@babel/register": "^7.15.3",
"@microsoft/api-extractor": "^7.18.16",
"@rollup/plugin-babel": "^5.3.0",
"@rollup/plugin-commonjs": "^21.0.1",
"@rollup/plugin-node-resolve": "^13.0.6",
"@rollup/plugin-replace": "^3.0.0",
"@types/jest": "^27.0.2",
"@typescript-eslint/eslint-plugin": "^5.1.0",
"@typescript-eslint/parser": "^5.1.0",
"cross-env": "^7.0.3",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"jest": "^27.3.1",
"prettier": "^2.4.1",
"redux": "^4",
"rimraf": "^3.0.2",
"rollup": "^2.58.1",
"rollup-plugin-terser": "^7.0.2",
"ts-jest": "27.0.7",
"typescript": "^4.4"
"tsup": "^6.7.0",
"typescript": "^4.4",
"vitest": "^0.29.8"
}
}
48 changes: 0 additions & 48 deletions rollup.config.js

This file was deleted.

File renamed without changes.
17 changes: 6 additions & 11 deletions test/test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { thunk as thunkMiddleware, withExtraArgument } from '../src/index'
import { thunk as thunkMiddleware, withExtraArgument } from 'redux-thunk'

describe('thunk middleware', () => {
const doDispatch = () => {}
Expand All @@ -23,24 +23,22 @@ describe('thunk middleware', () => {
})

describe('handle action', () => {
it('must run the given action function with dispatch and getState', done => {
it('must run the given action function with dispatch and getState', () => {
// @ts-ignore
const actionHandler = nextHandler()

actionHandler((dispatch: any, getState: any) => {
expect(dispatch).toBe(doDispatch)
expect(getState).toBe(doGetState)
done()
})
})

it('must pass action to next if not a function', done => {
it('must pass action to next if not a function', () => {
const actionObj = {}

// @ts-ignore
const actionHandler = nextHandler(action => {
expect(action).toBe(actionObj)
done()
})

actionHandler(actionObj)
Expand Down Expand Up @@ -78,18 +76,16 @@ describe('thunk middleware', () => {
})

describe('handle errors', () => {
it('must throw if argument is non-object', done => {
it('must throw if argument is non-object', () => {
try {
// @ts-expect-error
thunkMiddleware()
} catch (err) {
done()
}
} catch (err) {}
})
})

describe('withExtraArgument', () => {
it('must pass the third argument', done => {
it('must pass the third argument', () => {
const extraArg = { lol: true }
// @ts-ignore
withExtraArgument(extraArg)({
Expand All @@ -99,7 +95,6 @@ describe('thunk middleware', () => {
expect(dispatch).toBe(doDispatch)
expect(getState).toBe(doGetState)
expect(arg).toBe(extraArg)
done()
})
})
})
Expand Down
9 changes: 7 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@
"jsx": "react",
"declaration": true,
"emitDeclarationOnly": true,
"outDir": "./es",
"forceConsistentCasingInFileNames": true,
"experimentalDecorators": true,
"rootDirs": ["./src", "./test"]
"rootDirs": ["./src", "./test"],
"types": ["vitest/globals"],
"baseUrl": ".",
"paths": {
"redux-thunk": ["src/index.ts"], // @remap-prod-remove-line
"@internal/*": ["src/*"]
}
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist"]
Expand Down
24 changes: 24 additions & 0 deletions tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { defineConfig, Options } from 'tsup'

export default defineConfig(options => {
const commonOptions: Partial<Options> = {
entry: ['src/index.ts'],
...options
}

return [
{
...commonOptions,
format: ['esm'],
outExtension: () => ({ js: '.mjs' }),
dts: true,
clean: true
},
{
...commonOptions,
format: 'cjs',
outDir: './dist/cjs/',
outExtension: () => ({ js: '.cjs' })
}
]
})
17 changes: 17 additions & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { defineConfig } from 'vitest/config'

export default defineConfig({
test: {
globals: true,
include: ['./test/test.ts'],
alias: {
'redux-thunk': './src/index.ts', // @remap-prod-remove-line

// this mapping is disabled as we want `dist` imports in the tests only to be used for "type-only" imports which don't play a role for jest
'@internal/': './src/'
},
deps: {
interopDefault: true
}
}
})
Loading