packages
nuxt-cos
vite-plugin-cross-origin-storage
···
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
46
-
"test": "pnpm test:unit",
47
47
-
"test:unit": "vitest run"
46
46
+
"test": "pnpm test:unit && pnpm test:types",
47
47
+
"test:unit": "vitest run",
48
48
+
"test:types": "tsc --noEmit && vitest run --typecheck.only"
48
49
},
49
50
"dependencies": {
50
51
"@nuxt/kit": "^4.4.8",
···
1
1
+
declare module 'virtual:cos-loader' {
2
2
+
/** Loader `<script>` body (IIFE + inlined manifest) injected at SSR time. */
3
3
+
const scriptContent: string
4
4
+
export default scriptContent
5
5
+
}
···
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
4
-
import type { CosManifest } from '../src/runtime/loader'
4
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":')
···
1
1
+
import { assertType, describe, expectTypeOf, it } from 'vitest'
2
2
+
import type { ModuleOptions } from '../src/module'
3
3
+
4
4
+
describe('ModuleOptions', () => {
5
5
+
it('types packages as a string/RegExp array', () => {
6
6
+
expectTypeOf<ModuleOptions['packages']>().toEqualTypeOf<Array<string | RegExp>>()
7
7
+
})
8
8
+
9
9
+
it('accepts string and RegExp package matchers', () => {
10
10
+
assertType<ModuleOptions>({ packages: ['vue', /^@vue\//] })
11
11
+
})
12
12
+
13
13
+
it('rejects non-string/RegExp matchers', () => {
14
14
+
// @ts-expect-error packages entries must be string | RegExp
15
15
+
assertType<ModuleOptions>({ packages: [123] })
16
16
+
})
17
17
+
})
···
1
1
+
{
2
2
+
"extends": "./.nuxt/tsconfig.json",
3
3
+
"exclude": [
4
4
+
"dist",
5
5
+
"node_modules",
6
6
+
"test/fixtures",
7
7
+
],
8
8
+
}
···
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
11
+
typecheck: {
12
12
+
include: ['test/**/*.test-d.ts'],
13
13
+
tsconfig: './tsconfig.json',
14
14
+
},
11
15
},
12
16
})
···
50
50
"prepublishOnly": "pnpm lint && pnpm test",
51
51
"test": "pnpm test:unit && pnpm test:types",
52
52
"test:unit": "vitest run",
53
53
-
"test:types": "tsc --noEmit"
53
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"
···
1
1
+
import { assertType, describe, expectTypeOf, it } from 'vitest'
2
2
+
import { cosPlugin } from '../src/index'
3
3
+
import type { CosManifest, CosPluginOptions } from '../src/index'
4
4
+
import type { Plugin } from 'vite'
5
5
+
6
6
+
describe('cosPlugin', () => {
7
7
+
it('returns a vite plugin', () => {
8
8
+
expectTypeOf(cosPlugin).returns.toEqualTypeOf<Plugin>()
9
9
+
})
10
10
+
11
11
+
it('requires the packages option', () => {
12
12
+
// @ts-expect-error packages is required
13
13
+
assertType<CosPluginOptions>({})
14
14
+
assertType<CosPluginOptions>({ packages: ['vue'] })
15
15
+
assertType<CosPluginOptions>({ packages: [/^vue$/, '@vue/runtime-core'] })
16
16
+
})
17
17
+
18
18
+
it('accepts the optional options', () => {
19
19
+
assertType<CosPluginOptions>({
20
20
+
packages: ['vue'],
21
21
+
base: '/_nuxt/',
22
22
+
loaderEntry: '/path/to/loader.entry.mjs',
23
23
+
onGenerated: (script) => {
24
24
+
expectTypeOf(script).toEqualTypeOf<string>()
25
25
+
},
26
26
+
})
27
27
+
})
28
28
+
29
29
+
it('rejects unknown options', () => {
30
30
+
// @ts-expect-error unknown option
31
31
+
assertType<CosPluginOptions>({ packages: ['vue'], unknown: true })
32
32
+
})
33
33
+
34
34
+
it('types packages as a string/RegExp array', () => {
35
35
+
expectTypeOf<CosPluginOptions['packages']>().toEqualTypeOf<Array<string | RegExp>>()
36
36
+
})
37
37
+
})
38
38
+
39
39
+
describe('CosManifest', () => {
40
40
+
it('describes the manifest shape consumed by the loader', () => {
41
41
+
expectTypeOf<CosManifest>().toEqualTypeOf<{
42
42
+
base: string
43
43
+
entry: { specifier: string, file: string }
44
44
+
chunks: Record<string, { file: string, hash: string }>
45
45
+
}>()
46
46
+
})
47
47
+
})
···
5
5
globalSetup: ['./test/global-setup.ts'],
6
6
testTimeout: 30_000,
7
7
hookTimeout: 240_000,
8
8
+
typecheck: {
9
9
+
include: ['test/**/*.test-d.ts'],
10
10
+
tsconfig: './tsconfig.json',
11
11
+
},
8
12
},
9
13
})