1 import { TypeList } from "docs-ui"
2
3 export const metadata = {
4 title: `moduleIntegrationTestRunner Reference`,
5 }
6
7 # {metadata.title}
8
9 This is a reference to the `moduleIntegrationTestRunner` function provided by the `@medusajs/test-utils` package.
10
11 ## Example
12
13 ```ts
14 import { moduleIntegrationTestRunner } from "@medusajs/test-utils"
15 import { BLOG_MODULE } from ".."
16 import BlogModuleService from "../service"
17 import Post from "../models/post"
18
19 moduleIntegrationTestRunner<BlogModuleService>({
20 moduleName: BLOG_MODULE,
21 moduleModels: [Post],
22 resolve: "./src/modules/blog",
23 testSuite: ({ service }) => {
24 // TODO write tests
25 },
26 })
27 ```
28
29 ## Parameters
30
31 <TypeList
32 types={[
33 {
34 type: "`object`",
35 name: "Input",
36 description: "Object parameter of test options.",
37 children: [
38 {
39 type: "`string`",
40 name: "moduleName",
41 description: "The module's name.",
42 },
43 {
44 type: "string",
45 name: "resolve",
46 description: "The path to the module relative to the `src` directory.",
47 },
48 {
49 type: "`() => void`",
50 name: "testSuite",
51 description: "The Jest tests to run.",
52 },
53 {
54 type: "DmlEntity[]",
55 name: "moduleModels",
56 description: "The module's data models. If not specified, the data models are loaded from the module's `models` directory. The test database is only created if the module has at least one data model, so pass a dummy model if your module doesn't have data models.",
57 optional: true
58 },
59 {
60 type: "`string`",
61 name: "dbName",
62 description: "A name to use for the test database. If not specified, the database name is of the format `medusa-<moduleName>-integration-<jestWorkerId>`. Unlike `medusaIntegrationTestRunner`, the database isn't dropped after the tests end.",
63 optional: true
64 },
65 {
66 type: "`Record<string, any>`",
67 name: "moduleOptions",
68 description: "Options to pass to the module.",
69 optional: true
70 },
71 {
72 type: "`Record<string, any>`",
73 name: "injectedDependencies",
74 description: "Dependencies to inject into the module's container. The key is the registration name, and the value is the instance of the dependency.",
75 optional: true
76 },
77 {
78 type: "`string`",
79 name: "schema",
80 description: "The PostgreSQL schema that the database is created in.",
81 optional: true
82 },
83 {
84 type: "`boolean`",
85 name: "debug",
86 description: "Whether to show database log messages.",
87 defaultValue: "false",
88 optional: true
89 },
90 {
91 type: "`string`",
92 name: "cwd",
93 description: "The current working directory. If not set, the directory that you run the test command from is considered the current working directory.",
94 optional: true
95 }
96 ]
97 }
98 ]}
99 sectionTitle="Parameters"
100 openedLevel={2}
101 />
102
103 ## Test Suite Parameters
104
105 The function passed to `testSuite` accepts the following parameters:
106
107 <TypeList
108 types={[
109 {
110 type: "`object`",
111 name: "Input",
112 description: "Object parameter of test utilities.",
113 children: [
114 {
115 type: "any",
116 name: "service",
117 description: "An instance of the module's main service. Its type is the type argument passed to the `moduleIntegrationTestRunner` function.",
118 optional: false
119 },
120 {
121 type: "`Record<string, string>`",
122 name: "dbConfig",
123 description: "The created database's configurations",
124 children: [
125 {
126 type: "`string`",
127 name: "schema",
128 description: "The PostgreSQL schema the database is created in."
129 },
130 {
131 type: "`string`",
132 name: "clientUrl",
133 description: "The connection URL to the database."
134 },
135 ]
136 },
137 {
138 type: "`TestDatabase`",
139 name: "MikroOrmWrapper",
140 description: "Utility functions to query and manage the database.",
141 children: [
142 {
143 type: `[SqlEntityManager](https://mikro-orm.io/api/knex/class/EntityManager)`,
144 name: "manager",
145 description: "An instance of MikroORM's entity manager, which can be used to run queries and perform other database tasks."
146 },
147 {
148 type: "`() => Promise<void>`",
149 name: "setupDatabase",
150 description: "Creates the database for the test."
151 },
152 {
153 type: "`() => Promise<void>`",
154 name: "clearDatabase",
155 description: "Removes all data in the database's tables."
156 },
157 {
158 type: "`() => SqlEntityManager`",
159 name: "forkManager",
160 description: "Returns a new entity manager."
161 }
162 ]
163 }
164 ]
165 }
166 ]}
167 sectionTitle="Test Suite Parameters"
168 openedLevel={2}
169 />