Skip to content

Commit

Permalink
Merge branch 'main' into feat/run-in-worker
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed May 29, 2022
2 parents 93d48e8 + 27be365 commit bfbc35c
Show file tree
Hide file tree
Showing 21 changed files with 2,152 additions and 2,666 deletions.
9 changes: 9 additions & 0 deletions .pnpmfile.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
hooks: {
readPackage(pkg) {
if (pkg.name === 'vue-template-compiler')
pkg.dependencies.vue = '^2.6.0'
return pkg
},
},
}
2 changes: 0 additions & 2 deletions docs/docs-data.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// noinspection ES6PreferShortImport: IntelliJ IDE hint to avoid warning to use `~/contributors`, will fail on build if changed
/* PWA DISABLED */
export const pwaDisabled = false

/* Texts */
export const vitestName = 'Vitest'
Expand Down
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"private": true,
"scripts": {
"dev": "vitepress --port 3333 --open",
"build": "nr prefetch && vitepress build && esno scripts/build-pwa.ts",
"build": "nr prefetch && vitepress build",
"serve": "vitepress serve",
"preview-https": "pnpm run build && serve .vitepress/dist",
"prefetch": "esno scripts/fetch-avatars.ts"
Expand Down
8 changes: 4 additions & 4 deletions docs/scripts/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import fg from 'fast-glob'
import { font, preconnectHomeLinks, preconnectLinks } from '../docs-data'

const preconnect = `
${preconnectLinks.map(l => `<link rel="dns-prefetch" href="${l}">`).join('\n')}
${preconnectLinks.map(l => `<link rel="preconnect" crossorigin="anonymous" href="${l}">`).join('\n')}
${preconnectLinks.map(l => `<link rel="dns-prefetch" href="${l}">`).join('\n')}
${preconnectLinks.map(l => `<link rel="preconnect" crossorigin="anonymous" href="${l}">`).join('\n')}
`

const preconnectHome = `
${preconnectHomeLinks.map(l => `<link rel="dns-prefetch" href="${l}">`).join('\n')}
${preconnectHomeLinks.map(l => `<link rel="preconnect" crossorigin="anonymous" href="${l}">`).join('\n')}
${preconnectHomeLinks.map(l => `<link rel="dns-prefetch" href="${l}">`).join('\n')}
${preconnectHomeLinks.map(l => `<link rel="preconnect" crossorigin="anonymous" href="${l}">`).join('\n')}
`

export const optimizePages = async (pwa: boolean) => {
Expand Down
15 changes: 0 additions & 15 deletions docs/scripts/build-pwa.ts

This file was deleted.

156 changes: 78 additions & 78 deletions docs/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,84 @@ import Components from 'unplugin-vue-components/vite'
import Unocss from 'unocss/vite'
import { presetAttributify, presetIcons, presetUno } from 'unocss'
import { resolve } from 'pathe'
import type { VitePluginPWAAPI } from 'vite-plugin-pwa'
import { VitePWA } from 'vite-plugin-pwa'
import fg from 'fast-glob'
import {
pwaDisabled,
pwaFontStylesRegex,
pwaFontsRegex,
vitestDescription,
vitestName,
vitestShortName,
} from './docs-data'
import { optimizePages } from './scripts/assets'

export default defineConfig({
define: {
'process.env.__PWA_DISABLED__': pwaDisabled,
const PWA = VitePWA({
outDir: '.vitepress/dist',
registerType: 'autoUpdate',
// include all static assets under public/
includeAssets: fg.sync('**/*.{png,svg,ico,txt}', { cwd: resolve(__dirname, 'public') }),
manifest: {
id: '/',
name: vitestName,
short_name: vitestShortName,
description: vitestDescription,
theme_color: '#ffffff',
icons: [
{
src: 'pwa-192x192.png',
sizes: '192x192',
type: 'image/png',
},
{
src: 'pwa-512x512.png',
sizes: '512x512',
type: 'image/png',
},
{
src: 'logo.svg',
sizes: '165x165',
type: 'image/svg',
purpose: 'any maskable',
},
],
},
workbox: {
navigateFallbackDenylist: [/^\/new$/],
runtimeCaching: [
{
urlPattern: pwaFontsRegex,
handler: 'CacheFirst',
options: {
cacheName: 'google-fonts-cache',
expiration: {
maxEntries: 10,
maxAgeSeconds: 60 * 60 * 24 * 365, // <== 365 days
},
cacheableResponse: {
statuses: [0, 200],
},
},
},
{
urlPattern: pwaFontStylesRegex,
handler: 'CacheFirst',
options: {
cacheName: 'gstatic-fonts-cache',
expiration: {
maxEntries: 10,
maxAgeSeconds: 60 * 60 * 24 * 365, // <== 365 days
},
cacheableResponse: {
statuses: [0, 200],
},
},
},
],
},
})

export default defineConfig({
plugins: [
Components({
include: [/\.vue/, /\.md/],
Expand All @@ -40,82 +103,19 @@ export default defineConfig({
],
}),
IncludesPlugin(),
VitePWA({
disable: pwaDisabled,
outDir: '.vitepress/dist',
registerType: 'autoUpdate',
// include all static assets under public/
includeAssets: fg.sync('**/*.{png,svg,ico,txt}', { cwd: resolve(__dirname, 'public') }),
manifest: {
id: '/',
name: vitestName,
short_name: vitestShortName,
description: vitestDescription,
theme_color: '#ffffff',
icons: [
{
src: 'pwa-192x192.png',
sizes: '192x192',
type: 'image/png',
},
{
src: 'pwa-512x512.png',
sizes: '512x512',
type: 'image/png',
},
{
src: 'logo.svg',
sizes: '165x165',
type: 'image/svg',
purpose: 'any maskable',
},
],
},
workbox: {
navigateFallbackDenylist: [/^\/new$/],
runtimeCaching: [
{
urlPattern: pwaFontsRegex,
handler: 'CacheFirst',
options: {
cacheName: 'google-fonts-cache',
expiration: {
maxEntries: 10,
maxAgeSeconds: 60 * 60 * 24 * 365, // <== 365 days
},
cacheableResponse: {
statuses: [0, 200],
},
},
},
{
urlPattern: pwaFontStylesRegex,
handler: 'CacheFirst',
options: {
cacheName: 'gstatic-fonts-cache',
expiration: {
maxEntries: 10,
maxAgeSeconds: 60 * 60 * 24 * 365, // <== 365 days
},
cacheableResponse: {
statuses: [0, 200],
},
},
},
],
PWA,
{
name: 'pwa:post',
enforce: 'post',
async buildEnd() {
const pwaPlugin: VitePluginPWAAPI = PWA.find(i => i.name === 'vite-plugin-pwa')?.api
const pwa = pwaPlugin && !pwaPlugin.disabled
await optimizePages(pwa)
if (pwa)
await pwaPlugin.generateSW()
},
}),
},
],

optimizeDeps: {
include: [
'vue',
'@vueuse/core',
],
exclude: [
'vue-demi',
],
},
})

function IncludesPlugin(): Plugin {
Expand Down
5 changes: 5 additions & 0 deletions examples/image-snapshot/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Vitest Demo

Run `npm test` and change a test or source code to see HMR in action!

Learn more at https://vitest.dev
21 changes: 21 additions & 0 deletions examples/image-snapshot/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "@vitest/example-image-snapshot",
"type": "module",
"private": true,
"license": "MIT",
"main": "index.js",
"scripts": {
"test": "vitest",
"test:ui": "vitest --ui",
"test:run": "vitest run"
},
"devDependencies": {
"@vitest/ui": "latest",
"jest-image-snapshot": "^4.5.1",
"vite": "^2.9.9",
"vitest": "latest"
},
"stackblitz": {
"startCommand": "npm run test:ui"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions examples/image-snapshot/test/basic.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { readFileSync } from 'fs'
import { expect, test } from 'vitest'
import { toMatchImageSnapshot } from 'jest-image-snapshot'

declare global {
namespace jest {
interface Matchers<R> {
toMatchImageSnapshot(): R
}
}
}

expect.extend({ toMatchImageSnapshot })

test('image snapshot', () => {
expect(readFileSync('./test/stubs/input-image.png')).toMatchImageSnapshot()
})
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions examples/image-snapshot/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/// <reference types="vitest" />

// Configure Vitest (https://vitest.dev/config/)

import { defineConfig } from 'vite'

export default defineConfig({
test: {
/* for example, use global to avoid globals imports (describe, test, expect): */
// globals: true,
},
})
Loading

0 comments on commit bfbc35c

Please sign in to comment.