[READ-ONLY] Mirror of https://github.com/danielroe/cross-origin-storage. Load shared dependencies from Cross-Origin Storage (COS).
cross-origin-storage experimental nuxt vite vite-plugin
0

Configure Feed

Select the types of activity you want to include in your feed.

test: add type tests

+90 -4
+3 -2
packages/nuxt-cos/package.json
··· 43 43 "dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare", 44 44 "lint": "eslint .", 45 45 "prepack": "pnpm --filter vite-plugin-cross-origin-storage build && nuxt-module-build build", 46 - "test": "pnpm test:unit", 47 - "test:unit": "vitest run" 46 + "test": "pnpm test:unit && pnpm test:types", 47 + "test:unit": "vitest run", 48 + "test:types": "tsc --noEmit && vitest run --typecheck.only" 48 49 }, 49 50 "dependencies": { 50 51 "@nuxt/kit": "^4.4.8",
+5
packages/nuxt-cos/src/runtime/server/plugins/virtual-cos-loader.d.ts
··· 1 + declare module 'virtual:cos-loader' { 2 + /** Loader `<script>` body (IIFE + inlined manifest) injected at SSR time. */ 3 + const scriptContent: string 4 + export default scriptContent 5 + }
+1 -1
packages/nuxt-cos/test/ssr.test.ts
··· 1 1 import { fileURLToPath } from 'node:url' 2 2 import { describe, expect, it } from 'vitest' 3 3 import { $fetch, setup } from '@nuxt/test-utils/e2e' 4 - import type { CosManifest } from '../src/runtime/loader' 4 + import type { CosManifest } from 'vite-plugin-cross-origin-storage' 5 5 6 6 function parseManifest(html: string): CosManifest { 7 7 const start = html.indexOf('{"base":')
+17
packages/nuxt-cos/test/types.test-d.ts
··· 1 + import { assertType, describe, expectTypeOf, it } from 'vitest' 2 + import type { ModuleOptions } from '../src/module' 3 + 4 + describe('ModuleOptions', () => { 5 + it('types packages as a string/RegExp array', () => { 6 + expectTypeOf<ModuleOptions['packages']>().toEqualTypeOf<Array<string | RegExp>>() 7 + }) 8 + 9 + it('accepts string and RegExp package matchers', () => { 10 + assertType<ModuleOptions>({ packages: ['vue', /^@vue\//] }) 11 + }) 12 + 13 + it('rejects non-string/RegExp matchers', () => { 14 + // @ts-expect-error packages entries must be string | RegExp 15 + assertType<ModuleOptions>({ packages: [123] }) 16 + }) 17 + })
+8
packages/nuxt-cos/tsconfig.json
··· 1 + { 2 + "extends": "./.nuxt/tsconfig.json", 3 + "exclude": [ 4 + "dist", 5 + "node_modules", 6 + "test/fixtures", 7 + ], 8 + }
+4
packages/nuxt-cos/vitest.config.ts
··· 8 8 // The fixture is built into shared `.output` / `.nuxt` dirs; running test 9 9 // files in parallel makes their builds clobber each other. 10 10 fileParallelism: false, 11 + typecheck: { 12 + include: ['test/**/*.test-d.ts'], 13 + tsconfig: './tsconfig.json', 14 + }, 11 15 }, 12 16 })
+1 -1
packages/vite-plugin-cross-origin-storage/package.json
··· 50 50 "prepublishOnly": "pnpm lint && pnpm test", 51 51 "test": "pnpm test:unit && pnpm test:types", 52 52 "test:unit": "vitest run", 53 - "test:types": "tsc --noEmit" 53 + "test:types": "tsc --noEmit && vitest run --typecheck.only" 54 54 }, 55 55 "peerDependencies": { 56 56 "vite": "^5.0.0 || ^6.0.0 || ^7.0.0"
+47
packages/vite-plugin-cross-origin-storage/test/types.test-d.ts
··· 1 + import { assertType, describe, expectTypeOf, it } from 'vitest' 2 + import { cosPlugin } from '../src/index' 3 + import type { CosManifest, CosPluginOptions } from '../src/index' 4 + import type { Plugin } from 'vite' 5 + 6 + describe('cosPlugin', () => { 7 + it('returns a vite plugin', () => { 8 + expectTypeOf(cosPlugin).returns.toEqualTypeOf<Plugin>() 9 + }) 10 + 11 + it('requires the packages option', () => { 12 + // @ts-expect-error packages is required 13 + assertType<CosPluginOptions>({}) 14 + assertType<CosPluginOptions>({ packages: ['vue'] }) 15 + assertType<CosPluginOptions>({ packages: [/^vue$/, '@vue/runtime-core'] }) 16 + }) 17 + 18 + it('accepts the optional options', () => { 19 + assertType<CosPluginOptions>({ 20 + packages: ['vue'], 21 + base: '/_nuxt/', 22 + loaderEntry: '/path/to/loader.entry.mjs', 23 + onGenerated: (script) => { 24 + expectTypeOf(script).toEqualTypeOf<string>() 25 + }, 26 + }) 27 + }) 28 + 29 + it('rejects unknown options', () => { 30 + // @ts-expect-error unknown option 31 + assertType<CosPluginOptions>({ packages: ['vue'], unknown: true }) 32 + }) 33 + 34 + it('types packages as a string/RegExp array', () => { 35 + expectTypeOf<CosPluginOptions['packages']>().toEqualTypeOf<Array<string | RegExp>>() 36 + }) 37 + }) 38 + 39 + describe('CosManifest', () => { 40 + it('describes the manifest shape consumed by the loader', () => { 41 + expectTypeOf<CosManifest>().toEqualTypeOf<{ 42 + base: string 43 + entry: { specifier: string, file: string } 44 + chunks: Record<string, { file: string, hash: string }> 45 + }>() 46 + }) 47 + })
+4
packages/vite-plugin-cross-origin-storage/vitest.config.ts
··· 5 5 globalSetup: ['./test/global-setup.ts'], 6 6 testTimeout: 30_000, 7 7 hookTimeout: 240_000, 8 + typecheck: { 9 + include: ['test/**/*.test-d.ts'], 10 + tsconfig: './tsconfig.json', 11 + }, 8 12 }, 9 13 })