6
6
import { assert } from 'chai' ;
7
7
import { gray , green , red } from 'colorette' ;
8
8
import { diffLines } from 'diff' ;
9
- import { Dirent , promises as fs } from 'fs' ;
9
+ import { promises as fs , readdirSync } from 'fs' ;
10
10
import mockFs from 'mock-fs' ;
11
11
import type { DirectoryItems } from 'mock-fs/lib/filesystem' ;
12
- import { join } from 'path' ;
13
12
import { URL } from 'node:url' ;
13
+ import { join } from 'path' ;
14
14
import { v4 as uuid } from 'uuid' ;
15
15
import { Configuration } from '../src/cli/configuration.js' ;
16
+ import { exists } from '../src/cli/file-system-helper.js' ;
16
17
import { $Generator } from '../src/cli/generator.js' ;
17
18
import { Endpoint , EndpointConfiguration } from '../src/cli/shared.js' ;
18
- import { exists } from '../src/cli/file-system-helper.js' ;
19
19
20
20
const __dirname = process . cwd ( ) ;
21
21
@@ -65,14 +65,10 @@ describe('generator', function () {
65
65
}
66
66
67
67
const dataPath = join ( __dirname , 'tests' , 'data' ) ;
68
- let directoryEntries : Dirent [ ] = [ ] ;
69
- before ( async function ( ) {
70
- directoryEntries = ( await fs . readdir ( dataPath , { encoding : 'utf8' , withFileTypes : true } ) )
71
- . filter ( ( x ) => x . isDirectory ( ) ) ;
72
- } ) ;
73
- for ( const dirent of directoryEntries ) {
68
+ for ( const dirent of ( readdirSync ( dataPath , { encoding : 'utf8' , withFileTypes : true } ) )
69
+ . filter ( ( x ) => x . isDirectory ( ) ) ) {
74
70
const dirName = dirent . name ;
75
- it . only ( `works for ${ dirName } ` , async function ( ) {
71
+ it ( `works for ${ dirName } ` , async function ( ) {
76
72
let generator : $Generator | null = null ;
77
73
try {
78
74
// arrange
@@ -81,15 +77,17 @@ describe('generator', function () {
81
77
const inputDir = join ( caseDir , 'input' ) ;
82
78
83
79
const mockFsConfig : DirectoryItems = { [ baseOutputPath ] : { } } ;
84
- const configFilePath = join ( inputDir , 'config.js ' ) ;
80
+ const configFilePath = join ( inputDir , 'config.cjs ' ) ;
85
81
86
82
let configuredEndpoints : EndpointConfiguration [ ] | undefined = undefined ;
87
83
let hasConfiguredEndpoints = false ;
88
84
const args = [ '--outputDir' , baseOutputPath ] ;
89
- if ( await exists ( configFilePath ) ) {
85
+ if ( await mockFs . bypass ( ( ) => exists ( configFilePath ) ) ) {
90
86
args . unshift ( '--config' , configFilePath ) ;
91
87
mockFsConfig [ configFilePath ] = mockFs . load ( configFilePath ) ;
92
- configuredEndpoints = ( await import ( `file:///${ configFilePath } ` ) ) . endpoints ;
88
+ let importedConfig = await import ( `file:///${ configFilePath } ` ) ;
89
+ importedConfig = importedConfig . default ?? importedConfig ;
90
+ configuredEndpoints = importedConfig . endpoints ;
93
91
hasConfiguredEndpoints = Array . isArray ( configuredEndpoints ) && configuredEndpoints . length > 0 ;
94
92
}
95
93
if ( ! hasConfiguredEndpoints ) {
@@ -102,12 +100,11 @@ describe('generator', function () {
102
100
103
101
for ( const ep of configuration . endpoints ) {
104
102
let epInput = join ( inputDir , new URL ( ep . url ) . hostname ) ;
105
- epInput = await exists ( epInput ) ? epInput : inputDir ;
103
+ epInput = await mockFs . bypass ( ( ) => exists ( epInput ) ) ? epInput : inputDir ;
106
104
107
- const edmxXml = await fs . readFile ( join ( epInput , 'metadata.xml' ) , 'utf8' ) ;
108
- console . log ( '[test] edmxXml' , edmxXml ) ;
105
+ const edmxXml = await mockFs . bypass ( ( ) => fs . readFile ( join ( epInput , 'metadata.xml' ) , 'utf8' ) ) ;
109
106
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
110
- const endpoints : Endpoint [ ] = JSON . parse ( await fs . readFile ( join ( epInput , 'endpoints.json' ) , 'utf8' ) ) . value ;
107
+ const endpoints : Endpoint [ ] = JSON . parse ( await mockFs . bypass ( ( ) => fs . readFile ( join ( epInput , 'endpoints.json' ) , 'utf8' ) ) ) . value ;
111
108
112
109
// act
113
110
await generator . generateEndpointsFile ( endpoints , ep ) ;
0 commit comments