Skip to content

Commit a72e8ea

Browse files
Breaking: Monorepo. Svelte 5 migration. Visual testing (#124)
* test: initialize test-app * test: add basic, real app test * chore: run sv migrate svelte-5 * wip * chore: migrate to monorepo structure * fix: TestApp spm setup * wip * breaking: add createOpenModal. createOpenModal must be called to correctly associate component's lifecycle which is impossible with only * test: migrate tests-ct to test-app e2e tests * test: migrate focus-trap tests * chore: remove old tests-ct and unused scripts * chore: add dev.Dockerfile for running visual tests * chore: run format * test: add more visual snapshot checks * feat(breaking): don't export useModalContext, openModal * chore: fix lints * chore: fix ci commands * fix: missing env * chore: remove -t from docker for CI support * chore: specify .env.test * chore: add .env.test for test-app * cleanup .env situation * remove playwright from root * Revert "remove playwright from root" This reverts commit 4bdc21f.
1 parent 95ce502 commit a72e8ea

File tree

121 files changed

+3174
-2237
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+3174
-2237
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,55 +15,31 @@ jobs:
1515
- uses: wyvox/action-setup-pnpm@v3
1616
with:
1717
node-version: ${{ env.NODE_VERSION }}
18-
- name: Install Dependencies
19-
run: pnpm install
20-
- name: Run lint
21-
run: pnpm lint
18+
- run: pnpm install
19+
- run: pnpm lint
2220

2321
tests_e2e:
2422
name: Run end-to-end tests
2523
runs-on: ubuntu-latest
2624
needs: [lint]
27-
strategy:
28-
fail-fast: false
29-
matrix:
30-
# TODO: Fix tests for Svelte 5
31-
# svelte-version: ['4.2.12', '5.0.0']
32-
svelte-version: ['4.2.12']
3325

3426
steps:
3527
- uses: actions/checkout@v4
3628
- uses: wyvox/action-setup-pnpm@v3
3729
with:
3830
node-version: ${{ env.NODE_VERSION }}
39-
- name: Install Dependencies
40-
run: pnpm install
41-
- name: Install Svelte version ${{ matrix.svelte-version }}
42-
run: pnpm add -D svelte@${{ matrix.svelte-version }}
43-
- name: Install playwright browsers
44-
run: pnpm exec playwright install
45-
- name: Run tests
46-
run: pnpm test:ct
31+
- run: pnpm install
32+
- run: cp svelte-promise-modals/.env.example svelte-promise-modals/.env && pnpm test:visual
4733

4834
tests_unit:
4935
name: Run unit tests
5036
runs-on: ubuntu-latest
5137
needs: [lint]
52-
strategy:
53-
fail-fast: false
54-
matrix:
55-
# TODO: Fix tests for Svelte 5
56-
# svelte-version: ['4.2.12', '5.0.0']
57-
svelte-version: ['4.2.12']
5838

5939
steps:
6040
- uses: actions/checkout@v4
6141
- uses: wyvox/action-setup-pnpm@v3
6242
with:
6343
node-version: ${{ env.NODE_VERSION }}
64-
- name: Install Dependencies
65-
run: pnpm install
66-
- name: Install Svelte version ${{ matrix.svelte-version }}
67-
run: pnpm add -D svelte@${{ matrix.svelte-version }}
68-
- name: Run unit tests
69-
run: pnpm test:unit
44+
- run: pnpm install
45+
- run: pnpm -F svelte-promise-modals test:unit

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ node_modules
77
.env
88
.env.*
99
!.env.example
10+
!.env.test
1011
vite.config.js.timestamp-*
1112
vite.config.ts.timestamp-*
1213
/test-results/

README.md

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,20 @@ To use SPM in your project, add the target for the modals to your root template:
3434
<ModalContainer />
3535
```
3636

37-
Then you can import the `openModal` function wherever you need it and call with a component reference to
38-
render it as a modal.
37+
Then you can import the `createOpenModal` function that you need to call at the _root_ level of a component.
38+
It produces a function that you can finally use to open modals.
39+
```ts
40+
import { createOpenModal } from 'svelte-promise-modals';
41+
let openModal = createOpenModal();
42+
```
3943

4044
```svelte
4145
<script>
42-
import { openModal } from 'svelte-promise-modals';
46+
import { createOpenModal } from 'svelte-promise-modals';
4347
import SomeComponent from './SomeComponent.svelte';
4448
49+
let openModal = createOpenModal();
50+
4551
async function handleOpenModal() {
4652
let modal = openModal(SomeComponent);
4753
@@ -115,8 +121,10 @@ Then when you open the modal, it'll correctly infer the type of the result:
115121

116122
```svelte
117123
<script lang="ts">
118-
import { openModal } from 'svelte-promise-modals';
124+
import { createOpenModal } from 'svelte-promise-modals';
119125
import MyModal from './MyModal.svelte';
126+
127+
let openModal = createOpenModal();
120128
121129
async function handleOpenModal() {
122130
// You can specify `string` here, but it's also automatically inferred
@@ -154,9 +162,9 @@ unrendered.
154162

155163
```svelte
156164
<script>
157-
import { useModalContext } from 'svelte-promise-modals';
165+
import { createOpenModal } from 'svelte-promise-modals';
158166
159-
let { openModal } = useModalContext();
167+
let openModal = createOpenModal();
160168
161169
async function handleOpenModal() {
162170
let result = await openModal(FooModal);
@@ -337,13 +345,21 @@ In order to speed up modal in/out animations during testing, either:
337345

338346
Once you've cloned the project and installed dependencies with `pnpm install`, start a development server:
339347

348+
- `pnpm -F svelte-promise-modals dev` Running https://svelte-promise-modals.com/ website
349+
- `pnpm -F test-app dev` Running the `test-app` which contains modal testing scenarios. Also used for automated testing using Playwright, including Visual testing.
350+
- `pnpm test` Run Unit and E2E tests.
351+
- `pnpm -F test-app test:e2e` Run only E2E tests
352+
- `pnpm test:visual` Run only E2E tests inside docker *preferred* method to make sure screenshots are consistent across platforms.
353+
340354
```bash
341-
npm run dev
355+
pnpm -F svelte-promise-modals dev
342356

343357
# or start the server and open the app in a new browser tab
344-
npm run dev -- --open
358+
pnpm -F svelte-promise-modals dev -- --open
345359
```
346360

361+
362+
347363
## License
348364

349365
svelte-promise-modals is developed by and © Mainmatter GmbH and contributors. It is released under

dev.Dockerfile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
FROM mcr.microsoft.com/playwright:v1.53.1-noble AS base
2+
ARG DOCKER_USER
3+
ENV PNPM_HOME="/pnpm"
4+
ENV PATH="$PNPM_HOME:$PATH"
5+
6+
COPY --chown=$DOCKER_USER . /app
7+
WORKDIR /app
8+
ENV COREPACK_ENABLE_DOWNLOAD_PROMPT=0
9+
RUN corepack enable
10+
11+
FROM base AS build
12+
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
13+
14+
FROM build
15+
COPY --from=build /app/node_modules /app/node_modules
16+
17+
RUN corepack install
18+
RUN pnpm install
19+
RUN pnpm playwright install

package.json

Lines changed: 10 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,24 @@
11
{
2-
"name": "svelte-promise-modals",
2+
"name": "root",
3+
"private": true,
34
"version": "0.1.5",
45
"repository": "https://github.com/mainmatter/svelte-promise-modals",
56
"scripts": {
6-
"prepare": "svelte-kit sync",
7-
"dev": "vite dev",
8-
"build": "vite build && npm run package",
9-
"preview": "vite preview",
10-
"package": "svelte-kit sync && svelte-package && publint",
117
"release": "release-it",
128
"prepublishOnly": "npm run package",
13-
"test:ct:debug": "PWDEBUG=1 playwright test -c playwright-ct.config.ts",
14-
"test:ct": "playwright test -c playwright-ct.config.ts",
159
"changelog": "lerna-changelog",
16-
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
17-
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
18-
"test:unit": "vitest",
19-
"lint": "prettier --check . && eslint .",
20-
"format": "prettier --write . && eslint . --fix",
21-
"test:svelte4": "pnpm add -D [email protected] && pnpm test:unit && pnpm test:ct",
22-
"test:svelte5": "pnpm add -D svelte@next && pnpm test:unit && pnpm test:ct",
23-
"test:all-versions": "pnpm test:svelte4 && pnpm test:svelte5"
10+
"test": "pnpm -F svelte-promise-modals test:unit --run && pnpm -F test-app test:e2e",
11+
"lint": "pnpm -r /lint/",
12+
"format": "pnpm -r /format/",
13+
"test:visual": "pnpm docker:build && pnpm docker:e2e",
14+
"docker:build": "docker buildx build . --build-arg \"DOCKER_USER=$(id -u):$(id -g)\" -f dev.Dockerfile --tag spm-visual --load",
15+
"docker:e2e": "docker run -v \"$(pwd)/:/app\" -u $(id -u):$(id -g) -i --rm spm-visual pnpm -F test-app test:e2e"
2416
},
25-
"exports": {
26-
".": {
27-
"types": "./dist/index.d.ts",
28-
"svelte": "./dist/index.js"
29-
},
30-
"./*.css": {
31-
"import": "./dist/*.css",
32-
"require": "./dist/*.css"
33-
}
34-
},
35-
"files": [
36-
"dist",
37-
"!dist/**/*.test.*",
38-
"!dist/**/_*.*"
39-
],
4017
"engines": {
4118
"node": ">=16"
4219
},
43-
"pnpm": {
44-
"packageManager": "pnpm@^9.7.0"
45-
},
46-
"dependencies": {
47-
"deepmerge": "^4.3.0",
48-
"focus-trap": "^7.3.1"
49-
},
50-
"peerDependencies": {
51-
"svelte": "^3.54.0 || ^4.0.0 || ^5.0.0"
52-
},
5320
"devDependencies": {
54-
"@playwright/experimental-ct-svelte": "1.40.1",
55-
"@playwright/test": "1.40.1",
56-
"@release-it-plugins/lerna-changelog": "^6.1.0",
57-
"@sveltejs/adapter-auto": "^3.0.0",
58-
"@sveltejs/adapter-static": "^3.0.0",
59-
"@sveltejs/kit": "^2.0.0",
60-
"@sveltejs/package": "^2.0.0",
61-
"@sveltejs/vite-plugin-svelte": "^3.0.0",
62-
"@testing-library/dom": "^9.0.0",
63-
"@testing-library/jest-dom": "^6.0.0",
64-
"@testing-library/svelte": "^5.2.6",
65-
"@testing-library/user-event": "^14.4.3",
66-
"@types/prismjs": "^1.26.3",
67-
"@types/testing-library__jest-dom": "^5.14.5",
68-
"@typescript-eslint/eslint-plugin": "^6.0.0",
69-
"@typescript-eslint/parser": "^6.0.0",
70-
"@vitest/coverage-c8": "^0.33.0",
71-
"dedent": "^1.5.1",
72-
"eslint": "^8.28.0",
73-
"eslint-config-prettier": "^9.0.0",
74-
"eslint-plugin-prettier": "^5.0.0",
75-
"eslint-plugin-simple-import-sort": "^12.0.0",
76-
"eslint-plugin-svelte": "^2.32.4",
77-
"jest": "^29.4.3",
78-
"jsdom": "^24.0.0",
79-
"prettier": "^3.0.0",
80-
"prettier-plugin-svelte": "^3.0.0",
81-
"prism-svelte": "^0.5.0",
82-
"prismjs": "^1.29.0",
83-
"publint": "^0.2.0",
84-
"release-it": "^17.0.1",
85-
"sinon": "^17.0.0",
86-
"svelte": "^4.0.5",
87-
"svelte-check": "^3.4.3",
88-
"tslib": "^2.4.1",
89-
"typescript": "^5.0.0",
90-
"vite": "^5.0.0",
91-
"vitest": "^1.0.0"
21+
"playwright": "^1.53.0"
9222
},
93-
"svelte": "./dist/index.js",
94-
"types": "./dist/index.d.ts",
95-
"type": "module"
23+
"packageManager": "[email protected]"
9624
}

playwright-ct.config.ts

Lines changed: 0 additions & 57 deletions
This file was deleted.

playwright/index.html

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)