mirror of
https://github.com/re-rxjs/react-rxjs.git
synced 2025-12-08 18:01:51 +00:00
migrate to vitest
This commit is contained in:
parent
f34a69b639
commit
abfd3ad3fe
@ -31,7 +31,8 @@
|
||||
"build:cjs:dev": "node cjsBuild.js",
|
||||
"build:cjs:prod": "node cjsBuild.js --prod",
|
||||
"build:ts": "tsc -p ./tsconfig-build.json --outDir ./dist --skipLibCheck --emitDeclarationOnly",
|
||||
"test": "jest --coverage",
|
||||
"test": "vitest run --coverage",
|
||||
"test:watch": "vitest watch",
|
||||
"lint": "prettier --check README.md \"src/**/*.{js,jsx,ts,tsx,json,md}\"",
|
||||
"format": "prettier --write README.md \"src/**/*.{js,jsx,ts,tsx,json,md}\"",
|
||||
"prepack": "npm run build"
|
||||
|
||||
@ -1,10 +1,11 @@
|
||||
import { createRoot } from "./create-root"
|
||||
import { BehaviorSubject, of, Subject } from "rxjs"
|
||||
import { substate } from "./substate"
|
||||
import { describe, expect, it, vi } from "vitest"
|
||||
import { combineStates } from "./combineStates"
|
||||
import { StateNode } from "./types"
|
||||
import { createRoot } from "./create-root"
|
||||
import { routeState } from "./route-state"
|
||||
import { substate } from "./substate"
|
||||
import { instanceNode } from "./test-utils/instance-node"
|
||||
import { StateNode } from "./types"
|
||||
|
||||
describe("combineStates", () => {
|
||||
it("combines state nodes into one", () => {
|
||||
@ -126,8 +127,8 @@ describe("combineStates", () => {
|
||||
const promise = combined.getValue({ root: "" })
|
||||
expect(promise).toBeInstanceOf(Promise)
|
||||
|
||||
const next = jest.fn()
|
||||
const complete = jest.fn()
|
||||
const next = vi.fn()
|
||||
const complete = vi.fn()
|
||||
combined.getState$({ root: "" }).subscribe({ next, complete })
|
||||
expect(next).not.toHaveBeenCalled()
|
||||
expect(complete).not.toHaveBeenCalled()
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import { describe, expect, it, vi } from "vitest"
|
||||
import { createSignal } from "./create-signal"
|
||||
import { createRoot } from "./create-root"
|
||||
|
||||
@ -8,7 +9,7 @@ describe("createSignal", () => {
|
||||
|
||||
root.run()
|
||||
|
||||
const next = jest.fn()
|
||||
const next = vi.fn()
|
||||
signal.getSignal$().subscribe(next)
|
||||
expect(next).not.toBeCalled()
|
||||
|
||||
@ -25,12 +26,12 @@ describe("createSignal", () => {
|
||||
|
||||
root.run()
|
||||
|
||||
const nextA = jest.fn()
|
||||
const nextA = vi.fn()
|
||||
signal.getSignal$().subscribe(nextA)
|
||||
|
||||
signal.push(3)
|
||||
|
||||
const nextB = jest.fn()
|
||||
const nextB = vi.fn()
|
||||
signal.getSignal$().subscribe(nextB)
|
||||
|
||||
signal.push(4)
|
||||
@ -55,10 +56,10 @@ describe("createSignal", () => {
|
||||
root.run("a")
|
||||
root.run("b")
|
||||
|
||||
const nextA = jest.fn()
|
||||
const nextA = vi.fn()
|
||||
signal.getSignal$({ gameId: "a" }).subscribe(nextA)
|
||||
|
||||
const nextB = jest.fn()
|
||||
const nextB = vi.fn()
|
||||
signal.getSignal$({ gameId: "b" }).subscribe(nextB)
|
||||
|
||||
signal.push({ gameId: "a" }, 1)
|
||||
@ -98,7 +99,7 @@ describe("createSignal", () => {
|
||||
root.run()
|
||||
|
||||
const signal = createSignal<number, {}>(root)
|
||||
const next = jest.fn()
|
||||
const next = vi.fn()
|
||||
signal.getSignal$().subscribe(next)
|
||||
expect(next).not.toBeCalled()
|
||||
|
||||
|
||||
@ -2,9 +2,9 @@ import {
|
||||
Observable,
|
||||
Subject,
|
||||
Subscription,
|
||||
defer,
|
||||
filter,
|
||||
startWith,
|
||||
defer,
|
||||
} from "rxjs"
|
||||
import type { KeysBaseType } from "../types"
|
||||
import { EMPTY_VALUE } from "./empty-value"
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import { Observable, of, Subject } from "rxjs"
|
||||
import { describe, expect, it, vi } from "vitest"
|
||||
import { createRoot } from "./create-root"
|
||||
import { routeState } from "./route-state"
|
||||
import { substate } from "./substate"
|
||||
@ -65,7 +66,7 @@ describe("routeState", () => {
|
||||
const [key] = routeState(parent, { a: null, b: null }, (v) => v)
|
||||
root.run()
|
||||
|
||||
const next = jest.fn()
|
||||
const next = vi.fn()
|
||||
key.getState$().subscribe({
|
||||
next,
|
||||
})
|
||||
@ -88,7 +89,7 @@ describe("routeState", () => {
|
||||
const [key] = routeState(parent, { a: null, b: null }, () => "a")
|
||||
root.run()
|
||||
|
||||
const next = jest.fn()
|
||||
const next = vi.fn()
|
||||
key.getState$().subscribe({ next })
|
||||
|
||||
parentSource.next(1)
|
||||
|
||||
@ -65,6 +65,9 @@ export const routeState = <
|
||||
node.activateInstance(instanceKey)
|
||||
previousNode = node
|
||||
},
|
||||
error: () => {
|
||||
// TODO any implication here? How will we recover?
|
||||
},
|
||||
})
|
||||
}
|
||||
const removeInstanceRoutes = (instanceKey: K) => {
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import { NEVER, Subject, filter, map, of, startWith } from "rxjs"
|
||||
import { describe, expect, it, vi } from "vitest"
|
||||
import { InstanceUpdate, createRoot, subinstance, substate } from "./"
|
||||
|
||||
describe("subinstance", () => {
|
||||
@ -78,7 +79,7 @@ describe("subinstance", () => {
|
||||
it("ignores adding duplicate key values", () => {
|
||||
const root = createRoot()
|
||||
const instance$ = new Subject<InstanceUpdate<string>>()
|
||||
const instanceFn = jest.fn((id: string) => of(id))
|
||||
const instanceFn = vi.fn((id: string) => of(id))
|
||||
const [instanceNode, keys] = subinstance(
|
||||
root,
|
||||
"keyName",
|
||||
@ -93,7 +94,7 @@ describe("subinstance", () => {
|
||||
expect(instanceNode.getValue({ keyName: "a" })).toEqual("a")
|
||||
expect(instanceFn).toHaveBeenCalledTimes(1)
|
||||
|
||||
const keysObserver = jest.fn()
|
||||
const keysObserver = vi.fn()
|
||||
keys.getState$().subscribe(keysObserver)
|
||||
expect(keysObserver).toHaveBeenCalledTimes(1)
|
||||
|
||||
|
||||
@ -11,6 +11,7 @@ import {
|
||||
throwError,
|
||||
withLatestFrom,
|
||||
} from "rxjs"
|
||||
import { describe, expect, it, vi } from "vitest"
|
||||
import { createRoot } from "./create-root"
|
||||
import { createSignal } from "./create-signal"
|
||||
import { routeState } from "./route-state"
|
||||
@ -431,7 +432,7 @@ describe("subState", () => {
|
||||
const subNode = substate(contextNode, () => source$)
|
||||
root.run()
|
||||
|
||||
const complete = jest.fn()
|
||||
const complete = vi.fn()
|
||||
subNode.getState$({ root: "" }).subscribe({ complete })
|
||||
|
||||
contextSource$.next(1)
|
||||
@ -458,7 +459,7 @@ describe("subState", () => {
|
||||
source$.next(1)
|
||||
|
||||
contextSource$.next(2)
|
||||
const next = jest.fn()
|
||||
const next = vi.fn()
|
||||
subNode.getState$({ root: "" }).subscribe({ next })
|
||||
|
||||
expect(next).not.toHaveBeenCalled()
|
||||
@ -474,7 +475,7 @@ describe("subState", () => {
|
||||
|
||||
contextSource$.next(1)
|
||||
source$.next(1)
|
||||
const next = jest.fn()
|
||||
const next = vi.fn()
|
||||
subNode.getState$().subscribe({
|
||||
complete: () => {
|
||||
subNode.getState$().subscribe({ next })
|
||||
@ -499,7 +500,7 @@ describe("subState", () => {
|
||||
contextSource$.next(1)
|
||||
source$.next(1)
|
||||
|
||||
const complete = jest.fn()
|
||||
const complete = vi.fn()
|
||||
subNode.getState$({ root: "" }).subscribe({ complete })
|
||||
|
||||
contextSource$.next(1)
|
||||
@ -516,7 +517,7 @@ describe("subState", () => {
|
||||
|
||||
contextSource$.next(1)
|
||||
|
||||
const complete = jest.fn()
|
||||
const complete = vi.fn()
|
||||
subNode.getState$({ root: "" }).subscribe({ complete })
|
||||
|
||||
contextSource$.next(2)
|
||||
@ -536,7 +537,7 @@ describe("subState", () => {
|
||||
|
||||
expect(subNodeB.getValue()).toEqual(1)
|
||||
|
||||
const complete = jest.fn()
|
||||
const complete = vi.fn()
|
||||
subNodeB.getState$({ root: "" }).subscribe({ complete })
|
||||
|
||||
contextSource$.next(2)
|
||||
@ -564,7 +565,7 @@ describe("subState", () => {
|
||||
it("cleans up after self-referencing observables", () => {
|
||||
const root = createRoot()
|
||||
const signal = createSignal<string, {}>(root)
|
||||
const teardown = jest.fn()
|
||||
const teardown = vi.fn()
|
||||
const nodeA = substate(
|
||||
root,
|
||||
(_, getState$) =>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user