Skip to content

Commit

Permalink
feat: use browser mode
Browse files Browse the repository at this point in the history
  • Loading branch information
LittleSound committed Nov 21, 2024
1 parent 0e915f7 commit 317da0e
Show file tree
Hide file tree
Showing 15 changed files with 666 additions and 230 deletions.
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@
"@types/node": "^20.16.10",
"@types/semver": "^7.5.8",
"@types/serve-handler": "^6.1.4",
"@vitest/coverage-v8": "^2.1.1",
"@vitest/ui": "^2.1.1",
"@vitest/browser": "^2.1.5",
"@vitest/coverage-v8": "^2.1.5",
"@vitest/ui": "^2.1.5",
"@vue/consolidate": "1.0.0",
"conventional-changelog-cli": "^5.0.0",
"enquirer": "^2.4.1",
Expand All @@ -90,6 +91,7 @@
"marked": "13.0.3",
"npm-run-all2": "^6.2.3",
"picocolors": "^1.1.0",
"playwright": "^1.49.0",
"prettier": "^3.3.3",
"pretty-bytes": "^6.1.1",
"pug": "^3.0.3",
Expand All @@ -108,7 +110,7 @@
"typescript": "~5.6.2",
"typescript-eslint": "^8.5.0",
"vite": "catalog:",
"vitest": "^2.1.1"
"vitest": "^2.1.5"
},
"pnpm": {
"peerDependencyRules": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ describe('vanilla', () => {
create(3)
;(rows().item(0)!.firstChild as HTMLElement)!.click()

expect(html()).toMatchFileSnapshot('./__snapshots__/create-list.html')
expect(document.body.innerHTML).toBe(`<div id="host">${html()}</div>`)
await expect(html()).toMatchFileSnapshot('./__snapshots__/create-list.html')
expect(document.body.innerHTML.trim()).toBe(
`<div id="host">${html()}</div>`,
)

options.teardown()

expect(document.body.innerHTML).toBe('')
expect(document.body.innerHTML.trim()).toBe('')
})
it('shoud work with 1000 items', async () => {
const { html, ctx, options } = createListAppOnVanilla()
Expand All @@ -29,10 +31,12 @@ describe('vanilla', () => {
;(items.item(0)!.firstChild as HTMLElement)!.click()

expect(items.length).toBe(1000)
expect(document.body.innerHTML).toBe(`<div id="host">${html()}</div>`)
expect(document.body.innerHTML.trim()).toBe(
`<div id="host">${html()}</div>`,
)

options.teardown()

expect(document.body.innerHTML).toBe('')
expect(document.body.innerHTML.trim()).toBe('')
})
})
4 changes: 2 additions & 2 deletions packages/runtime-vapor/__benchmarks__/_runtimes/vanilla.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { BenchOptions } from 'vitest'
import { basicOptions } from '../_utils'

export function createListAppOnVanilla({
initHost = (): HTMLDivElement => {
Expand Down Expand Up @@ -37,8 +38,7 @@ export function createListAppOnVanilla({
}

const options = {
warmupIterations: 5,
iterations: 20,
...basicOptions,
setup: handleSetup,
teardown: handleTeardown,
} satisfies BenchOptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ describe('vapor-ref', () => {

await wait()

expect(html()).toMatchFileSnapshot('./__snapshots__/create-list.html')
expect(document.body.innerHTML).toBe(
await expect(html()).toMatchFileSnapshot('./__snapshots__/create-list.html')
expect(document.body.innerHTML.trim()).toBe(
`<div id="host" data-v-app="">${html()}</div>`,
)

options.teardown()

expect(document.body.innerHTML).toBe('')
expect(document.body.innerHTML.trim()).toBe('')
})
it('shoud work with 1000 items', async () => {
const { html, ctx, options, wait } = createListAppWithRef()
Expand All @@ -40,12 +40,12 @@ describe('vapor-ref', () => {
let count = 0
html().replaceAll('</a></td></tr>', v => (++count, v))
expect(count).toBe(1000)
expect(document.body.innerHTML).toBe(
expect(document.body.innerHTML.trim()).toBe(
`<div id="host" data-v-app="">${html()}</div>`,
)

options.teardown()

expect(document.body.innerHTML).toBe('')
expect(document.body.innerHTML.trim()).toBe('')
})
})
4 changes: 2 additions & 2 deletions packages/runtime-vapor/__benchmarks__/_runtimes/vapor-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
setText,
template,
} from '../../src'
import { basicOptions } from '../_utils'

export function createListAppWithRef({
initHost = (): HTMLDivElement => {
Expand Down Expand Up @@ -95,8 +96,7 @@ export function createListAppWithRef({
})

const options = {
warmupIterations: 5,
iterations: 20,
...basicOptions,
setup: handleSetup,
teardown: handleTeardown,
} satisfies BenchOptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ describe('vapor-shallow-ref', () => {

await wait()

expect(html()).toMatchFileSnapshot('./__snapshots__/create-list.html')
expect(document.body.innerHTML).toBe(
await expect(html()).toMatchFileSnapshot('./__snapshots__/create-list.html')
expect(document.body.innerHTML.trim()).toBe(
`<div id="host" data-v-app="">${html()}</div>`,
)

options.teardown()

expect(document.body.innerHTML).toBe('')
expect(document.body.innerHTML.trim()).toBe('')
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
shallowRef,
template,
} from '../../src'
import { basicOptions } from '../_utils'

export function createListAppWithShallowRef({
initHost = (): HTMLDivElement => {
Expand Down Expand Up @@ -96,8 +97,7 @@ export function createListAppWithShallowRef({
})

const options = {
warmupIterations: 5,
iterations: 20,
...basicOptions,
setup: handleSetup,
teardown: handleTeardown,
} satisfies BenchOptions
Expand Down
6 changes: 6 additions & 0 deletions packages/runtime-vapor/__benchmarks__/_utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { BenchOptions } from 'vitest'
import {
type App,
type Component,
Expand All @@ -9,6 +10,11 @@ import {
} from '../src'
import type { RawProps } from '../src/componentProps'

export const basicOptions = {
warmupIterations: 10,
iterations: 30,
} satisfies BenchOptions

export interface RenderContext {
component: Component
host: HTMLElement
Expand Down
17 changes: 17 additions & 0 deletions packages/runtime-vapor/__benchmarks__/demo.bench.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { bench, describe } from 'vitest'

describe('vitest bench demo', () => {
bench('normal', () => {
const x = [1, 5, 4, 2, 3]
x.sort((a, b) => {
return a - b
})
})

bench('reverse', () => {
const x = [1, 5, 4, 2, 3]
x.reverse().sort((a, b) => {
return a - b
})
})
})
Loading

0 comments on commit 317da0e

Please sign in to comment.