Skip to content

Commit 167963d

Browse files
author
Pascal Klesse
committed
test: update module tests to use async setup and add installModule mock
1 parent 7ae78df commit 167963d

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

test/module.test.ts

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ vi.mock('@nuxt/kit', () => ({
1212
createResolver: vi.fn().mockImplementation(() => ({
1313
resolve: vi.fn().mockImplementation(path => path),
1414
})),
15+
installModule: vi.fn(),
1516
}))
1617

1718
describe('Bug LT Module', () => {
@@ -28,6 +29,7 @@ describe('Bug LT Module', () => {
2829
it('should have correct default options', () => {
2930
expect(module.defaults).toEqual({
3031
enabled: true,
32+
ui: true,
3133
autoShow: true,
3234
position: 'bottom-right',
3335
buttonColor: '#ef4444',
@@ -39,13 +41,14 @@ describe('Bug LT Module', () => {
3941
})
4042
})
4143

42-
it('should register components correctly', () => {
44+
it('should register components correctly', async () => {
4345
const mockNuxt = {
4446
options: {
4547
runtimeConfig: {
4648
public: { bugLt: {} },
4749
bugLt: {},
4850
},
51+
modules: [],
4952
},
5053
}
5154

@@ -55,7 +58,7 @@ describe('Bug LT Module', () => {
5558
autoShow: true,
5659
}
5760

58-
module.setup(mockOptions, mockNuxt)
61+
await module.setup(mockOptions, mockNuxt)
5962

6063
expect(addComponent).toHaveBeenCalledWith({
6164
name: 'BugReportButton',
@@ -68,39 +71,41 @@ describe('Bug LT Module', () => {
6871
})
6972
})
7073

71-
it('should register composables correctly', () => {
74+
it('should register composables correctly', async () => {
7275
const mockNuxt = {
7376
options: {
7477
runtimeConfig: {
7578
public: { bugLt: {} },
7679
bugLt: {},
7780
},
81+
modules: [],
7882
},
7983
}
8084

8185
const mockOptions: ModuleOptions = {}
8286

83-
module.setup(mockOptions, mockNuxt)
87+
await module.setup(mockOptions, mockNuxt)
8488

8589
expect(addImports).toHaveBeenCalledWith({
8690
name: 'useBugReport',
8791
from: './runtime/composables/useBugReport',
8892
})
8993
})
9094

91-
it('should register server handlers correctly', () => {
95+
it('should register server handlers correctly', async () => {
9296
const mockNuxt = {
9397
options: {
9498
runtimeConfig: {
9599
public: { bugLt: {} },
96100
bugLt: {},
97101
},
102+
modules: [],
98103
},
99104
}
100105

101106
const mockOptions: ModuleOptions = {}
102107

103-
module.setup(mockOptions, mockNuxt)
108+
await module.setup(mockOptions, mockNuxt)
104109

105110
expect(addServerHandler).toHaveBeenCalledWith({
106111
route: '/api/bug-report',
@@ -115,30 +120,32 @@ describe('Bug LT Module', () => {
115120
})
116121
})
117122

118-
it('should register plugin correctly', () => {
123+
it('should register plugin correctly', async () => {
119124
const mockNuxt = {
120125
options: {
121126
runtimeConfig: {
122127
public: { bugLt: {} },
123128
bugLt: {},
124129
},
130+
modules: [],
125131
},
126132
}
127133

128134
const mockOptions: ModuleOptions = {}
129135

130-
module.setup(mockOptions, mockNuxt)
136+
await module.setup(mockOptions, mockNuxt)
131137

132138
expect(addPlugin).toHaveBeenCalledWith('./runtime/plugin.client')
133139
})
134140

135-
it('should configure runtime config correctly', () => {
141+
it('should configure runtime config correctly', async () => {
136142
const mockNuxt = {
137143
options: {
138144
runtimeConfig: {
139145
public: { bugLt: {} },
140146
bugLt: {},
141147
},
148+
modules: [],
142149
},
143150
}
144151

@@ -151,7 +158,7 @@ describe('Bug LT Module', () => {
151158
buttonColor: '#ff0000',
152159
}
153160

154-
module.setup(mockOptions, mockNuxt)
161+
await module.setup(mockOptions, mockNuxt)
155162

156163
// Public config should not expose sensitive data
157164
expect(mockNuxt.options.runtimeConfig.public.bugLt).toEqual({
@@ -167,13 +174,14 @@ describe('Bug LT Module', () => {
167174
})
168175
})
169176

170-
it('should handle missing linear configuration', () => {
177+
it('should handle missing linear configuration', async () => {
171178
const mockNuxt = {
172179
options: {
173180
runtimeConfig: {
174181
public: { bugLt: {} },
175182
bugLt: {},
176183
},
184+
modules: [],
177185
},
178186
}
179187

@@ -182,7 +190,7 @@ describe('Bug LT Module', () => {
182190
position: 'bottom-left',
183191
}
184192

185-
module.setup(mockOptions, mockNuxt)
193+
await module.setup(mockOptions, mockNuxt)
186194

187195
expect(mockNuxt.options.runtimeConfig.bugLt).toEqual({
188196
linearApiKey: undefined,
@@ -191,19 +199,20 @@ describe('Bug LT Module', () => {
191199
})
192200
})
193201

194-
it('should use createResolver to resolve file paths', () => {
202+
it('should use createResolver to resolve file paths', async () => {
195203
const mockNuxt = {
196204
options: {
197205
runtimeConfig: {
198206
public: { bugLt: {} },
199207
bugLt: {},
200208
},
209+
modules: [],
201210
},
202211
}
203212

204213
const mockOptions: ModuleOptions = {}
205214

206-
module.setup(mockOptions, mockNuxt)
215+
await module.setup(mockOptions, mockNuxt)
207216

208217
expect(createResolver).toHaveBeenCalledWith(expect.any(String))
209218
})

0 commit comments

Comments
 (0)