@@ -55,25 +55,50 @@ markdown.setOptions({
55
55
56
56
const testPath = path . resolve ( cwd , 'test' )
57
57
58
- const tests = [
59
- ...acquit . parse ( fs . readFileSync ( path . join ( testPath , 'geojson.test.js' ) ) . toString ( ) ) ,
60
- ...acquit . parse ( fs . readFileSync ( path . join ( testPath , 'docs/transactions.test.js' ) ) . toString ( ) ) ,
61
- ...acquit . parse ( fs . readFileSync ( path . join ( testPath , 'schema.alias.test.js' ) ) . toString ( ) ) ,
62
- ...acquit . parse ( fs . readFileSync ( path . join ( testPath , 'model.middleware.test.js' ) ) . toString ( ) ) ,
63
- ...acquit . parse ( fs . readFileSync ( path . join ( testPath , 'docs/date.test.js' ) ) . toString ( ) ) ,
64
- ...acquit . parse ( fs . readFileSync ( path . join ( testPath , 'docs/lean.test.js' ) ) . toString ( ) ) ,
65
- ...acquit . parse ( fs . readFileSync ( path . join ( testPath , 'docs/cast.test.js' ) ) . toString ( ) ) ,
66
- ...acquit . parse ( fs . readFileSync ( path . join ( testPath , 'docs/findoneandupdate.test.js' ) ) . toString ( ) ) ,
67
- ...acquit . parse ( fs . readFileSync ( path . join ( testPath , 'docs/custom-casting.test.js' ) ) . toString ( ) ) ,
68
- ...acquit . parse ( fs . readFileSync ( path . join ( testPath , 'docs/getters-setters.test.js' ) ) . toString ( ) ) ,
69
- ...acquit . parse ( fs . readFileSync ( path . join ( testPath , 'docs/virtuals.test.js' ) ) . toString ( ) ) ,
70
- ...acquit . parse ( fs . readFileSync ( path . join ( testPath , 'docs/defaults.test.js' ) ) . toString ( ) ) ,
71
- ...acquit . parse ( fs . readFileSync ( path . join ( testPath , 'docs/discriminators.test.js' ) ) . toString ( ) ) ,
72
- ...acquit . parse ( fs . readFileSync ( path . join ( testPath , 'docs/promises.test.js' ) ) . toString ( ) ) ,
73
- ...acquit . parse ( fs . readFileSync ( path . join ( testPath , 'docs/schematypes.test.js' ) ) . toString ( ) ) ,
74
- ...acquit . parse ( fs . readFileSync ( path . join ( testPath , 'docs/validation.test.js' ) ) . toString ( ) ) ,
75
- ...acquit . parse ( fs . readFileSync ( path . join ( testPath , 'docs/schemas.test.js' ) ) . toString ( ) )
58
+ /** additional test files to scan, relative to `test/` */
59
+ const additionalTestFiles = [
60
+ 'geojson.test.js' ,
61
+ 'schema.alias.test.js'
76
62
] ;
63
+ /** ignored files from `test/docs/` */
64
+ const ignoredTestFiles = [
65
+ // ignored because acquit does not like "for await"
66
+ 'asyncIterator.test.js'
67
+ ] ;
68
+
69
+ /**
70
+ * Load all test file contents with acquit
71
+ * @returns {Object[] } acquit ast array
72
+ */
73
+ async function getTests ( ) {
74
+ const promiseArray = [ ] ;
75
+
76
+ for ( const file of additionalTestFiles ) {
77
+ const filePath = path . join ( testPath , file ) ;
78
+ promiseArray . push ( fs . promises . readFile ( filePath ) . then ( v => ( { value : v . toString ( ) , path : filePath } ) ) ) ;
79
+ }
80
+
81
+ const testDocs = path . resolve ( testPath , 'docs' ) ;
82
+
83
+ for ( const file of await fs . promises . readdir ( testDocs ) ) {
84
+ if ( ignoredTestFiles . includes ( file ) ) {
85
+ continue ;
86
+ }
87
+
88
+ const filePath = path . join ( testDocs , file ) ;
89
+ promiseArray . push ( fs . promises . readFile ( filePath ) . then ( v => ( { value : v . toString ( ) , path : filePath } ) ) ) ;
90
+ }
91
+
92
+ return ( await Promise . all ( promiseArray ) ) . flatMap ( v => {
93
+ try {
94
+ return acquit . parse ( v . value ) ;
95
+ } catch ( err ) {
96
+ // add a file path to a acquit error, for better debugging
97
+ err . filePath = v . path ;
98
+ throw err ;
99
+ }
100
+ } )
101
+ }
77
102
78
103
/**
79
104
* Array of array of semver numbers, sorted with highest number first
@@ -351,7 +376,7 @@ async function pugify(filename, options, isReload = false) {
351
376
let contents = fs . readFileSync ( path . resolve ( cwd , inputFile ) ) . toString ( ) ;
352
377
353
378
if ( options . acquit ) {
354
- contents = transform ( contents , tests ) ;
379
+ contents = transform ( contents , await getTests ( ) ) ;
355
380
356
381
contents = contents . replaceAll ( / ^ ` ` ` a c q u i t $ / gmi, "```javascript" ) ;
357
382
}
0 commit comments