Skip to content
Myr

chore(ci): multiple version tests (#575)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* chore(ci): multiple version tests * fix workflow config * fix lint workflow * use alpha testing-library * for now comment out alpha and revisit it later * fix persistAsync test * tweak and fix workflow file * update react alpha and experimental * update react alpha/experimental * update react alpha/experimental

authored by Daishi Kato · committed by GitHub · parent 12b6111 · Browse files · 5 files+112 added−62 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

5 files+112 added−62 removed

  • tests:+29 added−17 removed
  • other:+83 added−45 removed

5 files+112 added−62 removed

added:.github/workflows/lint-and-type.yml+24 added
deleted:.github/workflows/lint.yml-44 removed
added:.github/workflows/test-multiple-versions.yml+58 added
modified:tests/persistAsync.test.tsx+29 added-17 removed
1import { act, render } from '@testing-library/react'1import { act, render, waitFor } from '@testing-library/react'2import create from 'zustand'3import { persist } from 'zustand/middleware'45const createPersistantStore = (initialValue: string | null) => {
93 unmodified lines
99100 const { findByText } = render(<Counter />)101102 await findByText('count: 0')103 await waitFor(() => {103 expect(onRehydrateStorageSpy).toBeCalledWith(104 undefined,105 new Error('getItem error')106 )104 expect(onRehydrateStorageSpy).toBeCalledWith(105 undefined,106 new Error('getItem error')107 )108 })109 })110111 it('can persist state', async () => {112 const { storage, setItemSpy } = createPersistantStore(null)
19 unmodified lines
132 }133134 const { findByText } = render(<Counter />)135 await findByText('count: 0')136 await waitFor(() => {134 expect(onRehydrateStorageSpy).toBeCalledWith({ count: 0 }, undefined)137 expect(onRehydrateStorageSpy).toBeCalledWith({ count: 0 }, undefined)138 })139140 // Write something to the store141 act(() => useStore.setState({ count: 42 }))142 await findByText('count: 42')
14 unmodified lines
157 }158159 const { findByText: findByText2 } = render(<Counter2 />)160 await findByText2('count: 42')161 await waitFor(() => {157 expect(onRehydrateStorageSpy2).toBeCalledWith({ count: 42 }, undefined)162 expect(onRehydrateStorageSpy2).toBeCalledWith({ count: 42 }, undefined)163 })164 })165166 it('can migrate persisted state', async () => {167 const setItemSpy = jest.fn()
67 unmodified lines
235236 const { findByText } = render(<Counter />)237238 await findByText('count: 0')239 await waitFor(() => {233 expect(console.error).toHaveBeenCalled()234 expect(onRehydrateStorageSpy).toBeCalledWith({ count: 0 }, undefined)240 expect(console.error).toHaveBeenCalled()241 expect(onRehydrateStorageSpy).toBeCalledWith({ count: 0 }, undefined)242 })243 })244245 it('can throw migrate error', async () => {246 console.error = jest.fn()
27 unmodified lines
274275 const { findByText } = render(<Counter />)276277 await findByText('count: 0')278 await waitFor(() => {270 expect(onRehydrateStorageSpy).toBeCalledWith(271 undefined,272 new Error('migrate error')273 )279 expect(onRehydrateStorageSpy).toBeCalledWith(280 undefined,281 new Error('migrate error')282 )283 })284 })285286 it('gives the merged state to onRehydrateStorage', async () => {287 const onRehydrateStorageSpy = jest.fn()
24 unmodified lines
312313 const { findByText } = render(<Counter />)314315 await findByText('count: 0')316 await waitFor(() => {306 expect(onRehydrateStorageSpy).toBeCalledWith(307 { count: 1, unstorableMethod },308 undefined309 )317 expect(onRehydrateStorageSpy).toBeCalledWith(318 { count: 1, unstorableMethod },319 undefined320 )321 })322 })323324 it('can custom merge the stored state', async () => {325 const storage = {
76 unmodified lines
modified:package.json+1 added-1 removed
51 unmodified lines
52 "build:context": "rollup -c --config-context",53 "postbuild": "yarn copy",54 "eslint": "eslint --fix '*.{js,json}' '{src,tests}/**/*.{ts,tsx}'",55 "eslint:ci": "eslint '*.{js,json}' '{src,tests}/**/*.{ts,tsx}'",56 "prepare": "yarn build",56 "pretest": "tsc --noEmit",57 "test": "jest",58 "test:ci": "jest",59 "test:dev": "jest --watch --no-coverage",60 "test:coverage:watch": "jest --watch",61 "copy": "shx cp -r dist/src/* dist/esm && shx mv dist/src/* dist && shx rm -rf dist/{src,tests} && shx cp package.json readme.md LICENSE dist && json -I -f dist/package.json -e \"this.private=false; this.devDependencies=undefined; this.optionalDependencies=undefined; this.scripts=undefined; this.prettier=undefined; this.jest=undefined; this['lint-staged']=undefined;\""62 },
110 unmodified lines