Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: testing-library/svelte-testing-library
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v5.2.7
Choose a base ref
...
head repository: testing-library/svelte-testing-library
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v5.2.8
Choose a head ref
  • 6 commits
  • 57 files changed
  • 1 contributor

Commits on May 7, 2025

  1. test: replace deprecated toMatchTypeOf (#434)

    mcous authored May 7, 2025

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    b2005b7 View commit details
  2. test: extract tests directory out of src (#433)

    mcous authored May 7, 2025

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    ea37c47 View commit details
  3. ci: expand matrix to include Node 22 (#435)

    mcous authored May 7, 2025

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    6096f05 View commit details

Commits on May 9, 2025

  1. ci: use specific dependencies for different Svelte/Node versions (#436)

    mcous authored May 9, 2025

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    f1fb8dd View commit details
  2. style: update to ESLint v9 and rework lint config (#438)

    mcous authored May 9, 2025

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    1aa3701 View commit details

Commits on May 19, 2025

  1. fix: configure dom-testing-library to flush Svelte changes (#439)

    mcous authored May 19, 2025

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    492dbd1 View commit details
Showing with 550 additions and 326 deletions.
  1. +0 −6 .eslintignore
  2. +0 −45 .eslintrc.cjs
  3. +0 −9 .github/dependabot.yml
  4. +17 −15 .github/workflows/release.yml
  5. +1 −0 .npmrc
  6. +0 −3 .prettierignore
  7. +0 −9 .prettierrc.yaml
  8. +10 −10 CONTRIBUTING.md
  9. +34 −0 README.md
  10. +95 −0 eslint.config.js
  11. +8 −6 jest.config.js
  12. +30 −35 package.json
  13. +14 −0 prettier.config.js
  14. +0 −3 scripts/changed-files
  15. +24 −20 scripts/install-dependencies
  16. +0 −9 src/__tests__/_jest-setup.js
  17. +0 −32 src/__tests__/events.test.js
  18. +1 −1 src/component-types.d.ts
  19. +3 −11 src/core/index.js
  20. +16 −9 src/index.js
  21. +53 −23 src/pure.js
  22. +7 −5 src/vite.js
  23. +9 −5 src/vitest.js
  24. +1 −1 src/__tests__/utils.js → tests/_env.js
  25. +1 −0 tests/_jest-setup.js
  26. +2 −1 {src/__tests__ → tests}/_jest-vitest-alias.js
  27. 0 {src/__tests__ → tests}/_vitest-setup.js
  28. +17 −6 {src/__tests__ → tests}/act.test.js
  29. +7 −3 {src/__tests__ → tests}/auto-cleanup.test.js
  30. 0 {src/__tests__ → tests}/cleanup.test.js
  31. +3 −3 {src/__tests__ → tests}/context.test.js
  32. 0 {src/__tests__ → tests}/debug.test.js
  33. +24 −0 tests/envs/svelte3/node16/package.json
  34. +24 −0 tests/envs/svelte3/package.json
  35. +24 −0 tests/envs/svelte4/node16/package.json
  36. +24 −0 tests/envs/svelte4/package.json
  37. +44 −0 tests/events.test.js
  38. 0 {src/__tests__ → tests}/fixtures/Comp.svelte
  39. 0 {src/__tests__ → tests}/fixtures/CompRunes.svelte
  40. 0 {src/__tests__ → tests}/fixtures/Context.svelte
  41. 0 {src/__tests__ → tests}/fixtures/Mounter.svelte
  42. 0 {src/__tests__ → tests}/fixtures/Transitioner.svelte
  43. +1 −1 {src/__tests__ → tests}/fixtures/Typed.svelte
  44. +1 −1 {src/__tests__ → tests}/fixtures/TypedRunes.svelte
  45. 0 {src/__tests__ → tests}/mount.test.js
  46. 0 {src/__tests__ → tests}/multi-base.test.js
  47. +3 −3 {src/__tests__ → tests}/render-runes.test-d.ts
  48. +8 −8 {src/__tests__ → tests}/render-utilities.test-d.ts
  49. +2 −2 {src/__tests__ → tests}/render.test-d.ts
  50. +13 −16 {src/__tests__ → tests}/render.test.js
  51. +3 −3 {src/__tests__ → tests}/rerender.test.js
  52. +8 −7 {src/__tests__ → tests}/transition.test.js
  53. +2 −2 {src/__tests__ → tests}/vite-plugin.test.js
  54. +1 −1 tsconfig.build.json
  55. +7 −2 tsconfig.json
  56. +3 −3 tsconfig.legacy.json
  57. +5 −7 vite.config.js
6 changes: 0 additions & 6 deletions .eslintignore

This file was deleted.

45 changes: 0 additions & 45 deletions .eslintrc.cjs

This file was deleted.

9 changes: 0 additions & 9 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -23,15 +23,6 @@ updates:
development:
dependency-type: 'development'

# TODO(mcous, 2024-04-30): update to ESLint v9 + flat config
ignore:
- dependency-name: 'eslint'
versions: ['>=9']
- dependency-name: 'eslint-plugin-n'
versions: ['>=17']
- dependency-name: 'eslint-plugin-promise'
versions: ['>=7']

# Update GitHub Actions dependencies
- package-ecosystem: 'github-actions'
directory: '/'
32 changes: 17 additions & 15 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ jobs:
main:
# ignore all-contributors PRs
if: ${{ !contains(github.head_ref, 'all-contributors') }}
name: Node ${{ matrix.node }}, Svelte ${{ matrix.svelte }}, ${{ matrix.check }}
name: Svelte ${{ matrix.svelte }}, Node ${{ matrix.node }}, ${{ matrix.check }}
runs-on: ubuntu-latest

# enable OIDC for codecov uploads
@@ -27,20 +27,22 @@ jobs:
strategy:
fail-fast: false
matrix:
node: ['16', '18', '20']
svelte: ['3', '4']
node: ['16', '18', '20', '22']
svelte: ['3', '4', '5']
check: ['test:vitest:jsdom', 'test:vitest:happy-dom', 'test:jest']
exclude:
# Don't run Svelte 3 on Node versions greater than 20
- { svelte: '3', node: '22' }
# Only run Svelte 5 on Node versions greater than or equal to 20
- { svelte: '5', node: '16' }
- { svelte: '5', node: '18' }
include:
# We only need to lint once, so do it on latest Node and Svelte
- { node: '20', svelte: '4', check: 'lint' }
# Run type checks in latest node
- { node: '20', svelte: '3', check: 'types:legacy' }
- { node: '20', svelte: '4', check: 'types:legacy' }
- { node: '20', svelte: '5', check: 'types' }
# Only run Svelte 5 checks on latest Node
- { node: '20', svelte: '5', check: 'test:vitest:jsdom' }
- { node: '20', svelte: '5', check: 'test:vitest:happy-dom' }
- { node: '20', svelte: '5', check: 'test:jest' }
- { svelte: '5', node: '22', check: 'lint' }
# Run type checks in latest applicable Node
- { svelte: '3', node: '20', check: 'types:legacy' }
- { svelte: '4', node: '22', check: 'types:legacy' }
- { svelte: '5', node: '22', check: 'types' }

steps:
- name: ⬇️ Checkout repo
@@ -73,10 +75,10 @@ jobs:
- name: ⎔ Setup node
uses: actions/setup-node@v4
with:
node-version: 20
node-version: 22

- name: 📥 Download deps
run: npm install --no-package-lock
run: npm install

- name: 🏗️ Build types
run: npm run build
@@ -100,7 +102,7 @@ jobs:
- name: ⎔ Setup node
uses: actions/setup-node@v4
with:
node-version: 20
node-version: 22

- name: 📥 Downloads types build
uses: actions/download-artifact@v4
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
package-lock=false
engine-strict=true
3 changes: 0 additions & 3 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
scripts/*
.eslintignore
.prettierignore
.all-contributorsrc
9 changes: 0 additions & 9 deletions .prettierrc.yaml

This file was deleted.

20 changes: 10 additions & 10 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -28,25 +28,24 @@ npm run preview-release

## Development setup

After cloning the repository, install the project's dependencies and run the `validate` script to run all checks and tests to verify your setup.
After cloning the repository, use the `setup` script to install dependencies and run all checks:

```shell
npm install # or `pnpm install`, or `yarn install`, etc.
npm run validate
npm run setup
```

### Lint and format

Run auto-formatting to ensure any changes adhere to the code style of the repository:

```shell
npm run format:delta
npm run format
```

To run lint and format checks without making any changes:

```shell
npm run lint:delta
npm run lint
```

### Test
@@ -63,18 +62,19 @@ npm run test:watch
Use the provided script to set up your environment for different versions of Svelte:

```shell
# install Svelte 5
# Svelte 5
npm run install:5
npm run all

# install Svelte 4
# Svelte 4
npm run install:4
npm run all:legacy

# install Svelte 3
# Svelte 3
npm run install:3
npm run all:legacy
```

Not all checks will pass on `svelte<5`. Reference the CI workflows to see which checks are expected to pass on older versions.

### Docs

Use the `toc` script to ensure the README's table of contents is up to date:
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -70,6 +70,7 @@
- [This Solution](#this-solution)
- [Installation](#installation)
- [Setup](#setup)
- [Auto-cleanup](#auto-cleanup)
- [Docs](#docs)
- [Issues](#issues)
- [🐛 Bugs](#-bugs)
@@ -140,6 +141,39 @@ test runners like Jest.
[vitest]: https://vitest.dev/
[setup docs]: https://testing-library.com/docs/svelte-testing-library/setup

### Auto-cleanup

In Vitest (via the `svelteTesting` plugin) and Jest (via the `beforeEach` and `afterEach` globals),
this library will automatically setup and cleanup the test environment before and after each test.

To do your own cleanup, or if you're using another framework, call the `setup` and `cleanup` functions yourself:

```js
import { cleanup, render, setup } from '@testing-library/svelte'

// before
setup()

// test
render(/* ... */)

// after
cleanup()
```

To disable auto-cleanup in Vitest, set the `autoCleanup` option of the plugin to false:

```js
svelteTesting({ autoCleanup: false })
```

To disable auto-cleanup in Jest and other frameworks with global test hooks,
set the `STL_SKIP_AUTO_CLEANUP` environment variable:

```shell
STL_SKIP_AUTO_CLEANUP=1 jest
```

## Docs

See the [**docs**][stl-docs] over at the Testing Library website.
95 changes: 95 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import js from '@eslint/js'
import eslintPluginVitest from '@vitest/eslint-plugin'
import eslintConfigPrettier from 'eslint-config-prettier'
import eslintPluginJestDom from 'eslint-plugin-jest-dom'
import eslintPluginPromise from 'eslint-plugin-promise'
import eslintPluginSimpleImportSort from 'eslint-plugin-simple-import-sort'
import eslintPluginSvelte from 'eslint-plugin-svelte'
import eslintPluginTestingLibrary from 'eslint-plugin-testing-library'
import eslintPluginUnicorn from 'eslint-plugin-unicorn'
import globals from 'globals'
import tseslint from 'typescript-eslint'

export default tseslint.config(
js.configs.recommended,
tseslint.configs.strict,
tseslint.configs.stylistic,
eslintPluginUnicorn.configs['flat/recommended'],
eslintPluginPromise.configs['flat/recommended'],
eslintPluginSvelte.configs['flat/recommended'],
eslintPluginSvelte.configs['flat/prettier'],
eslintConfigPrettier,
{
name: 'settings',
languageOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
parserOptions: {
parser: tseslint.parser,
extraFileExtensions: ['.svelte'],
},
globals: {
...globals.browser,
...globals.node,
...globals.jest,
},
},
},
{
name: 'ignores',
ignores: ['coverage', 'types'],
},
{
name: 'simple-import-sort',
plugins: {
'simple-import-sort': eslintPluginSimpleImportSort,
},
rules: {
'simple-import-sort/imports': 'error',
'simple-import-sort/exports': 'error',
},
},
{
name: 'tests',
files: ['**/*.test.js'],
extends: [
eslintPluginVitest.configs.recommended,
eslintPluginJestDom.configs['flat/recommended'],
eslintPluginTestingLibrary.configs['flat/dom'],
],
rules: {
'testing-library/no-node-access': [
'error',
{ allowContainerFirstChild: true },
],
},
},
{
name: 'extras',
rules: {
'unicorn/prevent-abbreviations': 'off',
},
},
{
name: 'svelte-extras',
files: ['**/*.svelte'],
rules: {
'svelte/no-unused-svelte-ignore': 'off',
'unicorn/filename-case': ['error', { case: 'pascalCase' }],
'unicorn/no-useless-undefined': 'off',
},
},
{
name: 'ts-extras',
files: ['**/*.ts'],
extends: [
tseslint.configs.strictTypeChecked,
tseslint.configs.stylisticTypeChecked,
],
languageOptions: {
parserOptions: {
projectService: true,
},
},
}
)
14 changes: 8 additions & 6 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
import { VERSION as SVELTE_VERSION } from 'svelte/compiler'

const SVELTE_TRANSFORM_PATTERN =
SVELTE_VERSION >= '5' ? '^.+\\.svelte(?:\\.js)?$' : '^.+\\.svelte$'
SVELTE_VERSION >= '5'
? String.raw`^.+\.svelte(?:\.js)?$`
: String.raw`^.+\.svelte$`

export default {
testMatch: ['<rootDir>/src/__tests__/**/*.test.js'],
testMatch: ['<rootDir>/tests/**/*.test.js'],
transform: {
[SVELTE_TRANSFORM_PATTERN]: 'svelte-jester',
},
moduleFileExtensions: ['js', 'svelte'],
extensionsToTreatAsEsm: ['.svelte'],
testEnvironment: 'jsdom',
setupFilesAfterEnv: ['<rootDir>/src/__tests__/_jest-setup.js'],
injectGlobals: false,
setupFilesAfterEnv: ['<rootDir>/tests/_jest-setup.js'],
injectGlobals: true,
moduleNameMapper: {
'^vitest$': '<rootDir>/src/__tests__/_jest-vitest-alias.js',
'^vitest$': '<rootDir>/tests/_jest-vitest-alias.js',
[String.raw`^@testing-library\/svelte$`]: '<rootDir>/src/index.js',
},
resetMocks: true,
restoreMocks: true,
collectCoverageFrom: ['<rootDir>/src/**/*'],
coveragePathIgnorePatterns: [
'/__tests__/',
'<rootDir>/src/vite.js',
'<rootDir>/src/vitest.js',
],
Loading