Skip to content

Commit

Permalink
chore: update to vitest v1 beta
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Dec 2, 2023
1 parent 4abae13 commit 46ea691
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 93 deletions.
2 changes: 1 addition & 1 deletion examples/app-vitest-full/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"listhen": "^1.5.5",
"nuxt": "3.8.2",
"typescript": "5.2.2",
"vitest": "0.34.6",
"vitest": "1.0.0-beta.6",
"vue-tsc": "1.8.19"
},
"version": "0.10.2",
Expand Down
2 changes: 1 addition & 1 deletion examples/app-vitest-full/tests/nuxt/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe('test utils', () => {
"<div>This is an auto-imported component</div>
<div> I am a global component </div>
<div>Index page</div>
<a href=\\"/test\\"> Test link </a>"
<a href="/test"> Test link </a>"
`)
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ it('should mock', async () => {
"<div>Mocked</div>
<div> I am a global component </div>
<div>Index page</div>
<a href=\\"/test\\"> Test link </a>"
<a href="/test"> Test link </a>"
`)
})
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ it('should mock', async () => {
"<div> Mocked 1 * 2 = 2</div>
<div> I am a global component </div>
<div>Index page</div>
<a href=\\"/test\\"> Test link </a>"
<a href="/test"> Test link </a>"
`)
})
4 changes: 2 additions & 2 deletions examples/app-vitest-full/tests/nuxt/utils-render.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ describe('test utils', () => {
it('can render components within nuxt suspense', async () => {
const { html } = await renderSuspended(App)
expect(html()).toMatchInlineSnapshot(`
"<div id=\\"test-wrapper\\">
"<div id="test-wrapper">
<div>This is an auto-imported component</div>
<div> I am a global component </div>
<div>Index page</div><a href=\\"/test\\"> Test link </a>
<div>Index page</div><a href="/test"> Test link </a>
</div>"
`)
})
Expand Down
2 changes: 1 addition & 1 deletion examples/module/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@
"@nuxt/test-utils": "latest",
"changelogen": "^0.5.5",
"nuxt": "^3.8.2",
"vitest": "0.34.6"
"vitest": "1.0.0-beta.6"
}
}
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"@testing-library/vue": "8.0.1",
"@types/estree": "1.0.5",
"@types/jsdom": "21.1.6",
"@vitest/ui": "0.34.6",
"@vitest/ui": "1.0.0-beta.6",
"@vue/test-utils": "2.4.3",
"changelogen": "0.5.5",
"eslint": "8.55.0",
Expand All @@ -80,21 +80,21 @@
"unbuild": "latest",
"unimport": "3.6.0",
"vite": "5.0.4",
"vitest": "0.34.6",
"vitest": "1.0.0-beta.6",
"vue-router": "4.2.5",
"vue-tsc": "1.8.24"
},
"peerDependencies": {
"@jest/globals": "^29.5.0",
"@testing-library/vue": "^7.0.0 || ^8.0.1",
"@vitest/ui": "0.34.6",
"@vitest/ui": "^0.33.0 || ^0.34.6 || ^1.0.0-beta.6",
"@vue/test-utils": "^2.4.2",
"h3": "*",
"happy-dom": "^9.10.9 || ^10.0.0 || ^11.0.0 || ^12.0.0",
"jsdom": "^22.0.0 || ^23.0.0",
"playwright-core": "^1.34.3",
"vite": "*",
"vitest": "^0.24.5 || ^0.26.0 || ^0.27.0 || ^0.28.0 || ^0.29.0 || ^0.30.0 || ^0.33.0 || ^0.34.6",
"vitest": "^0.24.5 || ^0.26.0 || ^0.27.0 || ^0.28.0 || ^0.29.0 || ^0.30.0 || ^0.33.0 || ^0.34.6 || ^1.0.0-beta.6",
"vue": "^3.3.4",
"vue-router": "^4.0.0"
},
Expand Down
122 changes: 51 additions & 71 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 11 additions & 11 deletions test/unit/mock-transform.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,27 +48,27 @@ describe('mocking', () => {
return () => 'mocked'
})
`)).toMatchInlineSnapshot(`
"import {vi} from \\"vitest\\";
"import {vi} from "vitest";
vi.hoisted(() => {
if(!globalThis.__NUXT_VITEST_MOCKS){
vi.stubGlobal(\\"__NUXT_VITEST_MOCKS\\", {})
vi.stubGlobal("__NUXT_VITEST_MOCKS", {})
}
});
vi.mock(\\"bob\\", async (importOriginal) => {
vi.mock("bob", async (importOriginal) => {
const mocks = globalThis.__NUXT_VITEST_MOCKS
if (!mocks[\\"bob\\"]) {
mocks[\\"bob\\"] = { ...await importOriginal(\\"bob\\") }
if (!mocks["bob"]) {
mocks["bob"] = { ...await importOriginal("bob") }
}
mocks[\\"bob\\"][\\"useSomeExport\\"] = await (() => {
mocks["bob"]["useSomeExport"] = await (() => {
return () => 'mocked'
})();
return mocks[\\"bob\\"]
return mocks["bob"]
});
import { mockNuxtImport } from '@nuxt/test-utils/runtime-utils'
import \\"bob\\";"
import "bob";"
`)
})
it('should not add `vi` import if it already exists', async () => {
Expand Down Expand Up @@ -100,13 +100,13 @@ describe('mocking', () => {
import { mockComponent } from '@nuxt/test-utils/runtime-utils'
mockComponent('MyComponent', () => import('./MockComponent.vue'))
`)).toMatchInlineSnapshot(`
"import {vi} from \\"vitest\\";
"import {vi} from "vitest";
vi.hoisted(() => {
if(!globalThis.__NUXT_VITEST_MOCKS){
vi.stubGlobal(\\"__NUXT_VITEST_MOCKS\\", {})
vi.stubGlobal("__NUXT_VITEST_MOCKS", {})
}
});
vi.mock(\\"MyComponent\\", async () => {
vi.mock("MyComponent", async () => {
const factory = (() => import('./MockComponent.vue'));
const result = typeof factory === 'function' ? await factory() : await factory
return 'default' in result ? result : { default: result }
Expand Down

0 comments on commit 46ea691

Please sign in to comment.