From dda6f1acda9db5d54ab2c90f40a64373aba60474 Mon Sep 17 00:00:00 2001 From: Mark Erikson Date: Sat, 11 Feb 2023 13:36:58 -0500 Subject: [PATCH 1/2] Run tests from source instead of building first --- package.json | 3 +-- test/applyMiddleware.spec.ts | 2 +- test/bindActionCreators.spec.ts | 2 +- test/combineReducers.spec.ts | 2 +- test/compose.spec.ts | 2 +- test/createStore.spec.ts | 8 +++++++- test/helpers/actionCreators.ts | 2 +- test/helpers/middleware.ts | 2 +- test/helpers/reducers.ts | 2 +- test/typescript/actionCreators.ts | 2 +- test/typescript/actions.ts | 2 +- test/typescript/compose.ts | 2 +- test/typescript/dispatch.ts | 2 +- test/typescript/enhancers.ts | 2 +- test/typescript/injectedDispatch.ts | 2 +- test/typescript/middleware.ts | 2 +- test/typescript/reducers.ts | 2 +- test/typescript/store.ts | 2 +- 18 files changed, 24 insertions(+), 19 deletions(-) diff --git a/package.json b/package.json index 85273a28b7..a4df23e34b 100644 --- a/package.json +++ b/package.json @@ -48,12 +48,11 @@ "format:check": "prettier --list-different \"{src,test}/**/*.{js,ts}\" \"**/*.md\"", "lint": "eslint --ext js,ts src test", "check-types": "tsc --noEmit", - "test": "jest && tsc -p test/typescript", + "test": "jest", "test:types": "tsc -p test/typescript", "test:watch": "jest --watch", "test:cov": "jest --coverage", "build": "rollup -c", - "pretest": "npm run build", "prepublishOnly": "npm run clean && npm run check-types && npm run format:check && npm run lint && npm test", "examples:lint": "eslint --ext js,ts examples", "examples:test": "cross-env CI=true babel-node examples/testAll.js" diff --git a/test/applyMiddleware.spec.ts b/test/applyMiddleware.spec.ts index 77122800c0..9c5d0068c7 100644 --- a/test/applyMiddleware.spec.ts +++ b/test/applyMiddleware.spec.ts @@ -7,7 +7,7 @@ import { Action, Store, Dispatch -} from '..' +} from '../src' import * as reducers from './helpers/reducers' import { addTodo, addTodoAsync, addTodoIfEmpty } from './helpers/actionCreators' import { thunk } from './helpers/middleware' diff --git a/test/bindActionCreators.spec.ts b/test/bindActionCreators.spec.ts index 03699410fa..870ba0b74d 100644 --- a/test/bindActionCreators.spec.ts +++ b/test/bindActionCreators.spec.ts @@ -1,4 +1,4 @@ -import { bindActionCreators, createStore, ActionCreator, Store } from '..' +import { bindActionCreators, createStore, ActionCreator, Store } from '../src' import { todos } from './helpers/reducers' import * as actionCreators from './helpers/actionCreators' diff --git a/test/combineReducers.spec.ts b/test/combineReducers.spec.ts index 898c3bc215..13b1f47598 100644 --- a/test/combineReducers.spec.ts +++ b/test/combineReducers.spec.ts @@ -5,7 +5,7 @@ import { Reducer, AnyAction, __DO_NOT_USE__ActionTypes as ActionTypes -} from '..' +} from '../src' describe('Utils', () => { describe('combineReducers', () => { diff --git a/test/compose.spec.ts b/test/compose.spec.ts index 6e61fdf75a..f372d0ecf1 100644 --- a/test/compose.spec.ts +++ b/test/compose.spec.ts @@ -1,4 +1,4 @@ -import { compose } from '..' +import { compose } from '../src' describe('Utils', () => { describe('compose', () => { diff --git a/test/createStore.spec.ts b/test/createStore.spec.ts index 3b82f37b2e..793dccdd69 100644 --- a/test/createStore.spec.ts +++ b/test/createStore.spec.ts @@ -1,4 +1,10 @@ -import { createStore, combineReducers, StoreEnhancer, Action, Store } from '..' +import { + createStore, + combineReducers, + StoreEnhancer, + Action, + Store +} from '../src' import { addTodo, dispatchInMiddle, diff --git a/test/helpers/actionCreators.ts b/test/helpers/actionCreators.ts index 46964ea9ce..62dbbd9cc9 100644 --- a/test/helpers/actionCreators.ts +++ b/test/helpers/actionCreators.ts @@ -7,7 +7,7 @@ import { THROW_ERROR, UNKNOWN_ACTION } from './actionTypes' -import { Action, AnyAction, Dispatch } from '../..' +import { Action, AnyAction, Dispatch } from '../../src' export function addTodo(text: string): AnyAction { return { type: ADD_TODO, text } diff --git a/test/helpers/middleware.ts b/test/helpers/middleware.ts index b7fd6857dd..66e01351c6 100644 --- a/test/helpers/middleware.ts +++ b/test/helpers/middleware.ts @@ -1,4 +1,4 @@ -import { MiddlewareAPI, Dispatch, AnyAction } from '../..' +import { MiddlewareAPI, Dispatch, AnyAction } from '../../src' type ThunkAction = T extends AnyAction ? AnyAction diff --git a/test/helpers/reducers.ts b/test/helpers/reducers.ts index cc40b95a3f..7438d6b660 100644 --- a/test/helpers/reducers.ts +++ b/test/helpers/reducers.ts @@ -6,7 +6,7 @@ import { UNSUBSCRIBE_IN_MIDDLE, THROW_ERROR } from './actionTypes' -import { AnyAction } from '../..' +import { AnyAction } from '../../src' function id(state: { id: number }[]) { return ( diff --git a/test/typescript/actionCreators.ts b/test/typescript/actionCreators.ts index 4fe5391fe6..232ec7bcf1 100644 --- a/test/typescript/actionCreators.ts +++ b/test/typescript/actionCreators.ts @@ -4,7 +4,7 @@ import { Dispatch, bindActionCreators, ActionCreatorsMapObject -} from '../..' +} from '../../src' interface AddTodoAction extends Action { text: string diff --git a/test/typescript/actions.ts b/test/typescript/actions.ts index 480a34151b..6b1fe1c9f0 100644 --- a/test/typescript/actions.ts +++ b/test/typescript/actions.ts @@ -1,4 +1,4 @@ -import { Action as ReduxAction } from '../..' +import { Action as ReduxAction } from '../../src' namespace FSA { interface Action

extends ReduxAction { diff --git a/test/typescript/compose.ts b/test/typescript/compose.ts index 454e857e6f..9d62ad9690 100644 --- a/test/typescript/compose.ts +++ b/test/typescript/compose.ts @@ -1,4 +1,4 @@ -import { compose } from '../..' +import { compose } from '../../src' // adapted from DefinitelyTyped/compose-function diff --git a/test/typescript/dispatch.ts b/test/typescript/dispatch.ts index adcd050c9f..b0f04a1c93 100644 --- a/test/typescript/dispatch.ts +++ b/test/typescript/dispatch.ts @@ -1,4 +1,4 @@ -import { Dispatch } from '../..' +import { Dispatch } from '../../src' /** * Default Dispatch type accepts any object with `type` property. diff --git a/test/typescript/enhancers.ts b/test/typescript/enhancers.ts index 16cb9b3f3c..ece858f652 100644 --- a/test/typescript/enhancers.ts +++ b/test/typescript/enhancers.ts @@ -5,7 +5,7 @@ import { Reducer, createStore, Store -} from '../..' +} from '../../src' interface State { someField: 'string' diff --git a/test/typescript/injectedDispatch.ts b/test/typescript/injectedDispatch.ts index 1517bfa43f..b4ff7668f6 100644 --- a/test/typescript/injectedDispatch.ts +++ b/test/typescript/injectedDispatch.ts @@ -1,4 +1,4 @@ -import { Dispatch, Action } from '../..' +import { Dispatch, Action } from '../../src' interface Component

{ props: P diff --git a/test/typescript/middleware.ts b/test/typescript/middleware.ts index 9514050a6c..8a39cd84f1 100644 --- a/test/typescript/middleware.ts +++ b/test/typescript/middleware.ts @@ -7,7 +7,7 @@ import { Reducer, Action, AnyAction -} from '../..' +} from '../../src' /** * Logger middleware doesn't add any extra types to dispatch, just logs actions diff --git a/test/typescript/reducers.ts b/test/typescript/reducers.ts index a482d58a62..6017e0790b 100644 --- a/test/typescript/reducers.ts +++ b/test/typescript/reducers.ts @@ -1,4 +1,4 @@ -import { Reducer, Action, combineReducers, ReducersMapObject } from '../..' +import { Reducer, Action, combineReducers, ReducersMapObject } from '../../src' /** * Simple reducer definition with no action shape checks. diff --git a/test/typescript/store.ts b/test/typescript/store.ts index f3b18fca83..3cdb6b769c 100644 --- a/test/typescript/store.ts +++ b/test/typescript/store.ts @@ -7,7 +7,7 @@ import { Unsubscribe, Observer, ExtendState -} from '../..' +} from '../../src' import 'symbol-observable' type BrandedString = string & { _brand: 'type' } From bad6237cc9286d811690b34ab80c53293705cf2c Mon Sep 17 00:00:00 2001 From: Mark Erikson Date: Sun, 12 Feb 2023 14:17:24 -0500 Subject: [PATCH 2/2] Add a build step and TS typetest matrix to the existing workflow --- .github/workflows/test.yaml | 35 +++++++++++++++++++++++++++++++++++ package.json | 3 ++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 370c1586d3..7caa380777 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -35,3 +35,38 @@ jobs: - name: Run test suite run: npm test + + - name: Check build + run: npm run build + + test-types: + name: Test Types with TypeScript ${{ matrix.ts }} + + needs: [build] + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + node: ['16.x'] + ts: ['4.1', '4.2', '4.3', '4.4', '4.5', '4.6', '4.7', '4.8', '4.9.2-rc'] + steps: + - name: Checkout repo + uses: actions/checkout@v2 + + - name: Use node ${{ matrix.node }} + uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node }} + cache: 'npm' + + - name: Install dependencies + run: npm ci + + - name: Install TypeScript ${{ matrix.ts }} + run: npm i --save-dev typescript@${{ matrix.ts }} + + - name: Test types + run: | + npm run tsc -- --version + npm run check-types + npm run test:types diff --git a/package.json b/package.json index a4df23e34b..6edbdb77c9 100644 --- a/package.json +++ b/package.json @@ -55,7 +55,8 @@ "build": "rollup -c", "prepublishOnly": "npm run clean && npm run check-types && npm run format:check && npm run lint && npm test", "examples:lint": "eslint --ext js,ts examples", - "examples:test": "cross-env CI=true babel-node examples/testAll.js" + "examples:test": "cross-env CI=true babel-node examples/testAll.js", + "tsc": "tsc" }, "dependencies": {}, "devDependencies": {