@@ -32,7 +32,7 @@ require('acquit-ignore')();
32
32
const { marked : markdown } = require ( 'marked' ) ;
33
33
const highlight = require ( 'highlight.js' ) ;
34
34
const { promisify } = require ( "util" ) ;
35
- const renderer = {
35
+ markdown . use ( {
36
36
heading : function ( text , level , raw , slugger ) {
37
37
const slug = slugger . slug ( raw ) ;
38
38
return `<h${ level } id="${ slug } ">
@@ -41,7 +41,7 @@ const renderer = {
41
41
</a>
42
42
</h${ level } >\n` ;
43
43
}
44
- } ;
44
+ } ) ;
45
45
markdown . setOptions ( {
46
46
highlight : function ( code , language ) {
47
47
if ( ! language ) {
@@ -53,29 +53,45 @@ markdown.setOptions({
53
53
return highlight . highlight ( code , { language } ) . value ;
54
54
}
55
55
} ) ;
56
- markdown . use ( { renderer } ) ;
57
-
58
- const testPath = path . resolve ( cwd , 'test' )
59
-
60
- const tests = [
61
- ...acquit . parse ( fs . readFileSync ( path . join ( testPath , 'geojson.test.js' ) ) . toString ( ) ) ,
62
- ...acquit . parse ( fs . readFileSync ( path . join ( testPath , 'docs/transactions.test.js' ) ) . toString ( ) ) ,
63
- ...acquit . parse ( fs . readFileSync ( path . join ( testPath , 'schema.alias.test.js' ) ) . toString ( ) ) ,
64
- ...acquit . parse ( fs . readFileSync ( path . join ( testPath , 'model.middleware.test.js' ) ) . toString ( ) ) ,
65
- ...acquit . parse ( fs . readFileSync ( path . join ( testPath , 'docs/date.test.js' ) ) . toString ( ) ) ,
66
- ...acquit . parse ( fs . readFileSync ( path . join ( testPath , 'docs/lean.test.js' ) ) . toString ( ) ) ,
67
- ...acquit . parse ( fs . readFileSync ( path . join ( testPath , 'docs/cast.test.js' ) ) . toString ( ) ) ,
68
- ...acquit . parse ( fs . readFileSync ( path . join ( testPath , 'docs/findoneandupdate.test.js' ) ) . toString ( ) ) ,
69
- ...acquit . parse ( fs . readFileSync ( path . join ( testPath , 'docs/custom-casting.test.js' ) ) . toString ( ) ) ,
70
- ...acquit . parse ( fs . readFileSync ( path . join ( testPath , 'docs/getters-setters.test.js' ) ) . toString ( ) ) ,
71
- ...acquit . parse ( fs . readFileSync ( path . join ( testPath , 'docs/virtuals.test.js' ) ) . toString ( ) ) ,
72
- ...acquit . parse ( fs . readFileSync ( path . join ( testPath , 'docs/defaults.test.js' ) ) . toString ( ) ) ,
73
- ...acquit . parse ( fs . readFileSync ( path . join ( testPath , 'docs/discriminators.test.js' ) ) . toString ( ) ) ,
74
- ...acquit . parse ( fs . readFileSync ( path . join ( testPath , 'docs/promises.test.js' ) ) . toString ( ) ) ,
75
- ...acquit . parse ( fs . readFileSync ( path . join ( testPath , 'docs/schematypes.test.js' ) ) . toString ( ) ) ,
76
- ...acquit . parse ( fs . readFileSync ( path . join ( testPath , 'docs/validation.test.js' ) ) . toString ( ) ) ,
77
- ...acquit . parse ( fs . readFileSync ( path . join ( testPath , 'docs/schemas.test.js' ) ) . toString ( ) )
56
+
57
+ const testPath = path . resolve ( cwd , 'test' ) ;
58
+
59
+ /** additional test files to scan, relative to `test/` */
60
+ const additionalTestFiles = [
61
+ 'geojson.test.js' ,
62
+ 'schema.alias.test.js'
78
63
] ;
64
+ /** ignored files from `test/docs/` */
65
+ const ignoredTestFiles = [
66
+ // ignored because acquit does not like "for await"
67
+ 'asyncIterator.test.js'
68
+ ] ;
69
+
70
+ /**
71
+ * Load all test file contents with acquit
72
+ * @returns {Object[] } acquit ast array
73
+ */
74
+ function getTests ( ) {
75
+ const testDocs = path . resolve ( testPath , 'docs' ) ;
76
+ const filesToScan = [
77
+ ...additionalTestFiles . map ( v => path . join ( testPath , v ) ) ,
78
+ ...fs . readdirSync ( testDocs ) . filter ( v => ! ignoredTestFiles . includes ( v ) ) . map ( v => path . join ( testDocs , v ) )
79
+ ] ;
80
+
81
+ const retArray = [ ] ;
82
+
83
+ for ( const file of filesToScan ) {
84
+ try {
85
+ retArray . push ( acquit . parse ( fs . readFileSync ( file ) . toString ( ) ) ) ;
86
+ } catch ( err ) {
87
+ // add a file path to a acquit error, for better debugging
88
+ err . filePath = file ;
89
+ throw err ;
90
+ }
91
+ }
92
+
93
+ return retArray . flat ( ) ;
94
+ }
79
95
80
96
function deleteAllHtmlFiles ( ) {
81
97
try {
@@ -407,7 +423,7 @@ async function pugify(filename, options, isReload = false) {
407
423
let contents = fs . readFileSync ( path . resolve ( cwd , inputFile ) ) . toString ( ) ;
408
424
409
425
if ( options . acquit ) {
410
- contents = transform ( contents , tests ) ;
426
+ contents = transform ( contents , getTests ( ) ) ;
411
427
412
428
contents = contents . replaceAll ( / ^ ` ` ` a c q u i t $ / gmi, "```javascript" ) ;
413
429
}
@@ -466,7 +482,7 @@ async function pugify(filename, options, isReload = false) {
466
482
} ) ;
467
483
}
468
484
469
- // extra function to start watching for file-changes, without having to call this file directly with "watch"
485
+ /** extra function to start watching for file-changes, without having to call this file directly with "watch" */
470
486
function startWatch ( ) {
471
487
Object . entries ( docsFilemap . fileMap ) . forEach ( ( [ file , fileValue ] ) => {
472
488
let watchPath = path . resolve ( cwd , file ) ;
@@ -534,7 +550,7 @@ const pathsToCopy = [
534
550
'docs/js' ,
535
551
'docs/css' ,
536
552
'docs/images'
537
- ]
553
+ ] ;
538
554
539
555
/** Copy all static files when versionedDeploy is used */
540
556
async function copyAllRequiredFiles ( ) {
0 commit comments