diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 000000000..b1565ae23 --- /dev/null +++ b/examples/README.md @@ -0,0 +1,21 @@ +# Examples + +| Example | Source | Playground | +|---|---|---| +| `lit` | [GitHub](https://github.com/vitest-dev/vitest/tree/main/examples/lit) | [Play Online](https://stackblitz.com/github/vitest-dev/vitest/tree/main/examples/lit?terminal=test) | +| `mocks` | [GitHub](https://github.com/vitest-dev/vitest/tree/main/examples/mocks) | [Play Online](https://stackblitz.com/github/vitest-dev/vitest/tree/main/examples/mocks?terminal=test) | +| `puppeteer` | [GitHub](https://github.com/vitest-dev/vitest/tree/main/examples/puppeteer) | [Play Online](https://stackblitz.com/github/vitest-dev/vitest/tree/main/examples/puppeteer?terminal=test) | +| `react` | [GitHub](https://github.com/vitest-dev/vitest/tree/main/examples/react) | [Play Online](https://stackblitz.com/github/vitest-dev/vitest/tree/main/examples/react?terminal=test) | +| `react-enzyme` | [GitHub](https://github.com/vitest-dev/vitest/tree/main/examples/react-enzyme) | [Play Online](https://stackblitz.com/github/vitest-dev/vitest/tree/main/examples/react-enzyme?terminal=test) | +| `react-mui` | [GitHub](https://github.com/vitest-dev/vitest/tree/main/examples/react-mui) | [Play Online](https://stackblitz.com/github/vitest-dev/vitest/tree/main/examples/react-mui?terminal=test) | +| `react-storybook-testing` | [GitHub](https://github.com/vitest-dev/vitest/tree/main/examples/react-storybook-testing) | [Play Online](https://stackblitz.com/github/vitest-dev/vitest/tree/main/examples/react-storybook-testing?terminal=test) | +| `react-testing-lib` | [GitHub](https://github.com/vitest-dev/vitest/tree/main/examples/react-testing-lib) | [Play Online](https://stackblitz.com/github/vitest-dev/vitest/tree/main/examples/react-testing-lib?terminal=test) | +| `react-testing-lib-msw` | [GitHub](https://github.com/vitest-dev/vitest/tree/main/examples/react-testing-lib-msw) | [Play Online](https://stackblitz.com/github/vitest-dev/vitest/tree/main/examples/react-testing-lib-msw?terminal=test) | +| `ruby` | [GitHub](https://github.com/vitest-dev/vitest/tree/main/examples/ruby) | [Play Online](https://stackblitz.com/github/vitest-dev/vitest/tree/main/examples/ruby?terminal=test) | +| `solid` | [GitHub](https://github.com/vitest-dev/vitest/tree/main/examples/solid) | [Play Online](https://stackblitz.com/github/vitest-dev/vitest/tree/main/examples/solid?terminal=test) | +| `svelte` | [GitHub](https://github.com/vitest-dev/vitest/tree/main/examples/svelte) | [Play Online](https://stackblitz.com/github/vitest-dev/vitest/tree/main/examples/svelte?terminal=test) | +| `testing-library-jest-dom` | [GitHub](https://github.com/vitest-dev/vitest/tree/main/examples/testing-library-jest-dom) | [Play Online](https://stackblitz.com/github/vitest-dev/vitest/tree/main/examples/testing-library-jest-dom?terminal=test) | +| `vitesse` | [GitHub](https://github.com/vitest-dev/vitest/tree/main/examples/vitesse) | [Play Online](https://stackblitz.com/github/vitest-dev/vitest/tree/main/examples/vitesse?terminal=test) | +| `vue` | [GitHub](https://github.com/vitest-dev/vitest/tree/main/examples/vue) | [Play Online](https://stackblitz.com/github/vitest-dev/vitest/tree/main/examples/vue?terminal=test) | +| `vue-jsx` | [GitHub](https://github.com/vitest-dev/vitest/tree/main/examples/vue-jsx) | [Play Online](https://stackblitz.com/github/vitest-dev/vitest/tree/main/examples/vue-jsx?terminal=test) | +| `vue2` | [GitHub](https://github.com/vitest-dev/vitest/tree/main/examples/vue2) | [Play Online](https://stackblitz.com/github/vitest-dev/vitest/tree/main/examples/vue2?terminal=test) | diff --git a/scripts/update-examples.ts b/scripts/update-examples.ts new file mode 100644 index 000000000..69f36d169 --- /dev/null +++ b/scripts/update-examples.ts @@ -0,0 +1,31 @@ +import { fileURLToPath } from 'url' +import { promises as fs } from 'fs' +import { resolve } from 'pathe' +import { notNullish } from '../packages/vitest/src/utils' + +async function run() { + const examplesRoot = resolve(fileURLToPath(import.meta.url), '../../examples') + + const examples = await fs.readdir(examplesRoot) + + const data = await Promise.all(examples.map(async(name) => { + const path = resolve(examplesRoot, name) + if ((await fs.lstat(path)).isFile()) + return + + const github = `https://github.com/vitest-dev/vitest/tree/main/examples/${name}` + const stackblitz = `https://stackblitz.com/github/vitest-dev/vitest/tree/main/examples/${name}?terminal=test` + return { + name, + path, + github, + stackblitz, + } + })) + + const table = `| Example | Source | Playground |\n|---|---|---|\n${data.filter(notNullish).map(i => `| \`${i.name}\` | [GitHub](${i.github}) | [Play Online](${i.stackblitz}) |`).join('\n')}` + + await fs.writeFile(resolve(examplesRoot, 'README.md'), `# Examples\n\n${table}\n`, 'utf-8') +} + +run()