-
Notifications
You must be signed in to change notification settings - Fork 79
feat: fixed test setup #240
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
Open
thejackshelton
wants to merge
20
commits into
kentcdodds:main
Choose a base branch
from
thejackshelton:pr/qwik-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 17 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
387348a
fix: test command
thejackshelton 8f1a866
initial qwik test
thejackshelton 1eca6ce
fix: type errors
thejackshelton 7a7a2bb
refactor: use h function
thejackshelton b88c19c
feat: use jsx function for the Qwik optimizer
thejackshelton b16efa0
refactor: simplify import
thejackshelton 5b2fb71
update package name
thejackshelton 1dac329
feat: use Qwik component instead of an inline component
thejackshelton fd98dcd
fix: mdx export
thejackshelton 3277303
refactor: jsdom and qwikloader
thejackshelton c69aae2
feat: use jsdom global to solve both the setup issues like vitest doe…
thejackshelton 8fa972f
feat: add jsdom global types
thejackshelton bbf8af3
feat: fix jsx runtime
thejackshelton 00ed04e
fix: handle qwik slotted content
thejackshelton f560118
feat: test passing
thejackshelton 25a537a
refactor: add v2 note
thejackshelton a3ab8bc
refactor: comment on output
thejackshelton 8ee6e66
refactor: remove qwik
thejackshelton 63a71a2
Update package.json
kentcdodds d0cd216
Update package.json
kentcdodds File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| /* eslint-disable react/no-unknown-property */ | ||
| /* eslint-disable react/react-in-jsx-scope */ | ||
| /** @jsxImportSource @builder.io/qwik */ | ||
|
|
||
| import * as Qwik from "@builder.io/qwik"; | ||
| import {suite} from 'uvu' | ||
| import * as assert from 'uvu/assert' | ||
| import { render } from '@noma.to/qwik-testing-library' | ||
| import {bundleMDX} from '../index.js' | ||
| import {getMDXComponent} from '../client/jsx.js'; | ||
|
|
||
| /** | ||
| * NOTE: Qwik v2 will change the package name from '@builder.io/qwik' to '@qwik.dev/core'. | ||
| * | ||
| * It's the Qwik team's responsibility to update the package name in the test once v2 has released. (Jack, a core team member has made the initial PR to this package, and will update this test once v2 has released.) | ||
| */ | ||
|
|
||
| const test = suite("qwik"); | ||
|
|
||
| const jsxBundlerConfig = { | ||
| jsxLib: { | ||
| varName: 'Qwik', | ||
| package: '@builder.io/qwik', | ||
| }, | ||
| jsxRuntime: { | ||
| varName: '_jsx_runtime', | ||
| package: '@builder.io/qwik/jsx-runtime', | ||
| }, | ||
| } | ||
|
|
||
| const jsxComponentConfig = { | ||
| Qwik, | ||
| _jsx_runtime: { | ||
| jsx: Qwik.jsx, | ||
| jsxs: Qwik.jsx, | ||
| Fragment: Qwik.Fragment | ||
| } | ||
| } | ||
|
|
||
| const mdxSource = ` | ||
| --- | ||
| title: Example Post | ||
| published: 2021-02-13 | ||
| description: This is some meta-data | ||
| --- | ||
| import { Demo } from './demo' | ||
|
|
||
| # This is the title | ||
|
|
||
| Here's a **neat** demo: | ||
| <Demo /> | ||
| `.trim(); | ||
|
|
||
| const demoTsx = ` | ||
| import { component$ } from '@builder.io/qwik' | ||
|
|
||
| export const Demo = component$(() => { | ||
| return <div>mdx-bundler with Qwik's runtime!</div> | ||
| }) | ||
| `.trim(); | ||
|
|
||
| test('smoke test for qwik', async () => { | ||
| const result = await bundleMDX({ | ||
| source: mdxSource, | ||
| jsxConfig: jsxBundlerConfig, | ||
| files: { | ||
| './demo.tsx': demoTsx | ||
| } | ||
| }); | ||
|
|
||
| /** | ||
| * @type {any} | ||
| */ | ||
| const Component = getMDXComponent(result.code, jsxComponentConfig) | ||
|
|
||
| /** @type {Qwik.Component<{}>} */ | ||
| const SpanBold = Qwik.component$(() => { | ||
| return Qwik.jsx('span', { class: "strong", children: Qwik.jsx(Qwik.Slot, { name: "" }) }) | ||
| }) | ||
|
|
||
| assert.equal(result.frontmatter, { | ||
| title: 'Example Post', | ||
| published: new Date('2021-02-13'), | ||
| description: 'This is some meta-data', | ||
| }) | ||
|
|
||
| const {container} = await render( | ||
| Qwik.jsx(Component, { components: { strong: SpanBold } }) | ||
| ) | ||
|
|
||
| /** | ||
| * Qwik v1 uses HTML comments as markers in its output for component boundaries and resumability. | ||
| * When Qwik v2 is released, the expected output will change to be more similar to other frameworks, | ||
| * but with distinctive dynamic and constant attributes (denoted by the ':' character). | ||
| * This test will need to be updated accordingly when migrating to v2. | ||
| */ | ||
|
|
||
| assert.equal( | ||
| container.innerHTML, | ||
| `<h1>This is the title</h1> | ||
| <p>Here's a <!--qv --><span class="strong"><!--qv q:key q:sref=0 q:s-->neat<!--/qv--></span><!--/qv--> demo:</p> | ||
| <!--qv --><div>mdx-bundler with Qwik's runtime!</div><!--/qv-->` | ||
| ) | ||
| }) | ||
|
|
||
| test.run() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would understand if we want to keep it that way, but to prevent having to update the test once we migrate to qwik V2, we could use queries to match the expected results instead of the raw inner html.
For example:
Or something along those lines.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah this should also work, since the v1 import is compatible in v2. I'll update this soon 🫡 . Appreciate the feedback!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually @ianlet I'm getting some linter issues from the react testing library that it's bad practice to not destructure here.
But when I try to use screen, it becomes hard to select the h1 for the qwik smoke test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah no worries! In any case, as we're testing the result of a transformation, it makes sense to expect the exact output. It's just that it makes this test more fragile and that we'll have to remember to come fix it as soon as Qwik internals change something (shouldn't happen often though).