|
1
|
import { createRuleTester } from "../../../test-utils" |
|
2
|
import { rule } from "../rule" |
|
3
|
|
|
4
|
const ruleTester = createRuleTester() |
|
5
|
|
|
6
|
const SUBSCRIBER = "src/subscribers/order-placed.ts" |
|
7
|
|
|
8
|
ruleTester.run("subscriber-default-export-required", rule, { |
|
9
|
valid: [ |
|
10
|
// Default export of the subscriber function. |
|
11
|
{ |
|
12
|
code: `import type { SubscriberConfig } from "@medusajs/framework" |
|
13
|
export default async function orderPlacedHandler() {} |
|
14
|
export const config: SubscriberConfig = { event: "order.placed" }`, |
|
15
|
filename: SUBSCRIBER, |
|
16
|
}, |
|
17
|
// Inline default export. |
|
18
|
{ |
|
19
|
code: `export default async () => {}`, |
|
20
|
filename: SUBSCRIBER, |
|
21
|
}, |
|
22
|
// Default re-export via specifier (`export { X as default }`). |
|
23
|
{ |
|
24
|
code: `const handler = async () => {} |
|
25
|
export { handler as default }`, |
|
26
|
filename: SUBSCRIBER, |
|
27
|
}, |
|
28
|
// Default re-export from another module. |
|
29
|
{ |
|
30
|
code: `export { default } from "./order-placed-impl"`, |
|
31
|
filename: SUBSCRIBER, |
|
32
|
}, |
|
33
|
], |
|
34
|
invalid: [ |
|
35
|
// No exports at all. |
|
36
|
{ |
|
37
|
code: `const handler = async () => {}`, |
|
38
|
filename: SUBSCRIBER, |
|
39
|
errors: [{ messageId: "missingDefaultExport" }], |
|
40
|
}, |
|
41
|
// Only a named export, no default. |
|
42
|
{ |
|
43
|
code: `export const config = { event: "order.placed" } |
|
44
|
const handler = async () => {} |
|
45
|
export { handler }`, |
|
46
|
filename: SUBSCRIBER, |
|
47
|
errors: [{ messageId: "missingDefaultExport" }], |
|
48
|
}, |
|
49
|
// Named export of the handler, but no default. |
|
50
|
{ |
|
51
|
code: `export const orderPlacedHandler = async () => {}`, |
|
52
|
filename: SUBSCRIBER, |
|
53
|
errors: [{ messageId: "missingDefaultExport" }], |
|
54
|
}, |
|
55
|
], |
|
56
|
}) |