@@ -38,9 +38,11 @@ async function testGenerate(args: {
38
38
name : string ;
39
39
type : string ;
40
40
} ;
41
+ onConnect ?: ( emitter : AwaitEventEmitter ) => void ;
41
42
} ) {
42
- const { schema, options, createSouceFile } = args ;
43
+ const { schema, options, createSouceFile, onConnect } = args ;
43
44
const connectCallback = ( emitter : AwaitEventEmitter ) => {
45
+ onConnect && onConnect ( emitter ) ;
44
46
emitter . off ( 'GenerateFiles' ) ;
45
47
if ( createSouceFile ) {
46
48
emitter . on (
@@ -1265,35 +1267,127 @@ describe('combine scalar filters', () => {
1265
1267
} ) ;
1266
1268
} ) ;
1267
1269
1268
- describe ( 'export all from index' , ( ) => {
1269
- before ( async ( ) => {
1270
- await testGenerate ( {
1271
- schema : `
1270
+ describe ( 'reexport option' , ( ) => {
1271
+ describe ( 'reexport Directories clean' , ( ) => {
1272
+ before ( async ( ) => {
1273
+ await testGenerate ( {
1274
+ schema : `
1272
1275
model User {
1273
1276
id Int @id
1274
1277
}` ,
1275
- options : [ 'reExportAll = true' ] ,
1278
+ options : [ 'reExport = Directories' ] ,
1279
+ } ) ;
1280
+ } ) ;
1281
+
1282
+ it ( 'user/index' , ( ) => {
1283
+ sourceFile = project . getSourceFile ( s =>
1284
+ s . getFilePath ( ) . endsWith ( '/user/index.ts' ) ,
1285
+ ) ! ;
1286
+ // sourceFile = project.getSourceFile('/user/index.ts')!;
1287
+ expect ( sourceFile ) . toBeTruthy ( ) ;
1288
+ expect ( sourceFile . getText ( ) ) . toContain (
1289
+ `export { AggregateUser } from './aggregate-user.output'` ,
1290
+ ) ;
1291
+ expect ( sourceFile . getText ( ) ) . toContain (
1292
+ `export { User } from './user.model'` ,
1293
+ ) ;
1276
1294
} ) ;
1277
1295
} ) ;
1278
1296
1279
- it ( 'user/index' , ( ) => {
1280
- sourceFile = project . getSourceFile ( s =>
1281
- s . getFilePath ( ) . endsWith ( '/user/index.ts' ) ,
1282
- ) ! ;
1283
- // sourceFile = project.getSourceFile('/user/index.ts')!;
1284
- expect ( sourceFile ) . toBeTruthy ( ) ;
1285
- expect ( sourceFile . getText ( ) ) . toContain (
1286
- `export { AggregateUser } from './aggregate-user.output'` ,
1287
- ) ;
1288
- expect ( sourceFile . getText ( ) ) . toContain ( `export { User } from './user.model'` ) ;
1297
+ describe ( 'reexport Directories with existing file' , ( ) => {
1298
+ before ( async ( ) => {
1299
+ await testGenerate ( {
1300
+ schema : `
1301
+ model User {
1302
+ id Int @id
1303
+ }` ,
1304
+ options : [ 'reExport = Directories' ] ,
1305
+ onConnect ( emitter ) {
1306
+ emitter . on ( 'PostBegin' , ( { project, output } : EventArguments ) => {
1307
+ project . createSourceFile (
1308
+ `${ output } /user/index.ts` ,
1309
+ `export { User } from './user.model';` ,
1310
+ { overwrite : true } ,
1311
+ ) ;
1312
+ } ) ;
1313
+ } ,
1314
+ } ) ;
1315
+ } ) ;
1316
+
1317
+ it ( 'user index should not contain duplicate identifer' , ( ) => {
1318
+ sourceFile = project . getSourceFile ( s =>
1319
+ s . getFilePath ( ) . endsWith ( '/user/index.ts' ) ,
1320
+ ) ! ;
1321
+ exports = sourceFile . getExportDeclarations ( ) . map ( x => ( {
1322
+ specifier : x . getModuleSpecifierValue ( ) ,
1323
+ name : x . getNamedExports ( ) [ 0 ] . getName ( ) ,
1324
+ } ) ) ;
1325
+ expect ( exports ) . not . toContainEqual (
1326
+ expect . objectContaining ( { specifier : './index' } ) ,
1327
+ ) ;
1328
+ } ) ;
1289
1329
} ) ;
1290
1330
1291
- it ( 'root index' , ( ) => {
1292
- const rootDirectory = project . getRootDirectories ( ) [ 0 ] . getParent ( ) ;
1293
- const sourceFile = rootDirectory ?. getSourceFile ( 'index.ts' ) ! ;
1294
- expect ( sourceFile ) . toBeTruthy ( ) ;
1295
- expect ( sourceFile . getText ( ) ) . toContain ( `SortOrder } from './prisma'` ) ;
1296
- expect ( sourceFile . getText ( ) ) . toContain ( `from './user'` ) ;
1331
+ describe ( 'reexport Single' , ( ) => {
1332
+ before ( async ( ) => {
1333
+ await testGenerate ( {
1334
+ schema : `
1335
+ model User {
1336
+ id Int @id
1337
+ }` ,
1338
+ options : [ 'reExport = Single' ] ,
1339
+ } ) ;
1340
+ } ) ;
1341
+
1342
+ it ( 'root index' , ( ) => {
1343
+ const rootDirectory = project . getRootDirectories ( ) [ 0 ] . getParent ( ) ;
1344
+ const sourceFile = rootDirectory ?. getSourceFileOrThrow ( 'index.ts' ) ! ;
1345
+ expect ( sourceFile ) . toBeTruthy ( ) ;
1346
+ expect ( sourceFile . getText ( ) ) . toContain (
1347
+ `export { SortOrder } from './prisma/sort-order.enum'` ,
1348
+ ) ;
1349
+ expect ( sourceFile . getText ( ) ) . toContain (
1350
+ `export { User } from './user/user.model'` ,
1351
+ ) ;
1352
+ } ) ;
1353
+ } ) ;
1354
+
1355
+ describe ( 'reexport All' , ( ) => {
1356
+ before ( async ( ) => {
1357
+ await testGenerate ( {
1358
+ schema : `
1359
+ model User {
1360
+ id Int @id
1361
+ }` ,
1362
+ options : [ 'reExport = All' ] ,
1363
+ } ) ;
1364
+ } ) ;
1365
+
1366
+ it ( 'root index' , ( ) => {
1367
+ const rootDirectory = project . getRootDirectories ( ) [ 0 ] . getParent ( ) ;
1368
+ const sourceFile = rootDirectory ?. getSourceFileOrThrow ( 'index.ts' ) ! ;
1369
+ expect ( sourceFile ) . toBeTruthy ( ) ;
1370
+ expect ( sourceFile . getText ( ) ) . toMatch (
1371
+ / e x p o r t { .* A f f e c t e d R o w s , .* } f r o m ' \. \/ p r i s m a ' / ,
1372
+ ) ;
1373
+ expect ( sourceFile . getText ( ) ) . toMatch (
1374
+ / e x p o r t { .* U s e r W h e r e I n p u t , .* } f r o m ' \. \/ u s e r ' / ,
1375
+ ) ;
1376
+ } ) ;
1377
+
1378
+ it ( 'user index' , ( ) => {
1379
+ sourceFile = project . getSourceFile ( s =>
1380
+ s . getFilePath ( ) . endsWith ( '/user/index.ts' ) ,
1381
+ ) ! ;
1382
+ // sourceFile = project.getSourceFile('/user/index.ts')!;
1383
+ expect ( sourceFile ) . toBeTruthy ( ) ;
1384
+ expect ( sourceFile . getText ( ) ) . toContain (
1385
+ `export { AggregateUser } from './aggregate-user.output'` ,
1386
+ ) ;
1387
+ expect ( sourceFile . getText ( ) ) . toContain (
1388
+ `export { User } from './user.model'` ,
1389
+ ) ;
1390
+ } ) ;
1297
1391
} ) ;
1298
1392
} ) ;
1299
1393
0 commit comments