Skip to content
Myr

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

8 files+135 added−79 removed

modified:__tests__/base.js+34 added-26 removed
453 unmodified lines
454 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 lines
779 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 lines
903 foo: true904 })905 })906907 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 })931932 it("throws on computed properties", () => {933 const baseState = {}934 Object.defineProperty(baseState, "foo", {
183 unmodified lines
1118 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 lines
1734 expect(produce(() => nothing)(3)).toBe(undefined)1735 })17361737 describe("base state type", () => {1730 testObjectTypes(produce)1738 if (!global.USES_BUILD) testObjectTypes(produce)1739 testLiteralTypes(produce)1740 })17411742 afterEach(() => {
254 unmodified lines
modified:__tests__/empty.ts+3 added-1 removed
modified:__tests__/hooks.js+36 added-10 removed
122 unmodified lines
123 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 lines
152 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 lines
202 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 lines
263 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 lines
modified:__tests__/polyfills.js+32 added-26 removed
modified:__tests__/redux.ts+11 added-14 removed
7 unmodified lines
8 Immutable9} from "../src/"10import * as redux from "redux"1112export interface State {12interface State {13 counter: number14}1516export interface Action {16interface Action {17 type: string18 payload: number19}2021export const initialState: State = {21const initialState: State = {22 counter: 023}2425/// =============== Actions2627export function addToCounter(addNumber: number) {27function addToCounter(addNumber: number) {28 return {29 type: "ADD_TO_COUNTER",30 payload: addNumber31 }32}3334export function subFromCounter(subNumber: number) {34function subFromCounter(subNumber: number) {35 return {36 type: "SUB_FROM_COUNTER",37 payload: subNumber38 }39}4041export const reduceCounterProducer = (42 state: State = initialState,43 action: Action44) =>41const reduceCounterProducer = (state: State = initialState, action: Action) =>42 produce(state, draftState => {43 switch (action.type) {44 case "ADD_TO_COUNTER":45 draftState.counter += action.payload
3 unmodified lines
49 break50 }51 })5256export const reduceCounterCurriedProducer = produce(53const reduceCounterCurriedProducer = produce(54 (draftState: Draft<State>, action: Action) => {55 switch (action.type) {56 case "ADD_TO_COUNTER":57 draftState.counter += action.payload
7 unmodified lines
65)6667/// =============== Reducers6872export const reduce = redux.combineReducers({69const reduce = redux.combineReducers({70 counterReducer: reduceCounterProducer71})7276export const curredReduce = redux.combineReducers({73const curredReduce = redux.combineReducers({74 counterReducer: reduceCounterCurriedProducer75})7677// reducing the current state to get the next state!78// console.log(reduce(initialState, addToCounter(12));7980// ================ store8185export const store = redux.createStore(reduce)86export const curriedStore = redux.createStore(curredReduce)82const store = redux.createStore(reduce)83const curriedStore = redux.createStore(curredReduce)8485it("#470 works with Redux combine reducers", () => {86 assert(87 store.getState().counterReducer,
11 unmodified lines
modified:.travis.yml-1 removed
13 unmodified lines
14script:15 - yarn build || travis_terminate 116 - if-node-version 10 || { yarn test && travis_terminate 0; }17 - yarn coveralls18 - yarn test:flow18jobs:19 include:20 - stage: deploy21 if: branch == master && !fork
5 unmodified lines
added: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 lines
10 "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