Skip to content

Commit

Permalink
chore: suppress logging during testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Julusian committed Dec 22, 2024
1 parent ad36c8f commit cedd32b
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 1 deletion.
7 changes: 7 additions & 0 deletions companion/lib/Log/Controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,13 @@ class LogController {
this.#logger = this.createLogger('Log/Controller')
}

/**
* Get the log level
*/
getLogLevel(): string {
return this.#winston.level
}

/**
* Set the log level to output
*/
Expand Down
5 changes: 4 additions & 1 deletion companion/test/Upgrade/v1tov2-upgradeStartup.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { describe, it, expect } from 'vitest'
import { describe, it, expect, beforeEach } from 'vitest'
import { DataStoreBase } from '../../lib/Data/StoreBase.js'
import LogController from '../../lib/Log/Controller.js'
import v1tov2 from '../../lib/Data/Upgrades/v1tov2.js'
import { createTables } from '../../lib/Data/Schema/v1.js'
import fs from 'fs-extra'
import { SuppressLogging } from '../Util.js'

function CreateDataDatabase() {
const db = new DataDatabase()
Expand All @@ -29,6 +30,8 @@ class DataDatabase extends DataStoreBase {
}

describe('upgrade', () => {
SuppressLogging()

it('empty', () => {
const db = CreateDataDatabase()
v1tov2.upgradeStartup(db, LogController.createLogger('test-logger'))
Expand Down
3 changes: 3 additions & 0 deletions companion/test/Upgrade/v1tov5-upgradeStartup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import v3tov4 from '../../lib/Data/Upgrades/v3tov4.js'
import v4tov5 from '../../lib/Data/Upgrades/v4tov5.js'
import { createTables } from '../../lib/Data/Schema/v1.js'
import fs from 'fs-extra'
import { SuppressLogging } from '../Util.js'

function CreateDataDatabase() {
const db = new DataDatabase()
Expand All @@ -32,6 +33,8 @@ class DataDatabase extends DataStoreBase {
}

describe('upgrade', () => {
SuppressLogging()

const db = CreateDataDatabase()
v1tov2.upgradeStartup(db, LogController.createLogger('test-logger'))
v2tov3.upgradeStartup(db, LogController.createLogger('test-logger'))
Expand Down
3 changes: 3 additions & 0 deletions companion/test/Upgrade/v2tov3-upgradeStartup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import LogController from '../../lib/Log/Controller.js'
import v2tov3 from '../../lib/Data/Upgrades/v2tov3.js'
import { createTables } from '../../lib/Data/Schema/v1.js'
import fs from 'fs-extra'
import { SuppressLogging } from '../Util.js'

let nano = 0

Expand Down Expand Up @@ -35,6 +36,8 @@ class DataDatabase extends DataStoreBase {
}

describe('upgrade', () => {
SuppressLogging()

it('empty', () => {
const db = CreateDataDatabase()
v2tov3.upgradeStartup(db, LogController.createLogger('test-logger'))
Expand Down
3 changes: 3 additions & 0 deletions companion/test/Upgrade/v3tov4-upgradeStartup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import LogController from '../../lib/Log/Controller.js'
import v3tov4 from '../../lib/Data/Upgrades/v3tov4.js'
import { createTables } from '../../lib/Data/Schema/v1.js'
import fs from 'fs-extra'
import { SuppressLogging } from '../Util.js'

function CreateDataDatabase() {
const db = new DataDatabase()
Expand All @@ -29,6 +30,8 @@ class DataDatabase extends DataStoreBase {
}

describe('upgrade', () => {
SuppressLogging()

it('empty', () => {
const db = CreateDataDatabase()
v3tov4.upgradeStartup(db, LogController.createLogger('test-logger'))
Expand Down
3 changes: 3 additions & 0 deletions companion/test/Upgrade/v4tov5-upgradeStartup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import LogController from '../../lib/Log/Controller.js'
import v4tov5 from '../../lib/Data/Upgrades/v4tov5.js'
import { createTables } from '../../lib/Data/Schema/v1.js'
import fs from 'fs-extra'
import { SuppressLogging } from '../Util.js'

function CreateDataDatabase() {
const db = new DataDatabase()
Expand All @@ -29,6 +30,8 @@ class DataDatabase extends DataStoreBase {
}

describe('upgrade', () => {
SuppressLogging()

const db = CreateDataDatabase()
let data = fs.readFileSync('./companion/test/Upgrade/v4tov5/db.v5.json', 'utf8')
data = JSON.parse(data)
Expand Down
13 changes: 13 additions & 0 deletions companion/test/Util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import LogController from '../lib/Log/Controller.js'
import { afterAll, beforeAll } from 'vitest'

export function SuppressLogging() {
let originalLogLevel: string = 'silly'
beforeAll(() => {
originalLogLevel = LogController.getLogLevel()
LogController.setLogLevel('error')
})
afterAll(() => {
LogController.setLogLevel(originalLogLevel)
})
}

0 comments on commit cedd32b

Please sign in to comment.