3.29 kBPlain TextView Raw
1/* eslint-disable */
2
3import { describe, expect, test } from 'vitest'
4import type { ContextualAggregateError } from '../errors/ContextualAggregateError.js'
5import { run } from './specHelpers.js'
6
7describe(`invalid destructuring cases`, () => {
8 test(`noParameters`, async () => {
9 const result = await run(() => 1) as ContextualAggregateError
10 expect({
11 result,
12 errors: result.errors,
13 context: result.errors[0]?.context,
14 }).toMatchInlineSnapshot(`
15 {
16 "context": {
17 "issue": "noParameters",
18 },
19 "errors": [
20 [ContextualError: Extension must destructure the first parameter passed to it and select exactly one entrypoint.],
21 ],
22 "result": [ContextualAggregateError: One or more extensions are invalid.],
23 }
24 `)
25 })
26 test(`destructuredWithoutEntryHook`, async () => {
27 const result = await run(async ({ x }) => {}) as ContextualAggregateError
28 expect({
29 result,
30 errors: result.errors,
31 context: result.errors[0]?.context,
32 }).toMatchInlineSnapshot(
33 `
34 {
35 "context": {
36 "issue": "destructuredWithoutEntryHook",
37 },
38 "errors": [
39 [ContextualError: Extension must destructure the first parameter passed to it and select exactly one entrypoint.],
40 ],
41 "result": [ContextualAggregateError: One or more extensions are invalid.],
42 }
43 `,
44 )
45 })
46 test(`multipleParameters`, async () => {
47 // @ts-expect-error two parameters is invalid
48 const result = await run(async ({ x }, y) => {}) as ContextualAggregateError
49 expect({
50 result,
51 errors: result.errors,
52 context: result.errors[0]?.context,
53 }).toMatchInlineSnapshot(
54 `
55 {
56 "context": {
57 "issue": "multipleParameters",
58 },
59 "errors": [
60 [ContextualError: Extension must destructure the first parameter passed to it and select exactly one entrypoint.],
61 ],
62 "result": [ContextualAggregateError: One or more extensions are invalid.],
63 }
64 `,
65 )
66 })
67 test(`notDestructured`, async () => {
68 const result = await run(async (_) => {}) as ContextualAggregateError
69 expect({
70 result,
71 errors: result.errors,
72 context: result.errors[0]?.context,
73 }).toMatchInlineSnapshot(`
74 {
75 "context": {
76 "issue": "notDestructured",
77 },
78 "errors": [
79 [ContextualError: Extension must destructure the first parameter passed to it and select exactly one entrypoint.],
80 ],
81 "result": [ContextualAggregateError: One or more extensions are invalid.],
82 }
83 `)
84 })
85 test(`multipleDestructuredHookNames`, async () => {
86 const result = await run(async ({ a, b }) => {}) as ContextualAggregateError
87 expect({
88 result,
89 errors: result.errors,
90 context: result.errors[0]?.context,
91 }).toMatchInlineSnapshot(`
92 {
93 "context": {
94 "issue": "multipleDestructuredHookNames",
95 },
96 "errors": [
97 [ContextualError: Extension must destructure the first parameter passed to it and select exactly one entrypoint.],
98 ],
99 "result": [ContextualAggregateError: One or more extensions are invalid.],
100 }
101 `)
102 })
103})