@@ -3,64 +3,146 @@ import docsifyInit from '../helpers/docsify-init.js';
3
3
import { test , expect } from './fixtures/docsify-init-fixture.js' ;
4
4
5
5
test . describe ( 'Configuration options' , ( ) => {
6
- test ( 'catchPluginErrors:true (handles uncaught errors)' , async ( { page } ) => {
7
- let consoleMsg , errorMsg ;
8
-
9
- page . on ( 'console' , msg => ( consoleMsg = msg . text ( ) ) ) ;
10
- page . on ( 'pageerror' , err => ( errorMsg = err . message ) ) ;
11
-
12
- await docsifyInit ( {
13
- config : {
14
- catchPluginErrors : true ,
15
- plugins : [
16
- function ( hook , vm ) {
17
- hook . init ( function ( ) {
18
- fail ( ) ;
19
- } ) ;
20
- hook . beforeEach ( markdown => {
21
- return `${ markdown } \n\nbeforeEach` ;
22
- } ) ;
23
- } ,
24
- ] ,
25
- } ,
26
- markdown : {
27
- homepage : '# Hello World' ,
28
- } ,
29
- // _logHTML: true,
6
+ test . describe ( 'catchPluginErrors' , ( ) => {
7
+ test ( 'true (handles uncaught errors)' , async ( { page } ) => {
8
+ let consoleMsg , errorMsg ;
9
+
10
+ page . on ( 'console' , msg => ( consoleMsg = msg . text ( ) ) ) ;
11
+ page . on ( 'pageerror' , err => ( errorMsg = err . message ) ) ;
12
+
13
+ await docsifyInit ( {
14
+ config : {
15
+ catchPluginErrors : true ,
16
+ plugins : [
17
+ function ( hook , vm ) {
18
+ hook . init ( function ( ) {
19
+ fail ( ) ;
20
+ } ) ;
21
+ hook . beforeEach ( markdown => {
22
+ return `${ markdown } \n\nbeforeEach` ;
23
+ } ) ;
24
+ } ,
25
+ ] ,
26
+ } ,
27
+ markdown : {
28
+ homepage : '# Hello World' ,
29
+ } ,
30
+ // _logHTML: true,
31
+ } ) ;
32
+
33
+ const mainElm = page . locator ( '#main' ) ;
34
+
35
+ expect ( errorMsg ) . toBeUndefined ( ) ;
36
+ expect ( consoleMsg ) . toContain ( 'Docsify plugin error' ) ;
37
+ await expect ( mainElm ) . toContainText ( 'Hello World' ) ;
38
+ await expect ( mainElm ) . toContainText ( 'beforeEach' ) ;
30
39
} ) ;
31
40
32
- const mainElm = page . locator ( '#main' ) ;
41
+ test ( 'false (throws uncaught errors)' , async ( { page } ) => {
42
+ let consoleMsg , errorMsg ;
43
+
44
+ page . on ( 'console' , msg => ( consoleMsg = msg . text ( ) ) ) ;
45
+ page . on ( 'pageerror' , err => ( errorMsg = err . message ) ) ;
33
46
34
- expect ( errorMsg ) . toBeUndefined ( ) ;
35
- expect ( consoleMsg ) . toContain ( 'Docsify plugin error' ) ;
36
- await expect ( mainElm ) . toContainText ( 'Hello World' ) ;
37
- await expect ( mainElm ) . toContainText ( 'beforeEach' ) ;
47
+ await docsifyInit ( {
48
+ config : {
49
+ catchPluginErrors : false ,
50
+ plugins : [
51
+ function ( hook , vm ) {
52
+ hook . ready ( function ( ) {
53
+ fail ( ) ;
54
+ } ) ;
55
+ } ,
56
+ ] ,
57
+ } ,
58
+ markdown : {
59
+ homepage : '# Hello World' ,
60
+ } ,
61
+ // _logHTML: true,
62
+ } ) ;
63
+
64
+ expect ( consoleMsg ) . toBeUndefined ( ) ;
65
+ expect ( errorMsg ) . toContain ( 'fail' ) ;
66
+ } ) ;
38
67
} ) ;
39
68
40
- test ( 'catchPluginErrors:false (throws uncaught errors)' , async ( { page } ) => {
41
- let consoleMsg , errorMsg ;
69
+ test . describe ( 'notFoundPage' , ( ) => {
70
+ test . describe ( 'renders default error content' , ( ) => {
71
+ test . beforeEach ( async ( { page } ) => {
72
+ await page . route ( 'README.md' , async route => {
73
+ await route . fulfill ( {
74
+ status : 500 ,
75
+ } ) ;
76
+ } ) ;
77
+ } ) ;
78
+
79
+ test ( 'false' , async ( { page } ) => {
80
+ await docsifyInit ( {
81
+ config : {
82
+ notFoundPage : false ,
83
+ } ,
84
+ } ) ;
42
85
43
- page . on ( 'console' , msg => ( consoleMsg = msg . text ( ) ) ) ;
44
- page . on ( 'pageerror' , err => ( errorMsg = err . message ) ) ;
86
+ await expect ( page . locator ( '#main' ) ) . toContainText ( '500' ) ;
87
+ } ) ;
45
88
46
- await docsifyInit ( {
47
- config : {
48
- catchPluginErrors : false ,
49
- plugins : [
50
- function ( hook , vm ) {
51
- hook . ready ( function ( ) {
52
- fail ( ) ;
53
- } ) ;
89
+ test ( 'true with non-404 error' , async ( { page } ) => {
90
+ await docsifyInit ( {
91
+ config : {
92
+ notFoundPage : true ,
93
+ } ,
94
+ routes : {
95
+ '_404.md' : '' ,
54
96
} ,
55
- ] ,
56
- } ,
57
- markdown : {
58
- homepage : '# Hello World' ,
59
- } ,
60
- // _logHTML: true,
97
+ } ) ;
98
+
99
+ await expect ( page . locator ( '#main' ) ) . toContainText ( '500' ) ;
100
+ } ) ;
101
+
102
+ test ( 'string with non-404 error' , async ( { page } ) => {
103
+ await docsifyInit ( {
104
+ config : {
105
+ notFoundPage : '404.md' ,
106
+ } ,
107
+ routes : {
108
+ '404.md' : '' ,
109
+ } ,
110
+ } ) ;
111
+
112
+ await expect ( page . locator ( '#main' ) ) . toContainText ( '500' ) ;
113
+ } ) ;
61
114
} ) ;
62
115
63
- expect ( consoleMsg ) . toBeUndefined ( ) ;
64
- expect ( errorMsg ) . toContain ( 'fail' ) ;
116
+ test ( 'true: renders _404.md page' , async ( { page } ) => {
117
+ const expectText = 'Pass' ;
118
+
119
+ await docsifyInit ( {
120
+ config : {
121
+ notFoundPage : true ,
122
+ } ,
123
+ routes : {
124
+ '_404.md' : expectText ,
125
+ } ,
126
+ } ) ;
127
+
128
+ await page . evaluate ( ( ) => ( window . location . hash = '#/fail' ) ) ;
129
+ await expect ( page . locator ( '#main' ) ) . toContainText ( expectText ) ;
130
+ } ) ;
131
+
132
+ test ( 'string: renders specified 404 page' , async ( { page } ) => {
133
+ const expectText = 'Pass' ;
134
+
135
+ await docsifyInit ( {
136
+ config : {
137
+ notFoundPage : '404.md' ,
138
+ } ,
139
+ routes : {
140
+ '404.md' : expectText ,
141
+ } ,
142
+ } ) ;
143
+
144
+ await page . evaluate ( ( ) => ( window . location . hash = '#/fail' ) ) ;
145
+ await expect ( page . locator ( '#main' ) ) . toContainText ( expectText ) ;
146
+ } ) ;
65
147
} ) ;
66
148
} ) ;
0 commit comments