ssssota / doc-vitest

Documentation tests with Vitest
https://npmjs.com/vite-plugin-doctest
49 stars 0 forks source link

Testing md snippets #80

Open wyozi opened 1 month ago

wyozi commented 1 month ago

I have a fairly simple use case where I'm trying to test code snippets in README.md. However, vitest gives Error: Failed to parse source for import analysis because the content contains invalid JS syntax. You may need to install appropriate plugins to handle the .md file format, or if it's an asset, add "**/*.md" toassetsIncludein your configuration.. Any idea what could be wrong?

vite.config.ts:

export default defineConfig({
  plugins: [doctest(), dts({ rollupTypes: true })],
  test: {
    includeSource: ["./src/**/*.[jt]s?(x)", "./README.md"],
  },
  ...
})

versions:

    "vite": "^5.2.11",
    "vite-plugin-doctest": "^1.0.0",
    "vite-plugin-dts": "^3.9.1",
    "vitest": "^1.6.0",

full error stack:

Error: Failed to parse source for import analysis because the content contains invalid JS syntax. You may need to install appropriate plugins to handle the .md file format, or if it's an asset, add "**/*.md" to `assetsInclude` in your configuration.
 ❯ formatError node_modules/.pnpm/vite@5.2.11_@types+node@20.12.12/node_modules/vite/dist/node/chunks/dep-cNe07EU9.js:50830:46
 ❯ TransformContext.error node_modules/.pnpm/vite@5.2.11_@types+node@20.12.12/node_modules/vite/dist/node/chunks/dep-cNe07EU9.js:50824:19
 ❯ TransformContext.transform node_modules/.pnpm/vite@5.2.11_@types+node@20.12.12/node_modules/vite/dist/node/chunks/dep-cNe07EU9.js:66069:22
 ❯ Object.transform node_modules/.pnpm/vite@5.2.11_@types+node@20.12.12/node_modules/vite/dist/node/chunks/dep-cNe07EU9.js:51139:30
 ❯ loadAndTransform node_modules/.pnpm/vite@5.2.11_@types+node@20.12.12/node_modules/vite/dist/node/chunks/dep-cNe07EU9.js:53894:29
ssssota commented 1 month ago

I'll check it! Thank you for reporting!!

ssssota commented 1 month ago

@wyozi I've checked, but I'm sorry. I couldn't reproduce this bug. Can you provide a reproduction repository?