1 import { createRuleTester } from "../../../test-utils"
2 import { rule } from "../rule"
3
4 const ruleTester = createRuleTester()
5
6 ruleTester.run("admin-no-medusa-utils-import", rule, {
7 valid: [
8 // The admin SDK is the supported, browser-safe entry point.
9 { code: `import { defineWidgetConfig } from "@medusajs/admin-sdk"` },
10 // Types are erased at build time — safe to import.
11 { code: `import type { HttpTypes } from "@medusajs/framework/types"` },
12 // The JS SDK is browser-safe.
13 { code: `import Medusa from "@medusajs/js-sdk"` },
14 // Unrelated third-party imports.
15 { code: `import { useState } from "react"` },
16 { code: `import { z } from "zod"` },
17 // A subpath whose name merely starts the same way — not an exact match.
18 { code: `import x from "@medusajs/framework/utils-extra"` },
19 ],
20 invalid: [
21 {
22 code: `import { MedusaError } from "@medusajs/framework/utils"`,
23 errors: [{ messageId: "nodeOnlyImportInAdmin" }],
24 },
25 {
26 code: `import { defineMiddlewares } from "@medusajs/framework/http"`,
27 errors: [{ messageId: "nodeOnlyImportInAdmin" }],
28 },
29 {
30 code: `import { createWorkflow } from "@medusajs/framework/workflows-sdk"`,
31 errors: [{ messageId: "nodeOnlyImportInAdmin" }],
32 },
33 // Single quotes are matched too.
34 {
35 code: `import { Modules } from '@medusajs/framework/utils'`,
36 errors: [{ messageId: "nodeOnlyImportInAdmin" }],
37 },
38 // Side-effect-only import.
39 {
40 code: `import "@medusajs/framework/utils"`,
41 errors: [{ messageId: "nodeOnlyImportInAdmin" }],
42 },
43 // Re-export of a Node-only module.
44 {
45 code: `export { MedusaError } from "@medusajs/framework/utils"`,
46 errors: [{ messageId: "nodeOnlyImportInAdmin" }],
47 },
48 {
49 code: `export * from "@medusajs/framework/http"`,
50 errors: [{ messageId: "nodeOnlyImportInAdmin" }],
51 },
52 ],
53 })