Skip to content

test: nest fixture in node_modules #22

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

Merged
merged 3 commits into from
Apr 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/mkdist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ function defineVueLoader(options?: DefineVueLoaderOptions): Loader {
)

if (!modified) {
return
return output
}

const contents = results
Expand Down
15 changes: 11 additions & 4 deletions test/mkdist.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { afterAll, describe, expect, it } from 'vitest'
import { vueLoader } from '../src/mkdist'

describe('transform typescript script setup', () => {
const tmpDir = fileURLToPath(new URL('./.tmp/fixtures', import.meta.url))
const tmpDir = fileURLToPath(new URL('../node_modules/.tmp/fixtures', import.meta.url))
afterAll(async () => {
await rm(tmpDir, { force: true, recursive: true })
})
Expand Down Expand Up @@ -216,7 +216,7 @@ describe('transform typescript script setup', () => {
`)
})

it('generates declaration', { timeout: 10000 }, async () => {
it('generates declaration', { timeout: 50_000 }, async () => {
const src = `
<template>
<div :data-test="toValue('hello')" />
Expand All @@ -241,6 +241,13 @@ describe('transform typescript script setup', () => {
export default _default;
"
`)

expect(await fixture(`<template><div /></template>`)).toMatchInlineSnapshot(`"<template><div /></template>"`)
expect(await declaration(`<template><div /></template>`)).toMatchInlineSnapshot(`
"declare const _default: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
export default _default;
"
`)
})

async function fixture(src: string): Promise<string> {
Expand All @@ -256,11 +263,11 @@ describe('transform typescript script setup', () => {
return await readFile(join(tmpDir, 'dist/index.vue'), 'utf-8')
}

async function declaration(src: string): Promise<string> {
async function declaration(src: string): Promise<string | undefined> {
await rm(tmpDir, { force: true, recursive: true })
await mkdir(join(tmpDir, 'src'), { recursive: true })
await writeFile(join(tmpDir, 'src/index.vue'), src)
await mkdist({ declaration: true, loaders: ['js', vueLoader], rootDir: tmpDir })
return await readFile(join(tmpDir, 'dist/index.vue.d.ts'), 'utf-8')
return await readFile(join(tmpDir, 'dist/index.vue.d.ts'), 'utf-8').catch(() => undefined)
}
})