Giter Site home page Giter Site logo

doc-vitest's Issues

Testing md snippets

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" to assetsInclude in 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/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-cNe07EU9.js:50830:46
 ❯ TransformContext.error node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-cNe07EU9.js:50824:19
 ❯ TransformContext.transform node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-cNe07EU9.js:66069:22
 ❯ Object.transform node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-cNe07EU9.js:51139:30
 ❯ loadAndTransform node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-cNe07EU9.js:53894:29

Test discovery in `class`es fails unless all fields contain doctest

Hello! Thank you for this plugin. I sorely missed doctests, coming from Rust.

Here is a minimum example of the issue:

class Foo {
	public constructor() { }

	/** some note about this property */ // ← this causes the test discovery to fail
	private readonly bar: number = 3;

	/**
	 * @import.meta.vitest
	 * ```ts
	 * assert(false);
	 * ```
	 */
	public readonly baz = (): void => { }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.