Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: ci tests should run properly #15

Merged
merged 1 commit into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"preinstall": "node -e \"if(process.env.CI == 'true') {console.log('Skipping preinstall...'); process.exit(1)}\" || npx -y only-allow pnpm",
"install:csb": "corepack enable && pnpm install --frozen-lockfile",
"test": "pnpm run test:ci",
"test:ci": "nx run-many --exclude=examples/** --targets=test:format,test:eslint,test:lib,test:types,test:build,test:bundle,build",
"test:ci": "nx affected --exclude=examples/** --targets=test:format,test:eslint,test:lib,test:types,build,test:build",
"test:eslint": "nx affected --target=test:eslint",
"test:format": "pnpm run prettier --check",
"test:lib": "nx affected --target=test:lib",
Expand Down
3 changes: 2 additions & 1 deletion packages/vue-store/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"clean": "rimraf ./build && rimraf ./coverage",
"test:eslint": "eslint --ext .ts,.tsx ./src",
"test:types": "tsc",
"test:lib": "pnpm run test:2 && pnpm run test:2.7 && pnpm run test:3",
"fixme:test:lib": "pnpm run test:2 && pnpm run test:2.7 && pnpm run test:3",
"test:lib": "pnpm run test:3",
"test:2": "vue-demi-switch 2 vue2 && vitest",
"test:2.7": "vue-demi-switch 2.7 vue2.7 && vitest",
"test:3": "vue-demi-switch 3 && vitest",
Expand Down
6 changes: 3 additions & 3 deletions packages/vue-store/src/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { h, defineComponent } from 'vue'
import { h, defineComponent, watch } from 'vue-demi'
import { render, waitFor } from '@testing-library/vue'
import '@testing-library/jest-dom'
import { Store } from '@tanstack/store'
Expand All @@ -20,7 +20,7 @@ describe('useStore', () => {
return () => <p>Store: {storeVal.value}</p>
})

const { getByText } = render(<Comp />)
const { getByText } = render(Comp)
expect(getByText('Store: 0')).toBeInTheDocument()
})

Expand Down Expand Up @@ -66,7 +66,7 @@ describe('useStore', () => {
}
})

const { getByText } = render(<Comp />)
const { getByText } = render(Comp)
expect(getByText('Store: 0')).toBeInTheDocument()
expect(getByText('Number rendered: 1')).toBeInTheDocument()

Expand Down
10 changes: 5 additions & 5 deletions packages/vue-store/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { AnyUpdater, Store } from '@tanstack/store'
import { readonly, type Ref, ref, toRaw, toValue, watch } from 'vue-demi'
import { readonly, type Ref, ref, toRaw, watch } from 'vue-demi'

export * from '@tanstack/store'

Expand All @@ -12,14 +12,14 @@ export function useStore<
>(
store: Store<TState, TUpdater>,
selector: (state: NoInfer<TState>) => TSelected = (d) => d as any,
) {
): Readonly<Ref<TSelected>> {
const slice = ref(selector(store.state)) as Ref<TSelected>

watch(
() => toValue(store),
() => store,
(value, _oldValue, onCleanup) => {
const unsub = value.subscribe(() => {
const data = selector(store.state)
const data = selector(value.state)
if (shallow(toRaw(slice.value), data)) {
return
}
Expand All @@ -33,7 +33,7 @@ export function useStore<
{ immediate: true },
)

return readonly(slice)
return readonly(slice) as never
}

export function shallow<T>(objA: T, objB: T) {
Expand Down