From e8fe4ba2b1ce42175b5a42ded99f9562cc493d76 Mon Sep 17 00:00:00 2001 From: aleclarson Date: Sun, 16 Dec 2018 09:37:22 -0500 Subject: [PATCH] fix(test): faulty .flowconfig The .js.flow tests were not working, because of a faulty config file. --- .flowconfig => __tests__/flow/.flowconfig | 8 +- __tests__/flow/flow.js.flow | 2 +- __tests__/flow/ts.ts | 98 ----------------------- package.json | 2 +- 4 files changed, 6 insertions(+), 104 deletions(-) rename .flowconfig => __tests__/flow/.flowconfig (62%) delete mode 100644 __tests__/flow/ts.ts diff --git a/.flowconfig b/__tests__/flow/.flowconfig similarity index 62% rename from .flowconfig rename to __tests__/flow/.flowconfig index b06faed4..3d2de4f5 100644 --- a/.flowconfig +++ b/__tests__/flow/.flowconfig @@ -1,8 +1,8 @@ -[ignore] -.*/node_modules - [include] -__tests__/flow +../../dist + +[lints] +untyped-import=error [options] suppress_comment= \\(.\\|\n\\)*\\$ExpectError diff --git a/__tests__/flow/flow.js.flow b/__tests__/flow/flow.js.flow index 8e223349..2e40774b 100644 --- a/__tests__/flow/flow.js.flow +++ b/__tests__/flow/flow.js.flow @@ -6,7 +6,7 @@ import produce, { applyPatches, Patch, original -} from "../../src/index.js" +} from "../../dist/immer.js" setAutoFreeze(true) setUseProxies(true) diff --git a/__tests__/flow/ts.ts b/__tests__/flow/ts.ts deleted file mode 100644 index 1b2e07f9..00000000 --- a/__tests__/flow/ts.ts +++ /dev/null @@ -1,98 +0,0 @@ -import produce, {setAutoFreeze, setUseProxies, original} from "../../src/index" - -setAutoFreeze(true) -setUseProxies(true) - -// we really don't want this code to actually execute.. -const result = produce({x: 3}, draft => { - draft.x = 4 - - // $ExpectError - console.log(draft.y) -}) - -console.log(result.x) - -const f2 = produce(draft => {}) -f2({x: 3}) - -// $ExpectError -setAutoFreeze(3) - -// $ExpectError -console.log(result.y) - -// $ExpectError -produce() - -// $ExpectError -produce({x: 3}) - -// $ExpectError -produce({x: 3}, []) - -{ - // curried & initial arg - const f = produce( - (state, increment: number) => { - state.x += increment - }, - {x: 3} - ) - - // $ExpectError Too few arguments - f({x: 5}) - - // $ExpectError - f({x: 5}, "test") - - f({x: 5}, 3) - - f(undefined, 3) -} - -{ - // curried f & no initial arg - const f2 = produce((state: {x: number}, increment: number) => { - state.x += increment - }) - - f2({x: 5}, 3) - - // $ExpectError - f2(undefined, 3) -} - -{ - // Issue #129 - const handlers = { - ["TEST"]: (draft: {}, {id, value}: {id: string; value: string}) => { - draft[id] = {...draft[id], value} - return draft - } - } - - const reducer = (state = {}, {type, payload}: any): any => - handlers[type] - ? produce(handlers[type])(state, payload) - : state -} - -produce({x: 3, z: {}}, draftState => { - const a = draftState - - if (a) { - a.x - // $ExpectError - a.y - } -}) - -produce([1], draftState => { - const a = original(draftState) - if (a) { - // $ExpectError - const b: string = a[0] - const c: number = a[0] - } -}) diff --git a/package.json b/package.json index 76b0863b..9e7b1e22 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "watch": "jest --watch", "test": "jest", "test:perf": "NODE_ENV=production yarn-or-npm build && cd __performance_tests__ && babel-node add-data.js && babel-node todo.js && babel-node incremental.js", - "test:flow": "yarn-or-npm flow check", + "test:flow": "yarn-or-npm flow check __tests__/flow", "test:dts": "tsc -p __tests__/tsconfig.json --noEmit", "coveralls": "jest --coverage && cat ./coverage/lcov.info | ./node_modules/.bin/coveralls && rm -rf ./coverage", "build": "rimraf dist/ && cross-env NODE_ENV=production rollup -c && cpx 'src/immer.{d.ts,js.flow}' dist -v"