@@ -6,37 +6,39 @@ const path = require('path')
66const fs = require ( 'fs-then-native' )
77const a = require ( 'assert' )
88
9- const runner = new TestRunner ( )
9+ /* needs to be sequence as `jsdoc.cache` is shared between tests */
10+ const runner = new TestRunner ( { sequential : true } )
1011
11- runner . test ( '.explainSync({ files, cache: true })' , function ( ) {
12+ runner . test ( 'caching: .explainSync({ files, cache: true })' , function ( ) {
1213 const f = new Fixture ( 'class-all' )
1314 jsdoc . cache . dir = 'tmp/cache-sync'
14- jsdoc . cache . clear ( ) . catch ( err => { /* ignore */ } )
15- const output = jsdoc . explainSync ( { files : f . sourcePath , cache : true } )
16- const expectedOutput = f . getExpectedOutput ( output )
15+ return jsdoc . cache . clear ( )
16+ . then ( ( ) => {
17+ const output = jsdoc . explainSync ( { files : f . sourcePath , cache : true } )
18+ const expectedOutput = f . getExpectedOutput ( output )
1719
18- a . ok ( typeof output === 'object' )
19- a . deepEqual ( output , expectedOutput )
20+ a . ok ( typeof output === 'object' )
21+ a . deepEqual ( output , expectedOutput )
22+ } )
2023} )
2124
22- runner . test ( '.explain({ files, cache: true })' , function ( ) {
25+ runner . test ( 'caching: .explain({ files, cache: true })' , function ( ) {
2326 const f = new Fixture ( 'class-all' )
2427 jsdoc . cache . dir = 'tmp/cache'
25- jsdoc . cache . clear ( ) . catch ( err => { /* ignore */ } )
26- return jsdoc . explain ( { files : f . sourcePath , cache : true } )
27- . then ( function ( output ) {
28- const cachedFiles = fs . readdirSync ( jsdoc . cache . dir )
29- . map ( function ( file ) {
30- return path . resolve ( jsdoc . cache . dir , file )
28+ return jsdoc . cache . clear ( )
29+ . then ( ( ) => {
30+ return jsdoc . explain ( { files : f . sourcePath , cache : true } )
31+ . then ( output => {
32+ const cachedFiles = fs . readdirSync ( jsdoc . cache . dir )
33+ . map ( file => path . resolve ( jsdoc . cache . dir , file ) )
34+ a . strictEqual ( cachedFiles . length , 1 )
35+ a . deepEqual ( output , f . getExpectedOutput ( output ) )
36+ const cachedData = JSON . parse ( fs . readFileSync ( cachedFiles [ 0 ] , 'utf8' ) )
37+ Fixture . removeFileSpecificData ( cachedData )
38+ a . deepEqual (
39+ cachedData ,
40+ f . getExpectedOutput ( output )
41+ )
3142 } )
32- a . strictEqual ( cachedFiles . length , 1 )
33- a . deepEqual ( output , f . getExpectedOutput ( output ) )
34- const cachedData = JSON . parse ( fs . readFileSync ( cachedFiles [ 0 ] , 'utf8' ) )
35- Fixture . removeFileSpecificData ( cachedData )
36- a . deepEqual (
37- cachedData ,
38- f . getExpectedOutput ( output )
39- )
4043 } )
41- . catch ( function ( err ) { console . error ( err . stack ) } )
4244} )
0 commit comments