@@ -80,6 +80,48 @@ describe('preprocessor', () => {
8080 } )
8181 } )
8282
83+ it ( 'should get content if preprocessor is an async function or return Promise with content' , ( done ) => {
84+ const fakePreprocessor = sinon . spy ( async ( content , file , done ) => {
85+ file . path = file . path + '-preprocessed'
86+ return 'new-content'
87+ } )
88+
89+ const injector = new di . Injector ( [ {
90+ 'preprocessor:fake' : [ 'factory' , function ( ) { return fakePreprocessor } ]
91+ } , emitterSetting ] )
92+ pp = m . createPriorityPreprocessor ( { '**/*.js' : [ 'fake' ] } , { } , null , injector )
93+
94+ const file = { originalPath : '/some/.dir/a.js' , path : 'path' }
95+
96+ pp ( file , ( ) => {
97+ expect ( fakePreprocessor ) . to . have . been . called
98+ expect ( file . path ) . to . equal ( 'path-preprocessed' )
99+ expect ( file . content ) . to . equal ( 'new-content' )
100+ done ( )
101+ } )
102+ } )
103+
104+ it ( 'should get content if preprocessor is an async function still calling done()' , ( done ) => {
105+ const fakePreprocessor = sinon . spy ( async ( content , file , done ) => {
106+ file . path = file . path + '-preprocessed'
107+ done ( null , 'new-content' )
108+ } )
109+
110+ const injector = new di . Injector ( [ {
111+ 'preprocessor:fake' : [ 'factory' , function ( ) { return fakePreprocessor } ]
112+ } , emitterSetting ] )
113+ pp = m . createPriorityPreprocessor ( { '**/*.js' : [ 'fake' ] } , { } , null , injector )
114+
115+ const file = { originalPath : '/some/.dir/a.js' , path : 'path' }
116+
117+ pp ( file , ( ) => {
118+ expect ( fakePreprocessor ) . to . have . been . called
119+ expect ( file . path ) . to . equal ( 'path-preprocessed' )
120+ expect ( file . content ) . to . equal ( 'new-content' )
121+ done ( )
122+ } )
123+ } )
124+
83125 it ( 'should check patterns after creation when invoked' , ( done ) => {
84126 const fakePreprocessor = sinon . spy ( ( content , file , done ) => {
85127 file . path = file . path + '-preprocessed'
0 commit comments