@@ -8,6 +8,7 @@ const Camera = require('lib/browser/camera');
88const ClientBridge = require ( 'lib/browser/client-bridge' ) ;
99const Calibrator = require ( 'lib/calibrator' ) ;
1010const WdErrors = require ( 'lib/constants/wd-errors' ) ;
11+ const GeminiError = require ( 'lib/errors/gemini-error' ) ;
1112
1213const makeBrowser = require ( '../../util' ) . makeBrowser ;
1314
@@ -203,6 +204,80 @@ describe('browser/new-browser', () => {
203204 return assert . isRejected ( launchBrowser ( ) ) ;
204205 } ) ;
205206 } ) ;
207+
208+ describe ( 'catch error on wd init' , ( ) => {
209+ it ( 'should fail if wd init fails' , ( ) => {
210+ wd . init . returns ( Promise . reject ( new Error ( 'o.O' ) ) ) ;
211+
212+ return assert . isRejected ( launchBrowser ( ) ) ;
213+ } ) ;
214+
215+ it ( 'should fail with GeminiError instance' , ( ) => {
216+ wd . init . returns ( Promise . reject ( { message : 'defaultError' } ) ) ;
217+
218+ return assert . isRejected ( launchBrowser ( ) , GeminiError ) ;
219+ } ) ;
220+
221+ it ( 'should fail with the error message by default' , ( ) => {
222+ wd . init . returns ( Promise . reject ( { message : 'error text' } ) ) ;
223+
224+ return launchBrowser ( )
225+ . catch ( ( e ) => assert . include ( e . message , 'error text' ) ) ;
226+ } ) ;
227+
228+ it ( 'should extend error message with error data if it exists' , ( ) => {
229+ wd . init . returns ( Promise . reject ( { data : 'error text' } ) ) ;
230+
231+ return launchBrowser ( )
232+ . catch ( ( e ) => assert . include ( e . message , 'error text' ) ) ;
233+ } ) ;
234+
235+ it ( 'should not add to the message fail reason if error data does not exists' , ( ) => {
236+ wd . init . returns ( Promise . reject ( { message : 'defaultError' } ) ) ;
237+
238+ return launchBrowser ( )
239+ . catch ( ( e ) => assert . notInclude ( e . message , 'Reason' ) ) ;
240+ } ) ;
241+
242+ it ( 'should cut all tags from error' , ( ) => {
243+ wd . init . returns ( Promise . reject ( { data : '<title></title><body><h1>Error</h1> text</body>' } ) ) ;
244+
245+ return launchBrowser ( )
246+ . catch ( ( e ) => {
247+ assert . notInclude ( e . message , '<title>' ) ;
248+ assert . notInclude ( e . message , '<body>' ) ;
249+ assert . notInclude ( e . message , '<h1>' ) ;
250+ } ) ;
251+ } ) ;
252+
253+ it ( 'should skip text from all tags except body' , ( ) => {
254+ wd . init . returns ( Promise . reject ( { data : '<title>4xx</title><body>Error</body>' } ) ) ;
255+
256+ return launchBrowser ( )
257+ . catch ( ( e ) => assert . notInclude ( e . message , '4xx' ) ) ;
258+ } ) ;
259+
260+ it ( 'should not skip text from internal tags in body tag' , ( ) => {
261+ wd . init . returns ( Promise . reject ( { data : '<body><h1>Error</h1> text</body>' } ) ) ;
262+
263+ return launchBrowser ( )
264+ . catch ( ( e ) => assert . include ( e . message , 'Error text' ) ) ;
265+ } ) ;
266+
267+ it ( 'should replace newlines to spaces' , ( ) => {
268+ wd . init . returns ( Promise . reject ( { data : '<body>Error\ntext</body>' } ) ) ;
269+
270+ return launchBrowser ( )
271+ . catch ( ( e ) => assert . include ( e . message , 'Error text' ) ) ;
272+ } ) ;
273+
274+ it ( 'should fail with full html if <body> tag is empty' , ( ) => {
275+ wd . init . returns ( Promise . reject ( { data : '<html><body></body></html>' } ) ) ;
276+
277+ return launchBrowser ( )
278+ . catch ( ( e ) => assert . include ( e . message , '<html><body></body></html>' ) ) ;
279+ } ) ;
280+ } ) ;
206281 } ) ;
207282
208283 describe ( 'URL opening' , ( ) => {
0 commit comments