Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update TS dev tooling and GH Actions workflow #320

Merged
merged 3 commits into from
Oct 23, 2021
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
68 changes: 53 additions & 15 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,65 @@
name: Tests

on: [push, pull_request]

name: CI
on: [pull_request]
jobs:
build:
name: Test Suite
name: Lint and Test on Node ${{ matrix.node }}

runs-on: ubuntu-latest
strategy:
matrix:
node: ['14.x']

steps:
- name: Set up Node
- name: Checkout repo
uses: actions/checkout@v2

- name: Use node ${{ matrix.node }}
uses: actions/setup-node@v1
with:
node-version: 14
cache: npm
node-version: ${{ matrix.node }}

- name: Checkout code
uses: actions/checkout@v2
- uses: c-hive/gha-npm-cache@v1

- name: Install deps
run: npm ci --ignore-scripts

- name: Run linter
run: npm run lint

- name: Install dependencies
run: npm ci
- name: Run tests
run: npm test

- name: Run build
- name: Compile
run: npm run build

- name: Run test suite
run: npm test
test-types:
name: Test Types with TypeScript ${{ matrix.ts }}

needs: [build]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node: ['14.x']
ts: ['3.9', '4.0', '4.1', '4.2', '4.3', '4.4', 'next']
steps:
- name: Checkout repo
uses: actions/checkout@v2

- name: Use node ${{ matrix.node }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}

- uses: c-hive/gha-npm-cache@v1

- name: Install deps
run: npm ci --ignore-scripts

- name: Install TypeScript ${{ matrix.ts }}
run: npm install typescript@${{ matrix.ts }} --ignore-scripts

- name: Test types
run: |
./node_modules/.bin/tsc --version
npm run test:typescript
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
],
"scripts": {
"clean": "rimraf lib dist es",
"prepare": "npm run clean && npm run lint && npm run test && npm run build",
"prepublishOnly": "npm run clean && npm run lint && npm run test && npm run build",
"lint": "eslint src test",
"test": "cross-env BABEL_ENV=commonjs mocha --require @babel/register --reporter spec test/*.js",
"test:typescript": "tsc --noEmit -p test/tsconfig.json",
"build": "npm run build:commonjs && npm run build:umd && npm run build:umd:min && npm run build:es",
"build:commonjs": "cross-env BABEL_ENV=commonjs babel src --out-dir lib",
"build:es": "cross-env BABEL_ENV=es babel src --out-dir es",
Expand Down Expand Up @@ -84,7 +85,7 @@
"prettier": "^1.18.2",
"redux": "^4",
"rimraf": "^3.0.0",
"typescript": "^3.6.2",
"typescript": "^4.4",
"typings-tester": "^0.3.2",
"webpack": "^4.39.3",
"webpack-cli": "^3.3.7"
Expand Down
17 changes: 14 additions & 3 deletions test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
{
"compilerOptions": {
"lib": ["dom", "es2017"],
"strict": true
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"emitDeclarationOnly": false,
"strict": true,
"noEmit": true,
"target": "esnext",
"jsx": "react",
"baseUrl": ".",
"skipLibCheck": true,
"noImplicitReturns": false,
"noUnusedLocals": false
},
"files": ["./*.ts", "./*.js"]
"include": ["**/*.ts"]
}
22 changes: 11 additions & 11 deletions test/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ const store = createStore(

store.dispatch((dispatch) => {
dispatch({ type: 'FOO' });
// typings:expect-error
// @ts-expect-error
dispatch({ type: 'BAR' });
dispatch({ type: 'BAR', result: 5 });
// typings:expect-error
// @ts-expect-error
store.dispatch({ type: 'BAZ' });
});

Expand All @@ -47,10 +47,10 @@ function testGetState(): ThunkResult<void> {
const state = getState();
const { foo } = state;
dispatch({ type: 'FOO' });
// typings:expect-error
// @ts-expect-error
dispatch({ type: 'BAR' });
dispatch({ type: 'BAR', result: 5 });
// typings:expect-error
// @ts-expect-error
dispatch({ type: 'BAZ' });
// Can dispatch another thunk action
dispatch(anotherThunkAction());
Expand Down Expand Up @@ -91,20 +91,20 @@ const actions: ActionDispatchs = bindActionCreators(
);

actions.anotherThunkAction() === 'hello';
// typings:expect-error
// @ts-expect-error
actions.anotherThunkAction() === false;
actions.promiseThunkAction().then((res) => console.log(res));
// typings:expect-error
// @ts-expect-error
actions.promiseThunkAction().prop;
actions.standardAction().type;
// typings:expect-error
// @ts-expect-error
actions.standardAction().other;

store.dispatch({ type: 'FOO' });
// typings:expect-error
// @ts-expect-error
store.dispatch({ type: 'BAR' });
store.dispatch({ type: 'BAR', result: 5 });
// typings:expect-error
// @ts-expect-error
store.dispatch({ type: 'BAZ' });
store.dispatch(testGetState());

Expand All @@ -120,10 +120,10 @@ const storeThunkArg = createStore(
storeThunkArg.dispatch((dispatch, getState, extraArg) => {
const bar: string = extraArg;
store.dispatch({ type: 'FOO' });
// typings:expect-error
// @ts-expect-error
store.dispatch({ type: 'BAR' });
store.dispatch({ type: 'BAR', result: 5 });
// typings:expect-error
// @ts-expect-error
store.dispatch({ type: 'BAZ' });
console.log(extraArg);
});
Expand Down