Skip to content

Commit

Permalink
chore(ci): multiple version tests (pmndrs#575)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
dai-shi authored Oct 4, 2021
1 parent 12b6111 commit 2367abb
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 62 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/lint-and-type.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: 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 pretest
44 changes: 0 additions & 44 deletions .github/workflows/lint.yml

This file was deleted.

58 changes: 58 additions & 0 deletions .github/workflows/test-multiple-versions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: 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:ci
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@
"postbuild": "yarn copy",
"eslint": "eslint --fix '*.{js,json}' '{src,tests}/**/*.{ts,tsx}'",
"eslint:ci": "eslint '*.{js,json}' '{src,tests}/**/*.{ts,tsx}'",
"prepare": "yarn build",
"pretest": "tsc --noEmit",
"test": "jest",
"test:ci": "jest",
"test:dev": "jest --watch --no-coverage",
"test:coverage:watch": "jest --watch",
"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;\""
Expand Down
46 changes: 29 additions & 17 deletions tests/persistAsync.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { act, render } from '@testing-library/react'
import { act, render, waitFor } from '@testing-library/react'
import create from 'zustand'
import { persist } from 'zustand/middleware'

Expand Down Expand Up @@ -100,10 +100,12 @@ describe('persist middleware with async configuration', () => {
const { findByText } = render(<Counter />)

await findByText('count: 0')
expect(onRehydrateStorageSpy).toBeCalledWith(
undefined,
new Error('getItem error')
)
await waitFor(() => {
expect(onRehydrateStorageSpy).toBeCalledWith(
undefined,
new Error('getItem error')
)
})
})

it('can persist state', async () => {
Expand Down Expand Up @@ -131,7 +133,9 @@ describe('persist middleware with async configuration', () => {

const { findByText } = render(<Counter />)
await findByText('count: 0')
expect(onRehydrateStorageSpy).toBeCalledWith({ count: 0 }, undefined)
await waitFor(() => {
expect(onRehydrateStorageSpy).toBeCalledWith({ count: 0 }, undefined)
})

// Write something to the store
act(() => useStore.setState({ count: 42 }))
Expand All @@ -154,7 +158,9 @@ describe('persist middleware with async configuration', () => {

const { findByText: findByText2 } = render(<Counter2 />)
await findByText2('count: 42')
expect(onRehydrateStorageSpy2).toBeCalledWith({ count: 42 }, undefined)
await waitFor(() => {
expect(onRehydrateStorageSpy2).toBeCalledWith({ count: 42 }, undefined)
})
})

it('can migrate persisted state', async () => {
Expand Down Expand Up @@ -230,8 +236,10 @@ describe('persist middleware with async configuration', () => {
const { findByText } = render(<Counter />)

await findByText('count: 0')
expect(console.error).toHaveBeenCalled()
expect(onRehydrateStorageSpy).toBeCalledWith({ count: 0 }, undefined)
await waitFor(() => {
expect(console.error).toHaveBeenCalled()
expect(onRehydrateStorageSpy).toBeCalledWith({ count: 0 }, undefined)
})
})

it('can throw migrate error', async () => {
Expand Down Expand Up @@ -267,10 +275,12 @@ describe('persist middleware with async configuration', () => {
const { findByText } = render(<Counter />)

await findByText('count: 0')
expect(onRehydrateStorageSpy).toBeCalledWith(
undefined,
new Error('migrate error')
)
await waitFor(() => {
expect(onRehydrateStorageSpy).toBeCalledWith(
undefined,
new Error('migrate error')
)
})
})

it('gives the merged state to onRehydrateStorage', async () => {
Expand Down Expand Up @@ -303,10 +313,12 @@ describe('persist middleware with async configuration', () => {
const { findByText } = render(<Counter />)

await findByText('count: 0')
expect(onRehydrateStorageSpy).toBeCalledWith(
{ count: 1, unstorableMethod },
undefined
)
await waitFor(() => {
expect(onRehydrateStorageSpy).toBeCalledWith(
{ count: 1, unstorableMethod },
undefined
)
})
})

it('can custom merge the stored state', async () => {
Expand Down

0 comments on commit 2367abb

Please sign in to comment.