1515/* eslint-disable no-console */
1616const puppeteer = require ( 'puppeteer' ) ;
1717const assert = require ( 'assert' ) ;
18+ const fs = require ( 'fs/promises' ) ;
19+ const path = require ( 'path' ) ;
1820const { spawn} = require ( 'child_process' ) ;
1921
2022const config = require ( './test-config.js' ) ;
@@ -34,13 +36,17 @@ describe('InfoLogger', function() {
3436 let subprocess ; // web-server runs into a subprocess
3537 let subprocessOutput = '' ;
3638 let ilgServer ;
39+ const testDbSourcePath = path . join ( __dirname , 'testdb.json' ) ;
40+ const testDbRunningPath = path . join ( __dirname , 'testdb-running.json' ) ;
3741
3842 this . timeout ( 30000 ) ;
3943 this . slow ( 1000 ) ;
4044
4145 const baseUrl = `http://${ config . http . hostname } :${ config . http . port } /` ;
4246
4347 before ( async ( ) => {
48+ await fs . copyFile ( testDbSourcePath , testDbRunningPath ) ;
49+
4450 // Add error handlers for uncaught errors
4551 process . on ( 'unhandledRejection' , ( error ) => {
4652 console . error ( '[Test Setup] Unhandled Promise Rejection at:' , new Date ( ) . toISOString ( ) ) ;
@@ -93,12 +99,12 @@ describe('InfoLogger', function() {
9399 }
94100 } ) ;
95101
96- it ( 'should have redirected to default page "/?q={"severity":{"in":"I W E F"},"level":{"max":1} }"' , async function ( ) {
102+ it ( 'should have redirected to default page "/?q={"severity":{"in":"I W E F"}}"' , async function ( ) {
97103 await page . goto ( baseUrl , { waitUntil : 'networkidle0' } ) ;
98104 const location = await page . evaluate ( ( ) => window . location ) ;
99105 const search = decodeURIComponent ( location . search ) ;
100106
101- assert . deepStrictEqual ( search , '?q={"severity":{"in":"I W E F"},"level":{"max":1} }' ) ;
107+ assert . deepStrictEqual ( search , '?q={"severity":{"in":"I W E F"}}' ) ;
102108 } ) ;
103109
104110 require ( './public/user-actions-mocha' ) ;
@@ -110,14 +116,18 @@ describe('InfoLogger', function() {
110116 require ( './public/log-context-menu-mocha' ) ;
111117
112118 after ( async ( ) => {
113- await browser . close ( ) ;
114- console . log ( '---------------------------------------------' ) ;
115- console . log ( 'Output of server logs for the previous tests:' ) ;
116- console . log ( '---------------------------------------------' ) ;
117- console . log ( subprocessOutput ) ;
118- console . log ( '---------------------------------------------' ) ;
119- subprocess . kill ( ) ;
120- closeServer ( ilgServer ) ;
119+ try {
120+ await browser . close ( ) ;
121+ console . log ( '---------------------------------------------' ) ;
122+ console . log ( 'Output of server logs for the previous tests:' ) ;
123+ console . log ( '---------------------------------------------' ) ;
124+ console . log ( subprocessOutput ) ;
125+ console . log ( '---------------------------------------------' ) ;
126+ subprocess . kill ( ) ;
127+ closeServer ( ilgServer ) ;
128+ } finally {
129+ await fs . rm ( testDbRunningPath , { force : true } ) ;
130+ }
121131
122132 } ) ;
123133} ) ;
0 commit comments