|
| 1 | +import { fileURLToPath } from 'node:url' |
| 2 | +import { expect, it } from 'vitest' |
| 3 | +import { getPackageExportsManifest } from 'vitest-package-exports' |
| 4 | + |
| 5 | +// Update the snapshot when updating the API |
| 6 | +// (and adjust the documentation accordingly). |
| 7 | +const exports = ` |
| 8 | +{ |
| 9 | + ".": { |
| 10 | + "createLoader": "function", |
| 11 | + "createParser": "function", |
| 12 | + "createSerializer": "function", |
| 13 | + "parseAsArrayOf": "function", |
| 14 | + "parseAsBoolean": "object", |
| 15 | + "parseAsFloat": "object", |
| 16 | + "parseAsHex": "object", |
| 17 | + "parseAsIndex": "object", |
| 18 | + "parseAsInteger": "object", |
| 19 | + "parseAsIsoDate": "object", |
| 20 | + "parseAsIsoDateTime": "object", |
| 21 | + "parseAsJson": "function", |
| 22 | + "parseAsNumberLiteral": "function", |
| 23 | + "parseAsString": "object", |
| 24 | + "parseAsStringEnum": "function", |
| 25 | + "parseAsStringLiteral": "function", |
| 26 | + "parseAsTimestamp": "object", |
| 27 | + "useQueryState": "function", |
| 28 | + "useQueryStates": "function", |
| 29 | + }, |
| 30 | + "./adapters/custom": { |
| 31 | + "renderQueryString": "function", |
| 32 | + "unstable_createAdapterProvider": "function", |
| 33 | + }, |
| 34 | + "./adapters/next": { |
| 35 | + "NuqsAdapter": "function", |
| 36 | + }, |
| 37 | + "./adapters/next/app": { |
| 38 | + "NuqsAdapter": "function", |
| 39 | + }, |
| 40 | + "./adapters/next/pages": { |
| 41 | + "NuqsAdapter": "function", |
| 42 | + }, |
| 43 | + "./adapters/react": { |
| 44 | + "NuqsAdapter": "function", |
| 45 | + "enableHistorySync": "function", |
| 46 | + }, |
| 47 | + "./adapters/react-router": { |
| 48 | + "NuqsAdapter": "function", |
| 49 | + "useOptimisticSearchParams": "function", |
| 50 | + }, |
| 51 | + "./adapters/react-router/v6": { |
| 52 | + "NuqsAdapter": "function", |
| 53 | + "useOptimisticSearchParams": "function", |
| 54 | + }, |
| 55 | + "./adapters/react-router/v7": { |
| 56 | + "NuqsAdapter": "function", |
| 57 | + "useOptimisticSearchParams": "function", |
| 58 | + }, |
| 59 | + "./adapters/remix": { |
| 60 | + "NuqsAdapter": "function", |
| 61 | + "useOptimisticSearchParams": "function", |
| 62 | + }, |
| 63 | + "./adapters/testing": { |
| 64 | + "NuqsTestingAdapter": "function", |
| 65 | + "withNuqsTestingAdapter": "function", |
| 66 | + }, |
| 67 | + "./server": { |
| 68 | + "createLoader": "function", |
| 69 | + "createParser": "function", |
| 70 | + "createSearchParamsCache": "function", |
| 71 | + "createSerializer": "function", |
| 72 | + "parseAsArrayOf": "function", |
| 73 | + "parseAsBoolean": "object", |
| 74 | + "parseAsFloat": "object", |
| 75 | + "parseAsHex": "object", |
| 76 | + "parseAsIndex": "object", |
| 77 | + "parseAsInteger": "object", |
| 78 | + "parseAsIsoDate": "object", |
| 79 | + "parseAsIsoDateTime": "object", |
| 80 | + "parseAsJson": "function", |
| 81 | + "parseAsNumberLiteral": "function", |
| 82 | + "parseAsString": "object", |
| 83 | + "parseAsStringEnum": "function", |
| 84 | + "parseAsStringLiteral": "function", |
| 85 | + "parseAsTimestamp": "object", |
| 86 | + }, |
| 87 | + "./testing": { |
| 88 | + "isParserBijective": "function", |
| 89 | + "testParseThenSerialize": "function", |
| 90 | + "testSerializeThenParse": "function", |
| 91 | + }, |
| 92 | +} |
| 93 | +` |
| 94 | + |
| 95 | +it('has a stable exported API (package.json)', async () => { |
| 96 | + const manifest = await getPackageExportsManifest({ |
| 97 | + importMode: 'package', |
| 98 | + cwd: fileURLToPath(import.meta.url) |
| 99 | + }) |
| 100 | + expect(manifest.exports).toMatchInlineSnapshot(exports) |
| 101 | +}) |
| 102 | + |
| 103 | +it('has a stable exported API (dist)', async () => { |
| 104 | + const manifest = await getPackageExportsManifest({ |
| 105 | + importMode: 'dist', |
| 106 | + cwd: fileURLToPath(import.meta.url) |
| 107 | + }) |
| 108 | + expect(manifest.exports).toMatchInlineSnapshot(exports) |
| 109 | +}) |
0 commit comments