@@ -5,6 +5,7 @@ import process from 'node:process';
5
5
import { createRequire } from 'node:module' ;
6
6
import { existsSync } from 'node:fs' ;
7
7
import { mock } from 'node:test' ;
8
+ import { promisify as promisify_ } from 'node:util' ;
8
9
import Generator from 'yeoman-generator' ;
9
10
import { afterEach , beforeEach , describe , expect , it } from 'esmocha' ;
10
11
import type Environment from 'yeoman-environment' ;
@@ -13,6 +14,8 @@ import helpers from '../src/helpers.js';
13
14
import { TestAdapter } from '../src/adapter.js' ;
14
15
import RunContext from '../src/run-context.js' ;
15
16
17
+ /* Remove argument from promisify return */
18
+ const promisify = function_ => ( ) => promisify_ ( function_ ) ( ) ;
16
19
const require = createRequire ( import . meta. url ) ;
17
20
const __dirname = dirname ( fileURLToPath ( import . meta. url ) ) ;
18
21
@@ -162,21 +165,27 @@ describe('yeoman-test', () => {
162
165
163
166
describe ( '.run()' , ( ) => {
164
167
describe ( 'with a generator' , ( ) => {
165
- it ( 'return a RunContext object' , done => {
166
- const context = helpers . run ( helpers . createDummyGenerator ( ) ) ;
167
- assert ( context instanceof RunContext ) ;
168
- context . on ( 'end' , done ) ;
169
- } ) ;
168
+ it (
169
+ 'return a RunContext object' ,
170
+ promisify ( done => {
171
+ const context = helpers . run ( helpers . createDummyGenerator ( ) ) ;
172
+ assert ( context instanceof RunContext ) ;
173
+ context . on ( 'end' , done ) ;
174
+ } ) ,
175
+ ) ;
170
176
} ) ;
171
177
172
178
describe ( 'with a namespace' , ( ) => {
173
- it ( 'return a RunContext object' , done => {
174
- const context = helpers . run ( 'simple:app' ) . withEnvironment ( environment => {
175
- environment . register ( require . resolve ( './fixtures/generator-simple/app' ) ) ;
176
- } ) ;
177
- assert ( context instanceof RunContext ) ;
178
- context . on ( 'end' , done ) ;
179
- } ) ;
179
+ it (
180
+ 'return a RunContext object' ,
181
+ promisify ( done => {
182
+ const context = helpers . run ( 'simple:app' ) . withEnvironment ( environment => {
183
+ environment . register ( require . resolve ( './fixtures/generator-simple/app' ) ) ;
184
+ } ) ;
185
+ assert ( context instanceof RunContext ) ;
186
+ context . on ( 'end' , done ) ;
187
+ } ) ,
188
+ ) ;
180
189
} ) ;
181
190
182
191
it ( 'pass settings to RunContext' , ( ) => {
@@ -192,55 +201,67 @@ describe('yeoman-test', () => {
192
201
assert . equal ( runContext . envOptions , environmentOptions ) ;
193
202
} ) ;
194
203
195
- it ( 'catch env errors' , done => {
196
- helpers
197
- . run (
198
- class extends helpers . createDummyGenerator ( ) {
199
- throws ( ) {
200
- this . env . emit ( 'error' , new Error ( 'an error' ) ) ;
201
- }
202
- } ,
203
- )
204
- . on ( 'error' , _ => {
205
- done ( ) ;
206
- } ) ;
207
- } ) ;
208
-
209
- it ( 'catch generator emitted errors' , done => {
210
- helpers
211
- . run (
212
- class extends helpers . createDummyGenerator ( ) {
213
- throws ( ) {
214
- this . emit ( 'error' , new Error ( 'an error' ) ) ;
215
- }
216
- } ,
217
- )
218
- . on ( 'error' , _ => {
219
- done ( ) ;
220
- } ) ;
221
- } ) ;
222
-
223
- it ( 'catch generator thrown errors' , done => {
224
- helpers
225
- . run (
226
- class extends helpers . createDummyGenerator ( ) {
227
- throws ( ) {
228
- throw new Error ( 'Some error.' ) ;
229
- }
230
- } ,
231
- )
232
- . on ( 'error' , _ => {
233
- done ( ) ;
234
- } ) ;
235
- } ) ;
204
+ it (
205
+ 'catch env errors' ,
206
+ promisify ( done => {
207
+ helpers
208
+ . run (
209
+ class extends helpers . createDummyGenerator ( ) {
210
+ throws ( ) {
211
+ this . env . emit ( 'error' , new Error ( 'an error' ) ) ;
212
+ }
213
+ } ,
214
+ )
215
+ . on ( 'error' , _ => {
216
+ done ( ) ;
217
+ } ) ;
218
+ } ) ,
219
+ ) ;
220
+
221
+ it (
222
+ 'catch generator emitted errors' ,
223
+ promisify ( done => {
224
+ helpers
225
+ . run (
226
+ class extends helpers . createDummyGenerator ( ) {
227
+ throws ( ) {
228
+ this . emit ( 'error' , new Error ( 'an error' ) ) ;
229
+ }
230
+ } ,
231
+ )
232
+ . on ( 'error' , _ => {
233
+ done ( ) ;
234
+ } ) ;
235
+ } ) ,
236
+ ) ;
237
+
238
+ it (
239
+ 'catch generator thrown errors' ,
240
+ promisify ( done => {
241
+ helpers
242
+ . run (
243
+ class extends helpers . createDummyGenerator ( ) {
244
+ throws ( ) {
245
+ throw new Error ( 'Some error.' ) ;
246
+ }
247
+ } ,
248
+ )
249
+ . on ( 'error' , _ => {
250
+ done ( ) ;
251
+ } ) ;
252
+ } ) ,
253
+ ) ;
236
254
237
255
// This is a workaround for corner case were an error is not correctly emitted
238
256
// See https://github.com/yeoman/generator/pull/1155
239
- it ( 'catch run errors' , done => {
240
- helpers . run ( class extends Generator { } , { } , { catchGeneratorError : true } ) . on ( 'error' , _ => {
241
- done ( ) ;
242
- } ) ;
243
- } ) ;
257
+ it (
258
+ 'catch run errors' ,
259
+ promisify ( done => {
260
+ helpers . run ( class extends Generator { } , { } , { catchGeneratorError : true } ) . on ( 'error' , _ => {
261
+ done ( ) ;
262
+ } ) ;
263
+ } ) ,
264
+ ) ;
244
265
245
266
describe ( 'with files' , ( ) => {
246
267
it ( 'write files to mem-fs' , async ( ) => {
0 commit comments