chore: verify build during test
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Michel Weststrate · committed by Michel Weststrate · parent 18cfe74 · Browse files · 8 files·+135 added−79 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
8 files+135 added−79 removed
- tests:+116 added−77 removed
- other:+19 added−2 removed
Provenance
- Commit
ef8990b- Tree
a94182c- Author
Michel Weststrate <mweststrate@fb.com>- Committer
Michel Weststrate <mweststrate@fb.com>- Parent
18cfe74
8 files changed+135 added−79 removed
modified:__tests__/base.js+34 added-26 removed
453 unmodified lines454 it("can assign by key", () => {455 const nextState = produce(baseState, s => {456 // Map.prototype.set should return the Map itself457 const res = s.aMap.set("force", true)458- expect(res).toBe(s.aMap[DRAFT_STATE].draft)458+ if (!global.USES_BUILD) expect(res).toBe(s.aMap[DRAFT_STATE].draft)459 })460 expect(nextState).not.toBe(baseState)461 expect(nextState.aMap).not.toBe(baseState.aMap)462 expect(nextState.aMap.get("force")).toEqual(true)316 unmodified lines779 it("can add new items", () => {780 const nextState = produce(baseState, s => {781 // Set.prototype.set should return the Set itself782 const res = s.aSet.add("force")783- expect(res).toBe(s.aSet[DRAFT_STATE].draft)783+ if (!global.USES_BUILD) expect(res).toBe(s.aSet[DRAFT_STATE].draft)784 })785 expect(nextState).not.toBe(baseState)786 expect(nextState.aSet).not.toBe(baseState.aSet)787 expect(baseState.aSet.has("force")).toBe(false)115 unmodified lines903 foo: true904 })905 })906 907+ if (!global.USES_BUILD)907- it("preserves non-enumerable properties", () => {908- const baseState = {}909- // Non-enumerable object property910- Object.defineProperty(baseState, "foo", {911- value: {a: 1},912- enumerable: false908+ it("preserves non-enumerable properties", () => {909+ const baseState = {}910+ // Non-enumerable object property911+ Object.defineProperty(baseState, "foo", {912+ value: {a: 1},913+ enumerable: false914+ })915+ // Non-enumerable primitive property916+ Object.defineProperty(baseState, "bar", {917+ value: 1,918+ enumerable: false919+ })920+ const nextState = produce(baseState, s => {921+ expect(s.foo).toBeTruthy()922+ expect(isEnumerable(s, "foo")).toBeFalsy()923+ s.bar++924+ expect(isEnumerable(s, "foo")).toBeFalsy()925+ s.foo.a++926+ expect(isEnumerable(s, "foo")).toBeFalsy()927+ })928+ expect(nextState.foo).toBeTruthy()929+ expect(isEnumerable(nextState, "foo")).toBeFalsy()930 })914- // Non-enumerable primitive property915- Object.defineProperty(baseState, "bar", {916- value: 1,917- enumerable: false918- })919- const nextState = produce(baseState, s => {920- expect(s.foo).toBeTruthy()921- expect(isEnumerable(s, "foo")).toBeFalsy()922- s.bar++923- expect(isEnumerable(s, "foo")).toBeFalsy()924- s.foo.a++925- expect(isEnumerable(s, "foo")).toBeFalsy()926- })927- expect(nextState.foo).toBeTruthy()928- expect(isEnumerable(nextState, "foo")).toBeFalsy()929- })931 932 it("throws on computed properties", () => {933 const baseState = {}934 Object.defineProperty(baseState, "foo", {183 unmodified lines1118 it("should reflect all changes made in the draft immediately", () => {1119 produce(baseState, draft => {1120 draft.anArray[0] = 51121 draft.anArray.unshift("test")1122+ if (!global.USES_BUILD)1121- expect(enumerableOnly(draft.anArray)).toEqual(["test", 5, 2, {c: 3}, 1])1123+ expect(enumerableOnly(draft.anArray)).toEqual([1124+ "test",1125+ 5,1126+ 2,1127+ {c: 3},1128+ 11129+ ])1130 draft.stuffz = "coffee"1131 expect(draft.stuffz).toBe("coffee")1132 })1133 })600 unmodified lines1734 expect(produce(() => nothing)(3)).toBe(undefined)1735 })1736 1737 describe("base state type", () => {1730- testObjectTypes(produce)1738+ if (!global.USES_BUILD) testObjectTypes(produce)1739 testLiteralTypes(produce)1740 })1741 1742 afterEach(() => {254 unmodified linesmodified:__tests__/empty.ts+3 added-1 removed
76 unmodified lines77787980818281838485868757 unmodified lines76 unmodified lines
const nextState = produce(baseState, s => { // Map.prototype.set should return the Map itself const res = s.aMap.set("force", true) // @ts-ignore if (!global.USES_BUILD) expect(res).toBe((s.aMap as any)[DRAFT_STATE].draft) expect(res).toBe((s.aMap as any)[DRAFT_STATE].draft) }) expect(nextState).not.toBe(baseState) expect(nextState.aMap).not.toBe(baseState.aMap) expect(nextState.aMap.get("force")).toEqual(true)57 unmodified linesmodified:__tests__/hooks.js+36 added-10 removed
122 unmodified lines123 describe("when draft is a Map", () => {124 test("assign", () => {125 const key1 = {prop: "val1"}126 const key2 = {prop: "val2"}127+ produce(128+ new Map([129+ ["a", 0],130+ [key1, 1],131+ [key2, 2]132+ ]),127- produce(new Map([["a", 0], [key1, 1], [key2, 2]]), s => {128- s.set("a", 10)129- s.set(key1, 11)130- })133+ s => {134+ s.set("a", 10)135+ s.set(key1, 11)136+ }137+ )138 expectCalls(onAssign)139 })140 test("assign (no change)", () => {141 produce(new Map([["a", 0]]), s => {10 unmodified lines152 test("nested assignments", () => {153 const key1 = {prop: "val1"}154 produce(155 new Map([149- ["a", new Map([[key1, new Map([["b", 1], ["c", 1], ["d", 1]])]])]156+ [157+ "a",158+ new Map([159+ [160+ key1,161+ new Map([162+ ["b", 1],163+ ["c", 1],164+ ["d", 1]165+ ])166+ ]167+ ])168+ ]169 ]),170 s => {171 const nested = s.get("a").get(key1)172 nested.set("b", 2)29 unmodified lines202 const val1 = {prop: "val1"}203 produce({a: new Set(["a", new Set([val1, 1])])}, s => {204 let nested205 s.a.forEach(value => {187- if (isSet(value)) {206+ if (value instanceof Set) {207 nested = value208 }209 })210 nested.add(2)52 unmodified lines263 describe("when draft is a Map -", () => {264 test("delete", () => {265 const key1 = {prop: "val1"}266 const key2 = {prop: "val2"}267+ produce(268+ new Map([269+ ["a", 0],270+ [key1, 1],271+ [key2, 2]272+ ]),248- produce(new Map([["a", 0], [key1, 1], [key2, 2]]), s => {249- s.delete("a")250- s.delete(key1)251- })273+ s => {274+ s.delete("a")275+ s.delete(key1)276+ }277+ )278 expectCalls(onDelete)279 })280 test("delete (no change)", () => {281 produce(new Map(), s => {106 unmodified linesmodified:__tests__/polyfills.js+32 added-26 removed
12 unmodified lines131415161717181920211819202122232425262728293031322324252627282930313334333435363736373839404138394041424344434445464546474849505152535412 unmodified linesSymbol = SymbolConstructorObject.assign = assignReflect.ownKeys = ownKeys
if (!global.USES_BUILD)describe("Symbol", () => { test("NOTHING", () => { const value = common.NOTHING expect(value).toBeTruthy() expect(typeof value).toBe("object") describe("Symbol", () => { test("NOTHING", () => { const value = common.NOTHING expect(value).toBeTruthy() expect(typeof value).toBe("object") }) test("DRAFTABLE", () => { const value = common.DRAFTABLE expect(typeof value).toBe("string") }) test("DRAFT_STATE", () => { const value = common.DRAFT_STATE expect(typeof value).toBe("string") }) }) test("DRAFTABLE", () => { const value = common.DRAFTABLE expect(typeof value).toBe("string") }) test("DRAFT_STATE", () => { const value = common.DRAFT_STATE expect(typeof value).toBe("string") })})
if (!global.USES_BUILD)describe("Reflect.ownKeys", () => { const {ownKeys} = common describe("Reflect.ownKeys", () => { const {ownKeys} = common
// Symbol keys are always last. it("includes symbol keys", () => { const s = SymbolConstructor() const obj = {[s]: 1, b: 1} expect(ownKeys(obj)).toEqual(["b", s]) }) // Symbol keys are always last. it("includes symbol keys", () => { const s = SymbolConstructor() const obj = {[s]: 1, b: 1} expect(ownKeys(obj)).toEqual(["b", s]) })
it("includes non-enumerable keys", () => { const obj = {a: 1} Object.defineProperty(obj, "b", {value: 1}) expect(ownKeys(obj)).toEqual(["a", "b"]) it("includes non-enumerable keys", () => { const obj = {a: 1} Object.defineProperty(obj, "b", {value: 1}) expect(ownKeys(obj)).toEqual(["a", "b"]) }) })
test("suppress jest warning", () => { expect(true).toBe(true)})modified:__tests__/redux.ts+11 added-14 removed
7 unmodified lines8 Immutable9 } from "../src/"10 import * as redux from "redux"11 12-export interface State {12+interface State {13 counter: number14 }15 16-export interface Action {16+interface Action {17 type: string18 payload: number19 }20 21-export const initialState: State = {21+const initialState: State = {22 counter: 023 }24 25 /// =============== Actions26 27-export function addToCounter(addNumber: number) {27+function addToCounter(addNumber: number) {28 return {29 type: "ADD_TO_COUNTER",30 payload: addNumber31 }32 }33 34-export function subFromCounter(subNumber: number) {34+function subFromCounter(subNumber: number) {35 return {36 type: "SUB_FROM_COUNTER",37 payload: subNumber38 }39 }40 41-export const reduceCounterProducer = (42- state: State = initialState,43- action: Action44-) =>41+const reduceCounterProducer = (state: State = initialState, action: Action) =>42 produce(state, draftState => {43 switch (action.type) {44 case "ADD_TO_COUNTER":45 draftState.counter += action.payload3 unmodified lines49 break50 }51 })52 56-export const reduceCounterCurriedProducer = produce(53+const reduceCounterCurriedProducer = produce(54 (draftState: Draft<State>, action: Action) => {55 switch (action.type) {56 case "ADD_TO_COUNTER":57 draftState.counter += action.payload7 unmodified lines65 )66 67 /// =============== Reducers68 72-export const reduce = redux.combineReducers({69+const reduce = redux.combineReducers({70 counterReducer: reduceCounterProducer71 })72 76-export const curredReduce = redux.combineReducers({73+const curredReduce = redux.combineReducers({74 counterReducer: reduceCounterCurriedProducer75 })76 77 // reducing the current state to get the next state!78 // console.log(reduce(initialState, addToCounter(12));79 80 // ================ store81 85-export const store = redux.createStore(reduce)86-export const curriedStore = redux.createStore(curredReduce)82+const store = redux.createStore(reduce)83+const curriedStore = redux.createStore(curredReduce)84 85 it("#470 works with Redux combine reducers", () => {86 assert(87 store.getState().counterReducer,11 unmodified linesmodified:.travis.yml-1 removed
13 unmodified lines14 script:15 - yarn build || travis_terminate 116 - if-node-version 10 || { yarn test && travis_terminate 0; }17 - yarn coveralls18- - yarn test:flow18 jobs:19 include:20 - stage: deploy21 if: branch == master && !fork5 unmodified linesadded:buid.jest.json+17 added
1+{2+ "moduleNameMapper": {3+ "src/.*": "<rootDir>"4+ },5+ "globals": {6+ "USES_BUILD": true,7+ "ts-jest": {8+ "tsConfig": {9+ "noUnusedLocals": false10+ }11+ }12+ },13+ "transform": {14+ "\\.js$": "babel-jest",15+ "\\.ts$": "ts-jest"16+ }17+}modified:package.json+2 added-1 removed
9 unmodified lines10 "jsnext:main": "dist/immer.module.js",11 "react-native": "dist/immer.module.js",12 "types": "./dist/index.d.ts",13 "scripts": {14- "test": "jest",14+ "test": "jest && yarn-or-npm test:build && yarn-or-npm test:flow",15 "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",16 "test:flow": "yarn-or-npm flow check __tests__/flow",17+ "test:build": "yarn-or-npm build && yarn jest --config buid.jest.json",18 "watch": "jest --watch",19 "coverage": "jest --coverage",20 "coveralls": "jest --coverage && cat ./coverage/lcov.info | ./node_modules/.bin/coveralls && rm -rf ./coverage",21 "build": "rimraf dist/ && yarn-or-npm bili && yarn-or-npm typed",85 unmodified lines