1
- var assert = require ( 'assert' ) ;
2
- var app = require ( './testapp/app' ) ;
3
- var http = require ( 'http' ) ;
4
- var phantom = require ( 'phantom' ) ;
1
+ const assert = require ( 'assert' ) ;
2
+ const app = require ( './testapp/app' ) ;
3
+ const puppeteer = require ( 'puppeteer' ) ;
5
4
require ( 'es6-shim' ) ;
6
5
7
6
describe ( 'integration' , function ( ) {
8
7
var server ;
8
+ var browser = null ;
9
9
var sitepage = null ;
10
- var phInstance = null ;
11
10
12
11
before ( function ( done ) {
13
12
app . set ( 'port' , 3001 ) ;
14
-
15
13
server = app . listen ( app . get ( 'port' ) , function ( ) {
16
14
done ( ) ;
17
15
} ) ;
18
16
} ) ;
19
17
20
- after ( function ( ) {
18
+ after ( async function ( ) {
21
19
server . close ( ) ;
22
- sitepage . close ( ) ;
23
- phInstance . exit ( ) ;
20
+ await sitepage . close ( ) ;
21
+ await browser . close ( ) ;
24
22
} ) ;
25
23
26
- it ( 'should have API Documentation hosted at /api-docs ' , function ( done ) {
24
+ it ( 'should intialize browser ' , async function ( ) {
27
25
this . timeout ( 30000 ) ;
28
- phantom . create ( )
29
- . then ( function ( instance ) {
30
- phInstance = instance ;
31
- return instance . createPage ( ) ;
32
- } )
33
- . then ( function ( page ) {
34
- sitepage = page ;
35
- return page . open ( 'http://localhost:3001/api-docs/' ) ;
36
- } )
37
- . then ( function ( status ) {
38
- setTimeout ( function ( ) {
39
- assert . equal ( 'success' , status ) ;
40
- done ( ) ;
41
- } , 100 ) ;
42
- } )
43
- . catch ( function ( err ) {
44
- done ( err ) ;
45
- } ) ;
26
+ browser = await puppeteer . launch ( ) ;
27
+ sitepage = await browser . newPage ( ) ;
28
+ } ) ;
29
+
30
+ it ( 'should have API Documentation hosted at /api-docs' , async function ( ) {
31
+ const httpResponse = await sitepage . goto ( 'http://localhost:3001/api-docs/' ) ;
32
+ assert . ok ( httpResponse . ok ( ) ) ;
46
33
} ) ;
47
34
48
- it ( 'should contain the expected elements on the page' , function ( done ) {
49
- sitepage . property ( 'title' )
50
- . then ( function ( title ) {
51
- assert . equal ( 'Swagger UI' , title ) ;
52
- return sitepage . evaluate ( function ( ) {
53
- return document . querySelector ( '.swagger-ui' ) . innerHTML ;
54
- } ) ;
55
- } )
56
- . then ( function ( html ) {
57
- assert . ok ( html ) ;
58
- assert . notEqual ( html . indexOf ( 'id="operations-/test-index"' ) , - 1 ) ;
59
- assert . notEqual ( html . indexOf ( 'id="operations-/test-impossible"' ) , - 1 ) ;
60
- done ( ) ;
61
- } )
62
- . catch ( function ( err ) {
63
- done ( err ) ;
64
- } ) ;
35
+ it ( 'should contain the expected elements on the page from /api-docs' , async function ( ) {
36
+ await sitepage . waitForSelector ( '.information-container' , { timeout : 2000 } ) ;
37
+ assert . equal ( 'Swagger UI' , await sitepage . title ( ) ) ;
38
+ const html = await sitepage . evaluate ( ( ) => document . querySelector ( '.swagger-ui' ) . innerHTML ) ;
39
+ assert . ok ( html ) ;
40
+ assert . notEqual ( html . indexOf ( "id=\"operations-\\/test-index\"" ) , - 1 ) ;
41
+ assert . notEqual ( html . indexOf ( "id=\"operations-\\/test-impossible\"" ) , - 1 ) ;
65
42
} ) ;
66
43
67
- it ( 'should have API Documentation hosted at /api-docs-from-url' , function ( done ) {
68
- sitepage . open ( 'http://localhost:3001/api-docs-from-url/' )
69
- . then ( function ( status ) {
70
- setTimeout ( function ( ) {
71
- assert . equal ( 'success' , status ) ;
72
- done ( ) ;
73
- } , 100 ) ;
74
- } )
75
- . catch ( function ( err ) {
76
- done ( err ) ;
77
- } ) ;
44
+ it ( 'should have API Documentation hosted at /api-docs-from-url' , async function ( ) {
45
+ const httpResponse = await sitepage . goto ( 'http://localhost:3001/api-docs-from-url/' ) ;
46
+ assert . ok ( httpResponse . ok ( ) ) ;
78
47
} ) ;
79
48
80
- it ( 'should contain the expected elements on the page' , function ( done ) {
81
- sitepage . property ( 'title' )
82
- . then ( function ( title ) {
83
- assert . equal ( 'Swagger UI' , title ) ;
84
- return sitepage . evaluate ( function ( ) {
85
- return document . querySelector ( '.swagger-ui' ) . innerHTML ;
86
- } ) ;
87
- } )
88
- . then ( function ( html ) {
89
- assert . ok ( html ) ;
90
- assert . notEqual ( html . indexOf ( 'id="operations-/test-index"' ) , - 1 ) ;
91
- assert . notEqual ( html . indexOf ( 'id="operations-/test-impossible"' ) , - 1 ) ;
92
- done ( ) ;
93
- } )
94
- . catch ( function ( err ) {
95
- done ( err ) ;
96
- } ) ;
49
+ it ( 'should contain the expected elements on the page from /api-docs-from-url' , async function ( ) {
50
+ await sitepage . waitForSelector ( '.information-container' , { timeout : 2000 } ) ;
51
+ assert . equal ( 'Swagger UI' , await sitepage . title ( ) ) ;
52
+ const html = await sitepage . evaluate ( ( ) => document . querySelector ( '.swagger-ui' ) . innerHTML ) ;
53
+ assert . ok ( html ) ;
54
+ // console.log(`**** ${html}`);
55
+ assert . notEqual ( html . indexOf ( "id=\"operations-\\/test-index\"" ) , - 1 ) ;
56
+ assert . notEqual ( html . indexOf ( "id=\"operations-\\/test-impossible\"" ) , - 1 ) ;
97
57
} ) ;
98
58
99
- it ( 'should have API Documentation hosted at /api-docs-using-object' , function ( done ) {
100
- sitepage . open ( 'http://localhost:3001/api-docs-using-object/' )
101
- . then ( function ( status ) {
102
- setTimeout ( function ( ) {
103
- assert . equal ( 'success' , status ) ;
104
- done ( ) ;
105
- } , 100 ) ;
106
- } )
107
- . catch ( function ( err ) {
108
- done ( err ) ;
109
- } ) ;
59
+ it ( 'should have API Documentation hosted at /api-docs-using-object' , async function ( ) {
60
+ const httpResponse = await sitepage . goto ( 'http://localhost:3001/api-docs-using-object/' ) ;
61
+ assert . ok ( httpResponse . ok ( ) ) ;
110
62
} ) ;
111
63
112
- it ( 'should contain the expected elements on the page for api-docs-using-object' , function ( done ) {
113
- sitepage . property ( 'title' )
114
- . then ( function ( title ) {
115
- assert . equal ( 'Swagger UI' , title ) ;
116
- return sitepage . evaluate ( function ( ) {
117
- return document . querySelector ( '.swagger-ui' ) . innerHTML ;
118
- } ) ;
119
- } )
120
- . then ( function ( html ) {
121
- assert . ok ( html ) ;
122
- assert . notEqual ( html . indexOf ( 'id="operations-/test-index"' ) , - 1 ) ;
123
- assert . notEqual ( html . indexOf ( 'id="operations-/test-impossible"' ) , - 1 ) ;
124
- done ( ) ;
125
- } )
126
- . catch ( function ( err ) {
127
- done ( err ) ;
128
- } ) ;
64
+ it ( 'should contain the expected elements on the page for api-docs-using-object' , async function ( ) {
65
+ await sitepage . waitForSelector ( '.information-container' , { timeout : 2000 } ) ;
66
+ assert . equal ( 'Swagger UI' , await sitepage . title ( ) ) ;
67
+ const html = await sitepage . evaluate ( ( ) => document . querySelector ( '.swagger-ui' ) . innerHTML ) ;
68
+ assert . ok ( html ) ;
69
+ assert . notEqual ( html . indexOf ( "id=\"operations-\\/test-index\"" ) , - 1 ) ;
70
+ assert . notEqual ( html . indexOf ( "id=\"operations-\\/test-impossible\"" ) , - 1 ) ;
129
71
} ) ;
130
72
131
- it ( 'should have API Documentation hosted at /api-docs-with-null' , function ( done ) {
132
- sitepage . open ( 'http://localhost:3001/api-docs-with-null/' )
133
- . then ( function ( status ) {
134
- setTimeout ( function ( ) {
135
- assert . equal ( 'success' , status ) ;
136
- done ( ) ;
137
- } , 100 ) ;
138
- } )
139
- . catch ( function ( err ) {
140
- done ( err ) ;
141
- } ) ;
73
+ it ( 'should have API Documentation hosted at /api-docs-with-null' , async function ( ) {
74
+ const httpResponse = await sitepage . goto ( 'http://localhost:3001/api-docs-with-null/' ) ;
75
+ assert . ok ( httpResponse . ok ( ) ) ;
142
76
} ) ;
143
77
144
- it ( 'should contain the expected elements on the page for api-docs-with-null' , function ( done ) {
145
- sitepage . property ( 'title' )
146
- . then ( function ( title ) {
147
- assert . equal ( 'Swagger UI' , title ) ;
148
- return sitepage . evaluate ( function ( ) {
149
- return document . querySelector ( '.swagger-ui' ) . innerHTML ;
150
- } ) ;
151
- } )
152
- . then ( function ( html ) {
153
- assert . ok ( html ) ;
154
- assert . notEqual ( html . indexOf ( 'id="operations-/test-index"' ) , - 1 ) ;
155
- assert . notEqual ( html . indexOf ( 'id="operations-/test-impossible"' ) , - 1 ) ;
156
- done ( ) ;
157
- } )
158
- . catch ( function ( err ) {
159
- done ( err ) ;
160
- } ) ;
78
+ it ( 'should contain the expected elements on the page for api-docs-with-null' , async function ( ) {
79
+ await sitepage . waitForSelector ( '.information-container' , { timeout : 2000 } ) ;
80
+ assert . equal ( 'Swagger UI' , await sitepage . title ( ) ) ;
81
+ const html = await sitepage . evaluate ( ( ) => document . querySelector ( '.swagger-ui' ) . innerHTML ) ;
82
+ assert . ok ( html ) ;
83
+ assert . notEqual ( html . indexOf ( "id=\"operations-\\/test-index\"" ) , - 1 ) ;
84
+ assert . notEqual ( html . indexOf ( "id=\"operations-\\/test-impossible\"" ) , - 1 ) ;
161
85
} ) ;
162
86
163
- it ( 'should not leak package.json' , function ( done ) {
164
- sitepage . open ( 'http://localhost:3001/api-docs/package.json' )
165
- . then ( ( ) => sitepage . evaluate ( function ( ) { return document . querySelector ( 'body' ) . innerText } ) )
166
- . then ( body => {
167
- assert . equal ( 'Not Found' , body ) ;
168
- done ( )
169
- } )
170
- . catch ( function ( err ) {
171
- done ( err ) ;
172
- } ) ;
87
+ it ( 'should not leak package.json' , async function ( ) {
88
+ await sitepage . goto ( 'http://localhost:3001/api-docs/package.json' ) ;
89
+ const body = await sitepage . evaluate ( ( ) => document . querySelector ( 'body' ) . innerText ) ;
90
+ assert . equal ( 'Not Found' , body ) ;
173
91
} ) ;
174
- } ) ;
92
+ } ) ;
0 commit comments