@@ -32,7 +32,7 @@ require('acquit-ignore')();
3232const { marked : markdown } = require ( 'marked' ) ;
3333const highlight = require ( 'highlight.js' ) ;
3434const { promisify } = require ( "util" ) ;
35- const renderer = {
35+ markdown . use ( {
3636 heading : function ( text , level , raw , slugger ) {
3737 const slug = slugger . slug ( raw ) ;
3838 return `<h${ level } id="${ slug } ">
@@ -41,7 +41,7 @@ const renderer = {
4141 </a>
4242 </h${ level } >\n` ;
4343 }
44- } ;
44+ } ) ;
4545markdown . setOptions ( {
4646 highlight : function ( code , language ) {
4747 if ( ! language ) {
@@ -53,29 +53,45 @@ markdown.setOptions({
5353 return highlight . highlight ( code , { language } ) . value ;
5454 }
5555} ) ;
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'
7863] ;
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+ }
7995
8096function deleteAllHtmlFiles ( ) {
8197 try {
@@ -407,7 +423,7 @@ async function pugify(filename, options, isReload = false) {
407423 let contents = fs . readFileSync ( path . resolve ( cwd , inputFile ) ) . toString ( ) ;
408424
409425 if ( options . acquit ) {
410- contents = transform ( contents , tests ) ;
426+ contents = transform ( contents , getTests ( ) ) ;
411427
412428 contents = contents . replaceAll ( / ^ ` ` ` a c q u i t $ / gmi, "```javascript" ) ;
413429 }
@@ -466,7 +482,7 @@ async function pugify(filename, options, isReload = false) {
466482 } ) ;
467483}
468484
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" */
470486function startWatch ( ) {
471487 Object . entries ( docsFilemap . fileMap ) . forEach ( ( [ file , fileValue ] ) => {
472488 let watchPath = path . resolve ( cwd , file ) ;
@@ -534,7 +550,7 @@ const pathsToCopy = [
534550 'docs/js' ,
535551 'docs/css' ,
536552 'docs/images'
537- ]
553+ ] ;
538554
539555/** Copy all static files when versionedDeploy is used */
540556async function copyAllRequiredFiles ( ) {
0 commit comments