-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add Marko example and include code coverage for Marko files (#4263
- Loading branch information
1 parent
5a741ca
commit eac7776
Showing
15 changed files
with
523 additions
and
1,248 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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,17 @@ | ||
export interface Input { | ||
count: number; | ||
} | ||
|
||
class { | ||
declare state: { times: number }; | ||
onCreate() { | ||
this.state = { times: 2 }; | ||
} | ||
} | ||
|
||
$ const { count } = input; | ||
$ const { times } = state; | ||
$ const result = count * times; | ||
|
||
<div>${count} x ${times} = ${result}</div> | ||
<button onClick(() => component.state.times++)>x1</button> |
This file contains 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,23 @@ | ||
{ | ||
"name": "@vitest/example-marko", | ||
"type": "module", | ||
"private": true, | ||
"scripts": { | ||
"test": "vitest", | ||
"test:ui": "vitest --ui", | ||
"coverage": "vitest run --coverage" | ||
}, | ||
"devDependencies": { | ||
"@marko/compiler": "latest", | ||
"@marko/testing-library": "latest", | ||
"@marko/vite": "latest", | ||
"@vitest/ui": "latest", | ||
"jsdom": "latest", | ||
"marko": "latest", | ||
"vite": "latest", | ||
"vitest": "latest" | ||
}, | ||
"stackblitz": { | ||
"startCommand": "npm run test:ui" | ||
} | ||
} |
This file contains 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,3 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`mount component 1`] = `"<div>4 x 2 = 8</div><button>x1</button>"`; |
This file contains 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,3 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`Hello.marko > mounts 1`] = `"<div>4 x 2 = 8</div><button>x1</button>"`; |
This file contains 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,31 @@ | ||
import Hello from '../components/Hello.marko' | ||
|
||
let host: HTMLElement | ||
|
||
afterEach(() => { | ||
host.remove() | ||
}) | ||
|
||
test('mount component', async () => { | ||
host = document.createElement('div') | ||
host.setAttribute('id', 'host') | ||
document.body.appendChild(host) | ||
const instance = Hello | ||
.renderSync({ count: 4 }) | ||
.appendTo(host) | ||
.getComponent() | ||
expect(instance).toBeTruthy() | ||
expect(host.innerHTML).toContain('4 x 2 = 8') | ||
expect(host.innerHTML).toMatchSnapshot() | ||
const btn = host.getElementsByTagName('button')[0] | ||
btn.click() // or btn.dispatchEvent(new window.Event('click', { bubbles: true })) | ||
await tick() | ||
expect(host.innerHTML).toContain('4 x 3 = 12') | ||
btn.click() | ||
await tick() | ||
expect(host.innerHTML).toContain('4 x 4 = 16') | ||
}) | ||
|
||
async function tick() { | ||
await new Promise(resolve => setTimeout(resolve)) | ||
} |
This file contains 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,21 @@ | ||
import { fireEvent, render, screen } from '@marko/testing-library' | ||
import Hello from '../components/Hello.marko' | ||
|
||
describe('Hello.marko', () => { | ||
it('mounts', async () => { | ||
const { container } = await render(Hello, { count: 4 }) | ||
expect(container).toBeTruthy() | ||
expect(container.innerHTML).toContain('4 x 2 = 8') | ||
expect(container.innerHTML).toMatchSnapshot() | ||
}) | ||
|
||
it('updates on button click', async () => { | ||
await render(Hello, { count: 4 }) | ||
const btn = screen.getByRole('button') | ||
const div = screen.getByText('4 x 2 = 8') | ||
await fireEvent.click(btn) | ||
expect(div.innerHTML).toBe('4 x 3 = 12') | ||
await fireEvent.click(btn) | ||
expect(div.innerHTML).toBe('4 x 4 = 16') | ||
}) | ||
}) |
This file contains 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,12 @@ | ||
import { defineConfig } from 'vite' | ||
import marko from '@marko/vite' | ||
|
||
export default defineConfig({ | ||
plugins: [ | ||
marko(), | ||
], | ||
test: { | ||
globals: true, | ||
environment: 'jsdom', | ||
}, | ||
}) |
This file contains 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 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
Oops, something went wrong.