Skip to content

Commit

Permalink
refactor(test): use aliases (pmndrs#571)
Browse files Browse the repository at this point in the history
  • Loading branch information
dai-shi authored Sep 28, 2021
1 parent e0ba3be commit ae86695
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 16 deletions.
5 changes: 4 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@
},
"alias": {
"extensions": [".js", ".jsx", ".ts", ".tsx", ".json"],
"map": [["zustand", "./src/index.ts"]]
"map": [
["^zustand$", "./src/index.ts"],
["zustand", "./src"]
]
}
}
},
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@
"rootDir": ".",
"testEnvironment": "jsdom",
"moduleNameMapper": {
"^zustand$": "<rootDir>/src/index.ts"
"^zustand$": "<rootDir>/src/index.ts",
"^zustand/(.*)$": "<rootDir>/src/$1.ts"
},
"modulePathIgnorePatterns": [
"dist"
Expand Down
2 changes: 1 addition & 1 deletion tests/basic.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from 'react'
import { act, fireEvent, render } from '@testing-library/react'
import ReactDOM from 'react-dom'
import create, { EqualityChecker, SetState, StateSelector } from '../src/index'
import create, { EqualityChecker, SetState, StateSelector } from 'zustand'

it('creates a store hook and api object', () => {
let params
Expand Down
4 changes: 2 additions & 2 deletions tests/context.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component as ClassComponent, useEffect, useState } from 'react'
import { render } from '@testing-library/react'
import createContext from '../src/context'
import create from '../src/index'
import create from 'zustand'
import createContext from 'zustand/context'

type CounterState = {
count: number
Expand Down
6 changes: 3 additions & 3 deletions tests/middlewareTypes.test.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { produce } from 'immer'
import type { Draft } from 'immer'
import create, { UseStore } from '../src'
import { NamedSet, devtools, persist } from '../src/middleware'
import { State, StateCreator } from '../src/vanilla'
import create, { UseStore } from 'zustand'
import { NamedSet, devtools, persist } from 'zustand/middleware'
import { State, StateCreator } from 'zustand/vanilla'

type TImmerConfigFn<T extends State> = (fn: (draft: Draft<T>) => void) => void
type TImmerConfig<T extends State> = StateCreator<T, TImmerConfigFn<T>>
Expand Down
4 changes: 2 additions & 2 deletions tests/persistAsync.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { act, render } from '@testing-library/react'
import create from '../src/index'
import { persist } from '../src/middleware'
import create from 'zustand'
import { persist } from 'zustand/middleware'

const createPersistantStore = (initialValue: string | null) => {
let state = initialValue
Expand Down
4 changes: 2 additions & 2 deletions tests/persistSync.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import create from '../src/index'
import { persist } from '../src/middleware'
import create from 'zustand'
import { persist } from 'zustand/middleware'

const createPersistantStore = (initialValue: string | null) => {
let state = initialValue
Expand Down
2 changes: 1 addition & 1 deletion tests/shallow.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import shallow from '../src/shallow'
import shallow from 'zustand/shallow'

describe('shallow', () => {
it('compares primitive values', () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/subscribe.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import create from '../src/index'
import create from 'zustand'

describe('subscribe()', () => {
it('should not be called if new state identity is the same', () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/types.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import create, {
StoreApi,
Subscribe,
UseStore,
} from '../src/index'
} from 'zustand'

it('can use exposed types', () => {
interface ExampleState {
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"noUncheckedIndexedAccess": true,
"baseUrl": ".",
"paths": {
"zustand": ["./src/index.ts"]
"zustand": ["./src/index.ts"],
"zustand/*": ["./src/*.ts"]
}
},
"include": ["src/**/*", "tests/**/*"],
Expand Down

0 comments on commit ae86695

Please sign in to comment.