sourcegraph/client/web-sveltekit/package.json
Felix Kling fff87e4a50
sveltekit: Setup unit tests with vitest (#54953)
This PR adds vitest and faker for unit testing, and to use it properly
already I refactored the promise->store helper to be more flexible.

**Unit testing**
vitest works prefectly together with vite (it's from the same
author/community). It will use the same configuration and so there is
very little additional configuration necessary.
I only had to update vite.config.ts to not overwrite `process` (but
according to https://vitejs.dev/config/shared-options.html#define I
might not be doing it right anyway... will look into this another time).

The API is pretty compatible with jest, so there shouldn't be any
surprises.

Tests can be run with `pnpm vitest`.

**Faker**
I stared to use faker on a differnt branch to generate more (and more
realistic) test data for storybook stories and unit test. Eventually I'd
like to use this to generate mock data for any of our GraphQL APIs. One
great feature is the ability to _seed_ the random number generator so
that you can get random but repeatable values in tests.

**Promise<>store utility**
Working with promises in a reactive way can be tricky. There is a risk
of stale data ovewriting current data when an older promise resolves
after a newer one.
Observables can help here but since we are trying to move away from
them, I introduced a simple store to handle promises. I extended it now
to handle more cases, especially being able to access the previous value
while a new promise is loading. The API might seem clunky (and I'd be
happy to improve it eventually), but this way makes it easier to
remember to call `set` whenever the promise changes.



## Test plan

`pnpm vitest`

Run dev server, open pages affected by promise store changes (repo
pages) and verify that they behave as expected.
2023-07-19 16:58:29 +02:00

62 lines
2.0 KiB
JSON

{
"name": "@sourcegraph/web-sveltekit",
"version": "0.0.1",
"scripts": {
"dev": "vite dev",
"dev:dotcom": "vite dev --mode=dotcom",
"dev:oss": "vite dev --mode=oss",
"build": "vite build",
"preview": "vite preview",
"test": "playwright test",
"sync": "svelte-kit sync",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
"lint": "eslint .",
"format": "prettier --plugin-search-dir . --write .",
"generate": "pnpm -w generate",
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build"
},
"devDependencies": {
"@faker-js/faker": "^8.0.2",
"@playwright/test": "1.25.0",
"@storybook/addon-essentials": "^7.0.26",
"@storybook/addon-interactions": "^7.0.26",
"@storybook/addon-links": "^7.0.26",
"@storybook/blocks": "^7.0.26",
"@storybook/svelte": "^7.0.26",
"@storybook/sveltekit": "^7.0.26",
"@storybook/testing-library": "^0.0.14-next.2",
"@sveltejs/adapter-auto": "^2.1.0",
"@sveltejs/adapter-static": "^2.0.2",
"@sveltejs/kit": "^1.20.4",
"@types/cookie": "^0.5.1",
"@types/prismjs": "^1.26.0",
"eslint-plugin-storybook": "^0.6.12",
"eslint-plugin-svelte3": "^4.0.0",
"prettier-plugin-svelte": "^2.10.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"storybook": "^7.0.26",
"storybook-dark-mode": "^3.0.0",
"svelte": "^4.0.0",
"svelte-check": "^3.4.3",
"tslib": "2.1.0",
"vite": "^4.3.9",
"vitest": "^0.33.0"
},
"type": "module",
"dependencies": {
"@popperjs/core": "^2.11.8",
"@remix-run/router": "~1.3.2",
"@sourcegraph/branded": "workspace:*",
"@sourcegraph/common": "workspace:*",
"@sourcegraph/http-client": "workspace:*",
"@sourcegraph/shared": "workspace:*",
"@sourcegraph/web": "workspace:*",
"@sourcegraph/wildcard": "workspace:*",
"lodash-es": "^4.17.21",
"prismjs": "^1.29.0"
}
}