@@ -16,6 +16,7 @@ import {
1616 ClientsideDeletionFailsafeError ,
1717 ServersideAdditionFailsafeError , ServersideDeletionFailsafeError
1818} from '../errors/Error'
19+ import Logger from '../lib/Logger'
1920
2021chai . use ( chaiAsPromised )
2122const expect = chai . expect
@@ -72,7 +73,7 @@ describe('Floccus', function() {
7273 this . slow ( 20000 ) // 20s is slow
7374
7475 const params = ( new URL ( window . location . href ) ) . searchParams
75- let SERVER , CREDENTIALS , ACCOUNTS , APP_VERSION , SEED , BROWSER , RANDOM_MANIPULATION_ITERATIONS , TEST_URL
76+ let SERVER , CREDENTIALS , ACCOUNTS , APP_VERSION , SEED , BROWSER , RANDOM_MANIPULATION_ITERATIONS , TEST_URL , IS_CI
7677 SERVER =
7778 params . get ( 'server' ) ||
7879 'http://localhost'
@@ -83,13 +84,25 @@ describe('Floccus', function() {
8384 }
8485 APP_VERSION = params . get ( 'app_version' ) || 'stable'
8586 BROWSER = params . get ( 'browser' ) || 'firefox'
87+ IS_CI = params . get ( 'ci' ) === 'true'
8688
8789 SEED = ( new URL ( window . location . href ) ) . searchParams . get ( 'seed' ) || Math . random ( ) + ''
8890 console . log ( 'RANDOMNESS SEED' , SEED )
8991 random . use ( seedrandom ( SEED ) )
9092
9193 RANDOM_MANIPULATION_ITERATIONS = 35
9294
95+ Logger . persist = ( ) => Promise . resolve ( )
96+ let DUMP_LOGS = function ( currentTest ) {
97+ // Dump logs if test failed
98+ if ( IS_CI && currentTest && currentTest . isFailed ( ) ) {
99+ for ( const log of Logger . messages ) {
100+ console . log ( log )
101+ }
102+ Logger . messages = [ ]
103+ }
104+ }
105+
93106 ACCOUNTS = [
94107 FakeAdapter . getDefaultValues ( ) ,
95108 {
@@ -282,6 +295,7 @@ describe('Floccus', function() {
282295 }
283296 } )
284297 afterEach ( 'clean up account' , async function ( ) {
298+ DUMP_LOGS ( this . currentTest )
285299 if ( ! account ) return
286300 try {
287301 await browser . bookmarks . removeTree ( account . getData ( ) . localRoot )
@@ -294,8 +308,8 @@ describe('Floccus', function() {
294308 await account . setData ( { serverRoot : null } )
295309 account . lockTimeout = 0
296310 const tree = await getAllBookmarks ( account )
297- await withSyncConnection ( account , async ( ) => {
298- await AsyncParallel . each ( tree . children , async child => {
311+ await withSyncConnection ( account , async ( ) => {
312+ await AsyncParallel . each ( tree . children , async ( child ) => {
299313 if ( child instanceof Folder ) {
300314 await account . server . removeFolder ( child )
301315 } else {
@@ -313,11 +327,16 @@ describe('Floccus', function() {
313327 await account . server . deleteFile ( file . id )
314328 }
315329 if ( files . length > 1 ) {
316- throw new Error ( 'Google Drive sync left more than one file behind' )
330+ throw new Error (
331+ 'Google Drive sync left more than one file behind'
332+ )
317333 }
318334 }
319335 if ( ACCOUNT_DATA . type === 'dropbox' ) {
320- const fileList = await account . server . listFiles ( ACCOUNT_DATA . bookmark_file , 100 )
336+ const fileList = await account . server . listFiles (
337+ ACCOUNT_DATA . bookmark_file ,
338+ 100
339+ )
321340 const files = fileList . matches
322341 for ( const file of files ) {
323342 await account . server . deleteFile ( file . metadata . metadata . id )
@@ -3991,16 +4010,17 @@ describe('Floccus', function() {
39914010 }
39924011 } )
39934012 afterEach ( 'clean up accounts' , async function ( ) {
4013+ DUMP_LOGS ( this . currentTest )
39944014 if ( ACCOUNT_DATA . type === 'git' ) {
39954015 await account1 . server . clearServer ( )
39964016 } else if ( ACCOUNT_DATA . type !== 'fake' ) {
39974017 await account1 . setData ( {
3998- serverRoot : null
4018+ serverRoot : null ,
39994019 } )
40004020 account1 . lockTimeout = 0
4001- await withSyncConnection ( account1 , async ( ) => {
4021+ await withSyncConnection ( account1 , async ( ) => {
40024022 const tree = await account1 . server . getBookmarksTree ( true )
4003- await AsyncParallel . each ( tree . children , async child => {
4023+ await AsyncParallel . each ( tree . children , async ( child ) => {
40044024 if ( child instanceof Folder ) {
40054025 await account1 . server . removeFolder ( child )
40064026 } else {
@@ -4010,17 +4030,24 @@ describe('Floccus', function() {
40104030 } )
40114031 }
40124032 if ( ACCOUNT_DATA . type === 'google-drive' ) {
4013- const fileList = await account1 . server . listFiles ( 'name = ' + "'" + ACCOUNT_DATA . bookmark_file + "'" )
4033+ const fileList = await account1 . server . listFiles (
4034+ 'name = ' + "'" + ACCOUNT_DATA . bookmark_file + "'"
4035+ )
40144036 const files = fileList . files
40154037 for ( const file of files ) {
40164038 await account1 . server . deleteFile ( file . id )
40174039 }
40184040 if ( files . length > 1 ) {
4019- throw new Error ( 'Google Drive sync left more than one file behind' )
4041+ throw new Error (
4042+ 'Google Drive sync left more than one file behind'
4043+ )
40204044 }
40214045 }
40224046 if ( ACCOUNT_DATA . type === 'dropbox' ) {
4023- const fileList = await account1 . server . listFiles ( ACCOUNT_DATA . bookmark_file , 100 )
4047+ const fileList = await account1 . server . listFiles (
4048+ ACCOUNT_DATA . bookmark_file ,
4049+ 100
4050+ )
40244051 const files = fileList . matches
40254052 for ( const file of files ) {
40264053 await account1 . server . deleteFile ( file . metadata . metadata . id )
@@ -5644,13 +5671,22 @@ describe('Floccus', function() {
56445671 }
56455672 } )
56465673 afterEach ( 'clean up account' , async function ( ) {
5674+ DUMP_LOGS ( this . currentTest )
56475675 if ( ! account ) return
56485676 try {
56495677 await awaitTabsUpdated ( )
56505678 const tabs = await browser . tabs . query ( {
5651- windowType : 'normal' // no devtools or panels or popups
5679+ windowType : 'normal' , // no devtools or panels or popups
56525680 } )
5653- await browser . tabs . remove ( tabs . filter ( tab => ! tab . url . startsWith ( 'chrome' ) && ! tab . url . startsWith ( 'moz' ) ) . map ( tab => tab . id ) )
5681+ await browser . tabs . remove (
5682+ tabs
5683+ . filter (
5684+ ( tab ) =>
5685+ ! tab . url . startsWith ( 'chrome' ) &&
5686+ ! tab . url . startsWith ( 'moz' )
5687+ )
5688+ . map ( ( tab ) => tab . id )
5689+ )
56545690 } catch ( e ) {
56555691 console . error ( e )
56565692 }
@@ -5661,8 +5697,8 @@ describe('Floccus', function() {
56615697 await account . setData ( { serverRoot : null } )
56625698 account . lockTimeout = 0
56635699 const tree = await getAllBookmarks ( account )
5664- await withSyncConnection ( account , async ( ) => {
5665- await AsyncParallel . each ( tree . children , async child => {
5700+ await withSyncConnection ( account , async ( ) => {
5701+ await AsyncParallel . each ( tree . children , async ( child ) => {
56665702 if ( child instanceof Folder ) {
56675703 await account . server . removeFolder ( child )
56685704 } else {
@@ -5672,17 +5708,24 @@ describe('Floccus', function() {
56725708 } )
56735709 }
56745710 if ( ACCOUNT_DATA . type === 'google-drive' ) {
5675- const fileList = await account . server . listFiles ( 'name = ' + "'" + ACCOUNT_DATA . bookmark_file + "'" )
5711+ const fileList = await account . server . listFiles (
5712+ 'name = ' + "'" + ACCOUNT_DATA . bookmark_file + "'"
5713+ )
56765714 const files = fileList . files
56775715 for ( const file of files ) {
56785716 await account . server . deleteFile ( file . id )
56795717 }
56805718 if ( files . length > 1 ) {
5681- throw new Error ( 'Google Drive sync left more than one file behind' )
5719+ throw new Error (
5720+ 'Google Drive sync left more than one file behind'
5721+ )
56825722 }
56835723 }
56845724 if ( ACCOUNT_DATA . type === 'dropbox' ) {
5685- const fileList = await account . server . listFiles ( ACCOUNT_DATA . bookmark_file , 100 )
5725+ const fileList = await account . server . listFiles (
5726+ ACCOUNT_DATA . bookmark_file ,
5727+ 100
5728+ )
56865729 const files = fileList . matches
56875730 for ( const file of files ) {
56885731 await account . server . deleteFile ( file . metadata . metadata . id )
@@ -6046,6 +6089,7 @@ describe('Floccus', function() {
60466089 }
60476090 } )
60486091 afterEach ( 'clean up account' , async function ( ) {
6092+ DUMP_LOGS ( this . currentTest )
60496093 if ( ! account ) return
60506094 try {
60516095 await awaitTabsUpdated ( )
@@ -7139,16 +7183,17 @@ describe('Floccus', function() {
71397183 afterEach ( 'clean up accounts' , async function ( ) {
71407184 RUN_INTERRUPTS = false
71417185 stopInterrupts ( )
7186+ DUMP_LOGS ( this . currentTest )
71427187 if ( ACCOUNT_DATA . type === 'git' ) {
71437188 await account1 . server . clearServer ( )
71447189 } else if ( ACCOUNT_DATA . type !== 'fake' ) {
71457190 await account1 . setData ( {
7146- serverRoot : null
7191+ serverRoot : null ,
71477192 } )
71487193 account1 . lockTimeout = 0
71497194 const tree = await getAllBookmarks ( account1 )
7150- await withSyncConnection ( account1 , async ( ) => {
7151- await AsyncParallel . each ( tree . children , async child => {
7195+ await withSyncConnection ( account1 , async ( ) => {
7196+ await AsyncParallel . each ( tree . children , async ( child ) => {
71527197 if ( child instanceof Folder ) {
71537198 await account1 . server . removeFolder ( child )
71547199 } else {
@@ -7158,13 +7203,17 @@ describe('Floccus', function() {
71587203 } )
71597204 }
71607205 if ( ACCOUNT_DATA . type === 'google-drive' ) {
7161- const fileList = await account1 . server . listFiles ( 'name = ' + "'" + ACCOUNT_DATA . bookmark_file + "'" )
7206+ const fileList = await account1 . server . listFiles (
7207+ 'name = ' + "'" + ACCOUNT_DATA . bookmark_file + "'"
7208+ )
71627209 const files = fileList . files
71637210 for ( const file of files ) {
71647211 await account1 . server . deleteFile ( file . id )
71657212 }
71667213 if ( files . length > 1 ) {
7167- throw new Error ( 'Google Drive sync left more than one file behind' )
7214+ throw new Error (
7215+ 'Google Drive sync left more than one file behind'
7216+ )
71687217 }
71697218 }
71707219 if ( ACCOUNT_DATA . type === 'dropbox' ) {
0 commit comments