File tree Expand file tree Collapse file tree 3 files changed +22
-21
lines changed
packages/@vuepress/core/lib/node Expand file tree Collapse file tree 3 files changed +22
-21
lines changed Original file line number Diff line number Diff line change @@ -286,13 +286,17 @@ module.exports = class Page {
286286 */
287287
288288 async enhance ( enhancers ) {
289- for ( const { name : pluginName , value : enhancer } of enhancers ) {
290- try {
291- await enhancer ( this )
292- } catch ( error ) {
293- console . log ( error )
294- throw new Error ( `[${ pluginName } ] execute extendPageData failed.` )
295- }
296- }
289+ return Promise . all (
290+ enhancers . map (
291+ async ( { value : enhancer , name : pluginName } ) => {
292+ try {
293+ await enhancer ( this )
294+ } catch ( error ) {
295+ console . log ( error )
296+ throw new Error ( `[${ pluginName } ] execute extendPageData failed.` )
297+ }
298+ }
299+ )
300+ )
297301 }
298302}
Original file line number Diff line number Diff line change @@ -111,11 +111,11 @@ describe('Page', () => {
111111 page = new Page ( { path : '/' } , app )
112112 enhancers = [
113113 {
114- pluginName : 'foo' ,
114+ name : 'foo' ,
115115 value : jest . fn ( )
116116 } ,
117117 {
118- pluginName : 'foo ' ,
118+ name : 'bar ' ,
119119 value : jest . fn ( )
120120 }
121121 ]
@@ -130,21 +130,22 @@ describe('Page', () => {
130130
131131 test ( 'should loop over sync and async enhancers' , async ( ) => {
132132 const mixedEnhancers = [ ...enhancers , {
133- pluginName : 'blog' ,
133+ name : 'blog' ,
134134 value : jest . fn ( ) . mockResolvedValue ( { } )
135135 } ]
136136 await page . enhance ( mixedEnhancers )
137137
138138 return mixedEnhancers . map ( enhancer => expect ( enhancer . value ) . toHaveBeenCalled ( ) )
139139 } )
140140
141- test ( 'should log when enhancing when failing ' , async ( ) => {
141+ test ( 'should log and throw an error when enhancing fails ' , async ( ) => {
142142 const error = { errorMessage : 'this is an error message' }
143+ const pluginName = 'error-plugin'
143144
144145 await expect ( page . enhance ( [ {
145- pluginName : 'error-plugin' ,
146+ name : pluginName ,
146147 value : jest . fn ( ) . mockRejectedValue ( error )
147- } ] ) ) . rejects . toThrow ( )
148+ } ] ) ) . rejects . toThrowError ( `[ ${ pluginName } ] execute extendPageData failed.` )
148149
149150 expect ( console . log ) . toHaveBeenCalledWith ( error )
150151 } )
Original file line number Diff line number Diff line change @@ -89,10 +89,9 @@ module.exports = class Build extends EventEmitter {
8989 // render pages
9090 logger . wait ( 'Rendering static HTML...' )
9191
92- const pagePaths = [ ]
93- for ( const page of this . context . pages ) {
94- pagePaths . push ( await this . renderPage ( page ) )
95- }
92+ const pagePaths = await Promise . all (
93+ this . context . pages . map ( page => this . renderPage ( page ) )
94+ )
9695
9796 readline . clearLine ( process . stdout , 0 )
9897 readline . cursorTo ( process . stdout , 0 )
@@ -134,9 +133,6 @@ module.exports = class Build extends EventEmitter {
134133
135134 async renderPage ( page ) {
136135 const pagePath = decodeURIComponent ( page . path )
137- readline . clearLine ( process . stdout , 0 )
138- readline . cursorTo ( process . stdout , 0 )
139- process . stdout . write ( `Rendering page: ${ pagePath } ` )
140136
141137 // #565 Avoid duplicate description meta at SSR.
142138 const meta = ( page . frontmatter && page . frontmatter . meta || [ ] ) . filter ( item => item . name !== 'description' )
You can’t perform that action at this time.
0 commit comments