1 import { TypeList } from "docs-ui"
2
3 export const metadata = {
4 title: `medusaIntegrationTestRunner Reference`,
5 }
6
7 # {metadata.title}
8
9 This is a reference to the `medusaIntegrationTestRunner` function provided by the `@medusajs/test-utils` package.
10
11 ## Example
12
13 ```ts
14 import { medusaIntegrationTestRunner } from "@medusajs/test-utils"
15
16 medusaIntegrationTestRunner({
17 testSuite: ({ api, getContainer }) => {
18 // TODO write tests...
19 },
20 })
21 ```
22
23 ## Parameters
24
25 <TypeList
26 types={[
27 {
28 type: "`object`",
29 name: "Input",
30 description: "Object parameter of test options.",
31 children: [
32 {
33 type: "`(options: MedusaSuiteOptions) => void`",
34 name: "testSuite",
35 description: "The Jest tests to run. It accepts [Test Suite Parameters](#test-suite-parameters)",
36 },
37 {
38 type: "`string`",
39 name: "dbName",
40 description: "A name to use for the database. If not specified, the database name will be of the format `medusa-<randomId>-integration-<jestWorkerId>`.",
41 optional: true
42 },
43 {
44 type: "`string`",
45 name: "schema",
46 description: "The PostgreSQL schema that the database is created in.",
47 defaultValue: "public",
48 optional: true
49 },
50 {
51 type: "`Record<string, any>`",
52 name: "env",
53 description: "Environment variables to pass to the test suite.",
54 optional: true
55 },
56 {
57 type: "`boolean`",
58 name: "debug",
59 description: "Whether to show database log messages.",
60 defaultValue: "false",
61 optional: true
62 },
63 {
64 type: "`string`",
65 name: "moduleName",
66 description: "The name of the module being tested. If not specified, a random name will be generated.",
67 optional: true
68 },
69 {
70 type: "`string`",
71 name: "medusaConfigFile",
72 description: "The path to the `medusa-config.ts` file, excluding `medusa-config.ts`. This path is used as the current working directory as well.",
73 defaultValue: "cwd (current working directory)",
74 optional: true
75 },
76 {
77 type: "`object`",
78 name: "hooks",
79 description: "An object containing hooks to run at different points in the test lifecycle.",
80 optional: true,
81 children: [
82 {
83 type: "`(container: MedusaContainer) => Promise<void>`",
84 name: "beforeServerStart",
85 description: "A hook that runs before the Medusa server starts.",
86 optional: true
87 }
88 ]
89 }
90 ]
91 }
92 ]}
93 openedLevel={2}
94 sectionTitle="Parameters"
95
96 />
97
98 ## Test Suite Parameters
99
100 The function passed to `testSuite` accepts the following parameters:
101
102 <TypeList
103 types={[
104 {
105 type: "`object`",
106 name: "Input",
107 description: "Object parameter of test utilities.",
108 children: [
109 {
110 type: "Record<string, Function>",
111 name: "api",
112 description: "A set of methods used to send requests to the Medusa application.",
113 optional: false,
114 children: [
115 {
116 type: "(path: string) => Promise<any>",
117 name: "get",
118 description: "Send a GET request to the specified path."
119 },
120 {
121 type: "(path: string, data?: any) => Promise<any>",
122 name: "post",
123 description: "Send a POST request to the specified path."
124 },
125 {
126 type: "(path: string) => Promise<any>",
127 name: "delete",
128 description: "Send a DELETE request to the specified path."
129 },
130 ]
131 },
132 {
133 type: "`() => MedusaContainer`",
134 name: "getContainer",
135 description: "A function that returns the Medusa container.",
136 },
137 {
138 type: "`Record<string, string>`",
139 name: "dbConfig",
140 description: "The created database's configurations",
141 children: [
142 {
143 type: "`string`",
144 name: "dbName",
145 description: "The database's name."
146 },
147 {
148 type: "`string`",
149 name: "schema",
150 description: "The PostgreSQL schema the database is created in."
151 },
152 {
153 type: "`string`",
154 name: "clientUrl",
155 description: "The connection URL to the database."
156 },
157 ]
158 },
159 {
160 type: "`Record<string, Function>`",
161 name: "dbUtils",
162 description: "A set of methods to manage the database",
163 children: [
164 {
165 type: "`(dbName: string) => Promise<void>`",
166 name: "create",
167 description: "Creates a database."
168 },
169 {
170 type: "`(options?: { templateName?: string }) => Promise<void>`",
171 name: "snapshot",
172 description: "Creates a PostgreSQL template database from the current test database. Call this in a `beforeAll` hook after seeding data to enable fast per-test restores. Optionally pass a `templateName` to use a custom template name instead of the default."
173 },
174 {
175 type: "`(options?: { templateName?: string }) => Promise<void>`",
176 name: "restore",
177 description: "Restores the test database from a previously created template snapshot. Call this in a `beforeEach` hook to reset the database to a known state before each test. Optionally pass a `templateName` to restore from a custom template."
178 },
179 {
180 type: "`(options: { schema?: string }) => Promise<void>`",
181 name: "teardown",
182 description: "Deletes all data in a database's tables."
183 },
184 {
185 type: "`(dbName: string) => Promise<void>`",
186 name: "shutdown",
187 description: "Drops a database."
188 },
189 ]
190 },
191 {
192 type: "`object`",
193 name: "utils",
194 description: "A set of utility functions for the test suite.",
195 children: [
196 {
197 type: "`() => Promise<void>`",
198 name: "waitWorkflowExecutions",
199 description: "Waits for all workflow executions to complete."
200 }
201 ]
202 }
203 ]
204 }
205 ]}
206 sectionTitle="Test Suite Parameters"
207 openedLevel={2}
208 />