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
Provenance
- Commit
2367abb- Tree
6de5e76- Author
Daishi Kato <dai-shi@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
12b6111
5 files changed+112 added−62 removed
added:.github/workflows/lint-and-type.yml+24 added
123456789101112131415161718192021222324name: Lint and Type
on: push: branches: [main] pull_request: types: [opened, synchronize]
jobs: lint: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v2 with: node-version: '12' cache: yarn - run: git fetch --depth=1 origin +refs/tags/*:refs/tags/* - run: yarn install --frozen-lockfile --check-files - run: cd examples && yarn install --frozen-lockfile --check-files - name: Lint run: yarn eslint:ci - name: Type run: yarn pretestdeleted:.github/workflows/lint.yml-44 removed
1234567891011121314151617181920212223242526272829303132333435363738394041424344name: Lint
on: push: branches: [main, master] pull_request: types: [opened, synchronize]
jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - run: git fetch --depth=1 origin +refs/tags/*:refs/tags/* - run: yarn install --frozen-lockfile --check-files - run: cd examples && yarn install --frozen-lockfile --check-files - run: yarn build - uses: actions/cache@v1 id: cache-build with: path: "." key: ${{ github.sha }}
lint: runs-on: ubuntu-latest needs: build steps: - uses: actions/cache@v1 id: restore-build with: path: "." key: ${{ github.sha }} - run: yarn eslint:ci
test: runs-on: ubuntu-latest needs: build steps: - uses: actions/cache@v1 id: restore-build with: path: "." key: ${{ github.sha }} - run: yarn testadded:.github/workflows/test-multiple-versions.yml+58 added
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758name: Test Multiple Versions
on: push: branches: [main] pull_request: types: [opened, synchronize]
jobs: test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v2 with: node-version: '12' cache: yarn - run: git fetch --depth=1 origin +refs/tags/*:refs/tags/* - run: yarn install --frozen-lockfile --check-files - name: Test Build # we don't have any other workflows to test build run: yarn build - name: Test Default run: yarn test:ci
test_matrix: runs-on: ubuntu-latest strategy: fail-fast: false matrix: react: - 16.8.0 - 17.0.0 - 18.0.0-alpha-f2c381131-20211004 - 0.0.0-experimental-f2c381131-20211004 testing: [default, alpha] exclude: - { react: 16.8.0, testing: alpha } - { react: 17.0.0, testing: alpha } steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v2 with: node-version: '12' cache: yarn - run: git fetch --depth=1 origin +refs/tags/*:refs/tags/* - run: yarn install --frozen-lockfile --check-files - name: Install alpha testing-library if: ${{ matrix.testing == 'alpha' }} run: yarn add -D @testing-library/react@alpha - name: Patch for React 16 if: ${{ startsWith(matrix.react, '16.') }} run: | sed -i~ '1s/^/import React from "react";/' tests/*.tsx sed -i~ 's/automatic/classic/' babel.config.js - name: Test ${{ matrix.react }} run: | yarn add -D react@${{ matrix.react }} react-dom@${{ matrix.react }} yarn test:cimodified:tests/persistAsync.test.tsx+29 added-17 removed
1-import { act, render } from '@testing-library/react'1+import { act, render, waitFor } from '@testing-library/react'2 import create from 'zustand'3 import { persist } from 'zustand/middleware'4 5 const createPersistantStore = (initialValue: string | null) => {93 unmodified lines99 100 const { findByText } = render(<Counter />)101 102 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 })110 111 it('can persist state', async () => {112 const { storage, setItemSpy } = createPersistantStore(null)19 unmodified lines132 }133 134 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+ })139 140 // Write something to the store141 act(() => useStore.setState({ count: 42 }))142 await findByText('count: 42')14 unmodified lines157 }158 159 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 })165 166 it('can migrate persisted state', async () => {167 const setItemSpy = jest.fn()67 unmodified lines235 236 const { findByText } = render(<Counter />)237 238 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 })244 245 it('can throw migrate error', async () => {246 console.error = jest.fn()27 unmodified lines274 275 const { findByText } = render(<Counter />)276 277 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 })285 286 it('gives the merged state to onRehydrateStorage', async () => {287 const onRehydrateStorageSpy = jest.fn()24 unmodified lines312 313 const { findByText } = render(<Counter />)314 315 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 })323 324 it('can custom merge the stored state', async () => {325 const storage = {76 unmodified linesmodified:package.json+1 added-1 removed
51 unmodified lines52 "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