Skip to content

Commit

Permalink
docs: update examples, support no online playground (#812)
Browse files Browse the repository at this point in the history
  • Loading branch information
patak-dev committed Feb 21, 2022
1 parent e37f4de commit 7291176
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
3 changes: 2 additions & 1 deletion examples/README.md
Expand Up @@ -4,9 +4,10 @@
| `cjs` | [GitHub](https://github.com/vitest-dev/vitest/tree/main/examples/cjs) | [Play Online](https://stackblitz.com/fork/github/vitest-dev/vitest/tree/main/examples/cjs?initialPath=__vitest__) |
| `coverage-test` | [GitHub](https://github.com/vitest-dev/vitest/tree/main/examples/coverage-test) | [Play Online](https://stackblitz.com/fork/github/vitest-dev/vitest/tree/main/examples/coverage-test?initialPath=__vitest__) |
| `fails` | [GitHub](https://github.com/vitest-dev/vitest/tree/main/examples/fails) | [Play Online](https://stackblitz.com/fork/github/vitest-dev/vitest/tree/main/examples/fails?initialPath=__vitest__) |
| `graphql` | [GitHub](https://github.com/vitest-dev/vitest/tree/main/examples/graphql) | [Play Online](https://stackblitz.com/fork/github/vitest-dev/vitest/tree/main/examples/graphql?initialPath=__vitest__) |
| `lit` | [GitHub](https://github.com/vitest-dev/vitest/tree/main/examples/lit) | [Play Online](https://stackblitz.com/fork/github/vitest-dev/vitest/tree/main/examples/lit?initialPath=__vitest__) |
| `mocks` | [GitHub](https://github.com/vitest-dev/vitest/tree/main/examples/mocks) | [Play Online](https://stackblitz.com/fork/github/vitest-dev/vitest/tree/main/examples/mocks?initialPath=__vitest__) |
| `puppeteer` | [GitHub](https://github.com/vitest-dev/vitest/tree/main/examples/puppeteer) | [Play Online](https://stackblitz.com/fork/github/vitest-dev/vitest/tree/main/examples/puppeteer?initialPath=__vitest__) |
| `puppeteer` | [GitHub](https://github.com/vitest-dev/vitest/tree/main/examples/puppeteer) | |
| `react` | [GitHub](https://github.com/vitest-dev/vitest/tree/main/examples/react) | [Play Online](https://stackblitz.com/fork/github/vitest-dev/vitest/tree/main/examples/react?initialPath=__vitest__) |
| `react-enzyme` | [GitHub](https://github.com/vitest-dev/vitest/tree/main/examples/react-enzyme) | [Play Online](https://stackblitz.com/fork/github/vitest-dev/vitest/tree/main/examples/react-enzyme?initialPath=__vitest__) |
| `react-mui` | [GitHub](https://github.com/vitest-dev/vitest/tree/main/examples/react-mui) | [Play Online](https://stackblitz.com/fork/github/vitest-dev/vitest/tree/main/examples/react-mui?initialPath=__vitest__) |
Expand Down
8 changes: 6 additions & 2 deletions scripts/update-examples.ts
Expand Up @@ -3,6 +3,10 @@ import { promises as fs } from 'fs'
import { resolve } from 'pathe'
import { notNullish } from '../packages/vitest/src/utils'

const noOnlinePlayground = [
'puppeteer', // e2e doesn't work in StackBlitz
]

async function run() {
const examplesRoot = resolve(fileURLToPath(import.meta.url), '../../examples')

Expand All @@ -14,7 +18,7 @@ async function run() {
return

const github = `https://github.com/vitest-dev/vitest/tree/main/examples/${name}`
const stackblitz = `https://stackblitz.com/fork/github/vitest-dev/vitest/tree/main/examples/${name}?initialPath=__vitest__`
const stackblitz = noOnlinePlayground.includes(name) ? undefined : `https://stackblitz.com/fork/github/vitest-dev/vitest/tree/main/examples/${name}?initialPath=__vitest__`
return {
name,
path,
Expand All @@ -23,7 +27,7 @@ async function run() {
}
}))

const table = `| Example | Source | Playground |\n|---|---|---|\n${data.filter(notNullish).map(i => `| \`${i.name}\` | [GitHub](${i.github}) | [Play Online](${i.stackblitz}) |`).join('\n')}`
const table = `| Example | Source | Playground |\n|---|---|---|\n${data.filter(notNullish).map(i => `| \`${i.name}\` | [GitHub](${i.github}) | ${i.stackblitz ? `[Play Online](${i.stackblitz}) ` : ''}|`).join('\n')}`

await fs.writeFile(resolve(examplesRoot, 'README.md'), `${table}\n`, 'utf-8')
}
Expand Down

0 comments on commit 7291176

Please sign in to comment.