From 48ecc0b19f3cefcba73470ffc3c347be4348c07c Mon Sep 17 00:00:00 2001 From: Michael Cousins Date: Sat, 27 Jul 2024 11:56:57 -0400 Subject: [PATCH 1/4] ci: simplify main CI workflow matrix configuration (#393) --- .eslintrc.cjs | 10 ++------- .github/workflows/release.yml | 37 ++++++++++++-------------------- package.json | 40 +++++++++++++++++------------------ 3 files changed, 36 insertions(+), 51 deletions(-) diff --git a/.eslintrc.cjs b/.eslintrc.cjs index f403dca..5bb87a1 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -3,14 +3,8 @@ module.exports = { env: { browser: true, es6: true, - 'vitest-globals/env': true, }, - extends: [ - 'standard', - 'plugin:vitest-globals/recommended', - 'plugin:svelte/recommended', - 'prettier', - ], + extends: ['standard', 'plugin:svelte/recommended', 'prettier'], plugins: ['svelte', 'simple-import-sort', 'json-files'], rules: { 'simple-import-sort/imports': 'error', @@ -51,6 +45,6 @@ module.exports = { ecmaVersion: 2022, sourceType: 'module', }, - globals: { $state: 'readonly', $props: 'readonly' }, + globals: { afterEach: 'readonly', $state: 'readonly', $props: 'readonly' }, ignorePatterns: ['!/.*'], } diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7b7ca01..9dbf325 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -17,9 +17,8 @@ jobs: main: # ignore all-contributors PRs if: ${{ !contains(github.head_ref, 'all-contributors') }} - name: Node ${{ matrix.node }}, Svelte ${{ matrix.svelte }}, ${{ matrix.test-runner }} + name: Node ${{ matrix.node }}, Svelte ${{ matrix.svelte }}, ${{ matrix.check }} runs-on: ubuntu-latest - continue-on-error: ${{ matrix.experimental }} # enable OIDC for codecov uploads permissions: @@ -30,21 +29,17 @@ jobs: matrix: node: ['16', '18', '20'] svelte: ['3', '4'] - test-runner: ['vitest:jsdom', 'vitest:happy-dom', 'jest'] - experimental: [false] + check: ['test:vitest:jsdom', 'test:vitest:happy-dom', 'test:jest'] include: - - node: '20' - svelte: 'next' - test-runner: 'vitest:jsdom' - experimental: true - - node: '20' - svelte: 'next' - test-runner: 'vitest:happy-dom' - experimental: true - - node: '20' - svelte: 'next' - test-runner: 'jest' - experimental: true + # We only need to lint once, so do it on latest Node and Svelte + - { node: '20', svelte: '4', check: 'lint' } + # `SvelteComponent` is not generic in Svelte 3, so type-checking only passes in >= 4 + - { node: '20', svelte: '4', check: 'types' } + - { node: '20', svelte: 'next', check: 'types' } + # Only run Svelte 5 checks on latest Node + - { node: '20', svelte: 'next', check: 'test:vitest:jsdom' } + - { node: '20', svelte: 'next', check: 'test:vitest:happy-dom' } + - { node: '20', svelte: 'next', check: 'test:jest' } steps: - name: ⬇️ Checkout repo @@ -60,15 +55,11 @@ jobs: npm install --no-package-lock npm install --no-save svelte@${{ matrix.svelte }} - - name: ▶️ Run tests - run: npm run test:${{ matrix.test-runner }} - - - name: ▶️ Run type-checks - # NOTE: `SvelteComponent` is not generic in Svelte v3, so type-checking will not pass - if: ${{ matrix.node == '20' && matrix.svelte != '3' && matrix.test-runner == 'vitest:jsdom' }} - run: npm run types + - name: ▶️ Run ${{ matrix.check }} + run: npm run ${{ matrix.check }} - name: ⬆️ Upload coverage report + if: ${{ startsWith(matrix.check, 'test:') }} uses: codecov/codecov-action@v4 with: use_oidc: true diff --git a/package.json b/package.json index c4924f5..15fcd34 100644 --- a/package.json +++ b/package.json @@ -53,6 +53,7 @@ "!__tests__" ], "scripts": { + "all": "npm-run-all contributors:generate toc format types build test:vitest:* test:jest", "toc": "doctoc README.md", "lint": "prettier . --check && eslint .", "lint:delta": "npm-run-all -p prettier:delta eslint:delta", @@ -62,7 +63,7 @@ "format:delta": "npm-run-all format:prettier:delta format:eslint:delta", "format:prettier:delta": "prettier --write `./scripts/changed-files`", "format:eslint:delta": "eslint --fix `./scripts/changed-files`", - "setup": "npm install && npm run validate", + "setup": "npm install && npm run all", "test": "vitest run --coverage", "test:watch": "vitest", "test:vitest:jsdom": "vitest run --coverage --environment jsdom", @@ -96,34 +97,33 @@ "@sveltejs/vite-plugin-svelte": "^3.1.1", "@testing-library/jest-dom": "^6.3.0", "@testing-library/user-event": "^14.5.2", - "@typescript-eslint/eslint-plugin": "7.15.0", - "@typescript-eslint/parser": "7.15.0", - "@vitest/coverage-v8": "^1.5.2", + "@typescript-eslint/eslint-plugin": "^7.16.0", + "@typescript-eslint/parser": "^7.16.0", + "@vitest/coverage-v8": "^2.0.2", "all-contributors-cli": "^6.26.1", "doctoc": "^2.2.1", - "eslint": "8.57.0", - "eslint-config-prettier": "9.1.0", - "eslint-config-standard": "17.1.0", - "eslint-plugin-import": "2.29.1", + "eslint": "^8.57.0", + "eslint-config-prettier": "^9.1.0", + "eslint-config-standard": "^17.1.0", + "eslint-plugin-import": "^2.29.1", "eslint-plugin-json-files": "^4.1.0", - "eslint-plugin-n": "16.6.2", - "eslint-plugin-promise": "6.4.0", - "eslint-plugin-simple-import-sort": "12.1.0", - "eslint-plugin-svelte": "2.41.0", - "eslint-plugin-vitest-globals": "1.5.0", + "eslint-plugin-n": "^16.6.2", + "eslint-plugin-promise": "^6.4.0", + "eslint-plugin-simple-import-sort": "^12.1.1", + "eslint-plugin-svelte": "^2.42.0", "expect-type": "^0.19.0", - "happy-dom": "^14.7.1", + "happy-dom": "^14.12.3", "jest": "^29.7.0", "jest-environment-jsdom": "^29.7.0", "jsdom": "^24.0.0", "npm-run-all": "^4.1.5", - "prettier": "3.3.2", - "prettier-plugin-svelte": "3.2.5", + "prettier": "^3.3.3", + "prettier-plugin-svelte": "^3.2.5", "svelte": "^3 || ^4 || ^5 || ^5.0.0-next.0", - "svelte-check": "^3.6.3", + "svelte-check": "^3.8.4", "svelte-jester": "^5.0.0", - "typescript": "^5.3.3", - "vite": "^5.1.1", - "vitest": "^1.5.2" + "typescript": "^5.5.3", + "vite": "^5.3.3", + "vitest": "^2.0.2" } } From 574c1e43d50bda29b599195d72ddfe0e0634b40e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 3 Aug 2024 07:48:47 -0400 Subject: [PATCH 2/4] chore(deps-dev): bump the lint group with 2 updates (#397) * chore(deps-dev): bump the lint group with 2 updates Bumps the lint group with 2 updates: [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/eslint-plugin) and [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/parser). Updates `@typescript-eslint/eslint-plugin` from 7.18.0 to 8.0.0 - [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases) - [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/CHANGELOG.md) - [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v8.0.0/packages/eslint-plugin) Updates `@typescript-eslint/parser` from 7.18.0 to 8.0.0 - [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases) - [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/parser/CHANGELOG.md) - [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v8.0.0/packages/parser) --- updated-dependencies: - dependency-name: "@typescript-eslint/eslint-plugin" dependency-type: direct:development update-type: version-update:semver-major dependency-group: lint - dependency-name: "@typescript-eslint/parser" dependency-type: direct:development update-type: version-update:semver-major dependency-group: lint ... Signed-off-by: dependabot[bot] Co-authored-by: Michael Cousins --- .eslintrc.cjs | 10 +--------- .github/dependabot.yml | 2 ++ package.json | 5 ++--- src/__tests__/types.test-d.ts | 1 + 4 files changed, 6 insertions(+), 12 deletions(-) diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 5bb87a1..91f6920 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -5,7 +5,7 @@ module.exports = { es6: true, }, extends: ['standard', 'plugin:svelte/recommended', 'prettier'], - plugins: ['svelte', 'simple-import-sort', 'json-files'], + plugins: ['svelte', 'simple-import-sort'], rules: { 'simple-import-sort/imports': 'error', 'simple-import-sort/exports': 'error', @@ -31,14 +31,6 @@ module.exports = { 'plugin:@typescript-eslint/stylistic', 'prettier', ], - rules: { - '@typescript-eslint/ban-types': [ - 'error', - { types: { '{}': false }, extendDefaults: true }, - ], - '@typescript-eslint/no-explicit-any': 'off', - 'import/export': 'off', - }, }, ], parserOptions: { diff --git a/.github/dependabot.yml b/.github/dependabot.yml index d4a16b5..c9eb8a7 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -29,6 +29,8 @@ updates: versions: ['>=9'] - dependency-name: 'eslint-plugin-n' versions: ['>=17'] + - dependency-name: 'eslint-plugin-promise' + versions: ['>=7'] # Update GitHub Actions dependencies - package-ecosystem: 'github-actions' diff --git a/package.json b/package.json index 15fcd34..6581340 100644 --- a/package.json +++ b/package.json @@ -97,8 +97,8 @@ "@sveltejs/vite-plugin-svelte": "^3.1.1", "@testing-library/jest-dom": "^6.3.0", "@testing-library/user-event": "^14.5.2", - "@typescript-eslint/eslint-plugin": "^7.16.0", - "@typescript-eslint/parser": "^7.16.0", + "@typescript-eslint/eslint-plugin": "^8.0.0", + "@typescript-eslint/parser": "^8.0.0", "@vitest/coverage-v8": "^2.0.2", "all-contributors-cli": "^6.26.1", "doctoc": "^2.2.1", @@ -106,7 +106,6 @@ "eslint-config-prettier": "^9.1.0", "eslint-config-standard": "^17.1.0", "eslint-plugin-import": "^2.29.1", - "eslint-plugin-json-files": "^4.1.0", "eslint-plugin-n": "^16.6.2", "eslint-plugin-promise": "^6.4.0", "eslint-plugin-simple-import-sort": "^12.1.1", diff --git a/src/__tests__/types.test-d.ts b/src/__tests__/types.test-d.ts index 9927a05..077bbcd 100644 --- a/src/__tests__/types.test-d.ts +++ b/src/__tests__/types.test-d.ts @@ -90,6 +90,7 @@ describe('types', () => { expectTypeOf(subject.fireEvent.click).toMatchTypeOf< ( element: Element | Node | Document | Window, + // eslint-disable-next-line @typescript-eslint/no-empty-object-type options?: {} ) => Promise >() From 2cf781c3731009e7cd250891e1e7a2393910720c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 1 Sep 2024 22:40:26 -0400 Subject: [PATCH 3/4] chore(deps-dev): bump the test group with 3 updates (#399) Bumps the test group with 3 updates: [expect-type](https://github.com/mmkal/expect-type), [happy-dom](https://github.com/capricorn86/happy-dom) and [jsdom](https://github.com/jsdom/jsdom). Updates `expect-type` from 0.19.0 to 0.20.0 - [Release notes](https://github.com/mmkal/expect-type/releases) - [Commits](https://github.com/mmkal/expect-type/compare/0.19.0...v0.20.0) Updates `happy-dom` from 14.12.3 to 15.7.3 - [Release notes](https://github.com/capricorn86/happy-dom/releases) - [Commits](https://github.com/capricorn86/happy-dom/compare/v14.12.3...v15.7.3) Updates `jsdom` from 24.1.3 to 25.0.0 - [Release notes](https://github.com/jsdom/jsdom/releases) - [Changelog](https://github.com/jsdom/jsdom/blob/main/Changelog.md) - [Commits](https://github.com/jsdom/jsdom/compare/24.1.3...25.0.0) --- updated-dependencies: - dependency-name: expect-type dependency-type: direct:development update-type: version-update:semver-minor dependency-group: test - dependency-name: happy-dom dependency-type: direct:development update-type: version-update:semver-major dependency-group: test - dependency-name: jsdom dependency-type: direct:development update-type: version-update:semver-major dependency-group: test ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 6581340..3fbcde7 100644 --- a/package.json +++ b/package.json @@ -110,11 +110,11 @@ "eslint-plugin-promise": "^6.4.0", "eslint-plugin-simple-import-sort": "^12.1.1", "eslint-plugin-svelte": "^2.42.0", - "expect-type": "^0.19.0", - "happy-dom": "^14.12.3", + "expect-type": "^0.20.0", + "happy-dom": "^15.7.3", "jest": "^29.7.0", "jest-environment-jsdom": "^29.7.0", - "jsdom": "^24.0.0", + "jsdom": "^25.0.0", "npm-run-all": "^4.1.5", "prettier": "^3.3.3", "prettier-plugin-svelte": "^3.2.5", From 6f45a962bffc649ef77afcc6a456f8a39df8cb0f Mon Sep 17 00:00:00 2001 From: Michael Cousins Date: Tue, 1 Oct 2024 14:46:50 -0400 Subject: [PATCH 4/4] fix(svelte5): update typings to support new component types (#400) --- .github/workflows/release.yml | 2 +- package.json | 1 + src/__tests__/fixtures/Mounter.svelte | 2 +- .../fixtures/{Simple.svelte => Typed.svelte} | 2 + src/__tests__/fixtures/TypedRunes.svelte | 8 ++++ src/__tests__/render-runes.test-d.ts | 39 +++++++++++++++++ ...s.test-d.ts => render-utilities.test-d.ts} | 43 +++---------------- src/__tests__/render.test-d.ts | 39 +++++++++++++++++ src/component-types.d.ts | 43 +++++++++++++++++++ src/pure.js | 14 +++--- tsconfig.legacy.json | 8 ++++ 11 files changed, 154 insertions(+), 47 deletions(-) rename src/__tests__/fixtures/{Simple.svelte => Typed.svelte} (76%) create mode 100644 src/__tests__/fixtures/TypedRunes.svelte create mode 100644 src/__tests__/render-runes.test-d.ts rename src/__tests__/{types.test-d.ts => render-utilities.test-d.ts} (55%) create mode 100644 src/__tests__/render.test-d.ts create mode 100644 src/component-types.d.ts create mode 100644 tsconfig.legacy.json diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9dbf325..8b2ac4a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -34,7 +34,7 @@ jobs: # We only need to lint once, so do it on latest Node and Svelte - { node: '20', svelte: '4', check: 'lint' } # `SvelteComponent` is not generic in Svelte 3, so type-checking only passes in >= 4 - - { node: '20', svelte: '4', check: 'types' } + - { node: '20', svelte: '4', check: 'types:legacy' } - { node: '20', svelte: 'next', check: 'types' } # Only run Svelte 5 checks on latest Node - { node: '20', svelte: 'next', check: 'test:vitest:jsdom' } diff --git a/package.json b/package.json index 3fbcde7..e536ce0 100644 --- a/package.json +++ b/package.json @@ -70,6 +70,7 @@ "test:vitest:happy-dom": "vitest run --coverage --environment happy-dom", "test:jest": "npx --node-options=\"--experimental-vm-modules --no-warnings\" jest --coverage", "types": "svelte-check", + "types:legacy": "svelte-check --tsconfig tsconfig.legacy.json", "validate": "npm-run-all test:vitest:* test:jest types build", "build": "tsc -p tsconfig.build.json", "contributors:add": "all-contributors add", diff --git a/src/__tests__/fixtures/Mounter.svelte b/src/__tests__/fixtures/Mounter.svelte index 27205dd..68f72f9 100644 --- a/src/__tests__/fixtures/Mounter.svelte +++ b/src/__tests__/fixtures/Mounter.svelte @@ -16,4 +16,4 @@ }) - + diff --git a/src/__tests__/fixtures/Simple.svelte b/src/__tests__/fixtures/Typed.svelte similarity index 76% rename from src/__tests__/fixtures/Simple.svelte rename to src/__tests__/fixtures/Typed.svelte index c9c2f15..44960ab 100644 --- a/src/__tests__/fixtures/Simple.svelte +++ b/src/__tests__/fixtures/Typed.svelte @@ -1,6 +1,8 @@

hello {name}

diff --git a/src/__tests__/fixtures/TypedRunes.svelte b/src/__tests__/fixtures/TypedRunes.svelte new file mode 100644 index 0000000..979be41 --- /dev/null +++ b/src/__tests__/fixtures/TypedRunes.svelte @@ -0,0 +1,8 @@ + + +

hello {name}

+

count: {count}

diff --git a/src/__tests__/render-runes.test-d.ts b/src/__tests__/render-runes.test-d.ts new file mode 100644 index 0000000..2d0c69f --- /dev/null +++ b/src/__tests__/render-runes.test-d.ts @@ -0,0 +1,39 @@ +import { expectTypeOf } from 'expect-type' +import { describe, test } from 'vitest' + +import * as subject from '../index.js' +import Component from './fixtures/TypedRunes.svelte' + +describe('types', () => { + test('render is a function that accepts a Svelte component', () => { + subject.render(Component, { name: 'Alice', count: 42 }) + subject.render(Component, { props: { name: 'Alice', count: 42 } }) + }) + + test('rerender is a function that accepts partial props', async () => { + const { rerender } = subject.render(Component, { name: 'Alice', count: 42 }) + + await rerender({ name: 'Bob' }) + await rerender({ count: 0 }) + }) + + test('invalid prop types are rejected', () => { + // @ts-expect-error: name should be a string + subject.render(Component, { name: 42 }) + + // @ts-expect-error: name should be a string + subject.render(Component, { props: { name: 42 } }) + }) + + test('render result has container and component', () => { + const result = subject.render(Component, { name: 'Alice', count: 42 }) + + expectTypeOf(result).toMatchTypeOf<{ + container: HTMLElement + component: { hello: string } + debug: (el?: HTMLElement) => void + rerender: (props: { name?: string; count?: number }) => Promise + unmount: () => void + }>() + }) +}) diff --git a/src/__tests__/types.test-d.ts b/src/__tests__/render-utilities.test-d.ts similarity index 55% rename from src/__tests__/types.test-d.ts rename to src/__tests__/render-utilities.test-d.ts index 077bbcd..b45614e 100644 --- a/src/__tests__/types.test-d.ts +++ b/src/__tests__/render-utilities.test-d.ts @@ -1,45 +1,12 @@ import { expectTypeOf } from 'expect-type' -import type { ComponentProps, SvelteComponent } from 'svelte' import { describe, test } from 'vitest' import * as subject from '../index.js' -import Simple from './fixtures/Simple.svelte' - -describe('types', () => { - test('render is a function that accepts a Svelte component', () => { - subject.render(Simple, { name: 'Alice', count: 42 }) - subject.render(Simple, { props: { name: 'Alice', count: 42 } }) - }) - - test('rerender is a function that accepts partial props', async () => { - const { rerender } = subject.render(Simple, { name: 'Alice', count: 42 }) - - await rerender({ name: 'Bob' }) - await rerender({ count: 0 }) - }) - - test('invalid prop types are rejected', () => { - // @ts-expect-error: name should be a string - subject.render(Simple, { name: 42 }) - - // @ts-expect-error: name should be a string - subject.render(Simple, { props: { name: 42 } }) - }) - - test('render result has container and component', () => { - const result = subject.render(Simple, { name: 'Alice', count: 42 }) - - expectTypeOf(result).toMatchTypeOf<{ - container: HTMLElement - component: SvelteComponent<{ name: string }> - debug: (el?: HTMLElement) => void - rerender: (props: Partial>) => Promise - unmount: () => void - }>() - }) +import Component from './fixtures/Comp.svelte' +describe('render query and utility types', () => { test('render result has default queries', () => { - const result = subject.render(Simple, { name: 'Alice', count: 42 }) + const result = subject.render(Component, { name: 'Alice' }) expectTypeOf(result.getByRole).parameters.toMatchTypeOf< [role: subject.ByRoleMatcher, options?: subject.ByRoleOptions] @@ -55,8 +22,8 @@ describe('types', () => { () => '' ) const result = subject.render( - Simple, - { name: 'Alice', count: 42 }, + Component, + { name: 'Alice' }, { queries: { getByVibes } } ) diff --git a/src/__tests__/render.test-d.ts b/src/__tests__/render.test-d.ts new file mode 100644 index 0000000..f8d1d90 --- /dev/null +++ b/src/__tests__/render.test-d.ts @@ -0,0 +1,39 @@ +import { expectTypeOf } from 'expect-type' +import { describe, test } from 'vitest' + +import * as subject from '../index.js' +import Component from './fixtures/Typed.svelte' + +describe('types', () => { + test('render is a function that accepts a Svelte component', () => { + subject.render(Component, { name: 'Alice', count: 42 }) + subject.render(Component, { props: { name: 'Alice', count: 42 } }) + }) + + test('rerender is a function that accepts partial props', async () => { + const { rerender } = subject.render(Component, { name: 'Alice', count: 42 }) + + await rerender({ name: 'Bob' }) + await rerender({ count: 0 }) + }) + + test('invalid prop types are rejected', () => { + // @ts-expect-error: name should be a string + subject.render(Component, { name: 42 }) + + // @ts-expect-error: name should be a string + subject.render(Component, { props: { name: 42 } }) + }) + + test('render result has container and component', () => { + const result = subject.render(Component, { name: 'Alice', count: 42 }) + + expectTypeOf(result).toMatchTypeOf<{ + container: HTMLElement + component: { hello: string } + debug: (el?: HTMLElement) => void + rerender: (props: { name?: string; count?: number }) => Promise + unmount: () => void + }>() + }) +}) diff --git a/src/component-types.d.ts b/src/component-types.d.ts new file mode 100644 index 0000000..a349597 --- /dev/null +++ b/src/component-types.d.ts @@ -0,0 +1,43 @@ +import type * as Svelte from 'svelte' + +// eslint-disable-next-line @typescript-eslint/no-explicit-any +type IS_MODERN_SVELTE = any extends Svelte.Component ? false : true + +/** A compiled, imported Svelte component. */ +export type Component

= IS_MODERN_SVELTE extends true + ? Svelte.Component

| Svelte.SvelteComponent

+ : Svelte.SvelteComponent

+ +/** + * The type of an imported, compiled Svelte component. + * + * In Svelte 4, this was the Svelte component class' type. + * In Svelte 5, this distinction no longer matters. + */ +export type ComponentType = C extends Svelte.SvelteComponent + ? Svelte.ComponentType + : C + +/** The props of a component. */ +export type Props = Svelte.ComponentProps + +/** + * The exported fields of a component. + * + * In Svelte 4, this is simply the instance of the component class. + * In Svelte 5, this is the set of variables marked as `export`'d. + */ +export type Exports = C extends Svelte.SvelteComponent + ? C + : C extends Svelte.Component + ? E + : never + +/** + * Options that may be passed to `mount` when rendering the component. + * + * In Svelte 4, these are the options passed to the component constructor. + */ +export type MountOptions = IS_MODERN_SVELTE extends true + ? Parameters, Exports>>[1] + : Svelte.ComponentConstructorOptions> diff --git a/src/pure.js b/src/pure.js index edb94b3..875f87c 100644 --- a/src/pure.js +++ b/src/pure.js @@ -13,8 +13,8 @@ const componentCache = new Set() /** * Customize how Svelte renders the component. * - * @template {import('svelte').SvelteComponent} C - * @typedef {import('svelte').ComponentProps | Partial>>} SvelteComponentOptions + * @template {import('./component-types.js').Component} C + * @typedef {import('./component-types.js').Props | Partial>} SvelteComponentOptions */ /** @@ -30,15 +30,15 @@ const componentCache = new Set() /** * The rendered component and bound testing functions. * - * @template {import('svelte').SvelteComponent} C + * @template {import('./component-types.js').Component} C * @template {import('@testing-library/dom').Queries} [Q=typeof import('@testing-library/dom').queries] * * @typedef {{ * container: HTMLElement * baseElement: HTMLElement - * component: C + * component: import('./component-types.js').Exports * debug: (el?: HTMLElement | DocumentFragment) => void - * rerender: (props: Partial>) => Promise + * rerender: (props: Partial>) => Promise * unmount: () => void * } & { * [P in keyof Q]: import('@testing-library/dom').BoundFunction @@ -48,10 +48,10 @@ const componentCache = new Set() /** * Render a component into the document. * - * @template {import('svelte').SvelteComponent} C + * @template {import('./component-types.js').Component} C * @template {import('@testing-library/dom').Queries} [Q=typeof import('@testing-library/dom').queries] * - * @param {import('svelte').ComponentType} Component - The component to render. + * @param {import('./component-types.js').ComponentType} Component - The component to render. * @param {SvelteComponentOptions} options - Customize how Svelte renders the component. * @param {RenderOptions} renderOptions - Customize how Testing Library sets up the document and binds queries. * @returns {RenderResult} The rendered component and bound testing functions. diff --git a/tsconfig.legacy.json b/tsconfig.legacy.json new file mode 100644 index 0000000..b5d9e57 --- /dev/null +++ b/tsconfig.legacy.json @@ -0,0 +1,8 @@ +{ + "extends": ["./tsconfig.json"], + "exclude": [ + "src/__tests__/render-runes.test-d.ts", + "src/__tests__/fixtures/CompRunes.svelte", + "src/__tests__/fixtures/TypedRunes.svelte" + ] +}