Skip to content

Commit b98c4ed

Browse files
Copilottaylortom
andcommitted
Migrate tests to tests/ directory with .spec.js naming and strict assertions
Co-authored-by: taylortom <1059083+taylortom@users.noreply.github.com>
1 parent cfd92ef commit b98c4ed

File tree

2 files changed

+36
-36
lines changed

2 files changed

+36
-36
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@
3939
]
4040
},
4141
"scripts": {
42-
"test": "node --test"
42+
"test": "node --test tests/*.spec.js"
4343
}
4444
}
Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import assert from 'assert'
21
import { describe, it, beforeEach, afterEach } from 'node:test'
2+
import assert from 'node:assert/strict'
33
import chalk from 'chalk'
44
import LoggerModule from '../lib/LoggerModule.js'
55

66
describe('LoggerModule', () => {
7-
describe('colourise()', () => {
7+
describe('#colourise()', () => {
88
it('should return string with colour function applied', () => {
99
const result = LoggerModule.colourise('test', chalk.red)
1010
assert.ok(result.includes('test'))
@@ -17,20 +17,20 @@ describe('LoggerModule', () => {
1717

1818
it('should return uncoloured string if no colour function provided', () => {
1919
const result = LoggerModule.colourise('test', null)
20-
assert.strictEqual(result, 'test')
20+
assert.equal(result, 'test')
2121
})
2222

2323
it('should handle undefined colour function', () => {
2424
const result = LoggerModule.colourise('test', undefined)
25-
assert.strictEqual(result, 'test')
25+
assert.equal(result, 'test')
2626
})
2727
})
2828

29-
describe('getDateStamp()', () => {
29+
describe('#getDateStamp()', () => {
3030
it('should return empty string when timestamp is disabled', () => {
3131
const config = { timestamp: false }
3232
const result = LoggerModule.getDateStamp(config)
33-
assert.strictEqual(result, '')
33+
assert.equal(result, '')
3434
})
3535

3636
it('should return ISO format date when dateFormat is "iso"', () => {
@@ -46,7 +46,7 @@ describe('LoggerModule', () => {
4646
})
4747
})
4848

49-
describe('isLevelEnabled()', () => {
49+
describe('#isLevelEnabled()', () => {
5050
let logger
5151

5252
beforeEach(() => {
@@ -55,28 +55,28 @@ describe('LoggerModule', () => {
5555
})
5656

5757
it('should return true for enabled levels', () => {
58-
assert.strictEqual(logger.isLevelEnabled('error'), true)
59-
assert.strictEqual(logger.isLevelEnabled('warn'), true)
60-
assert.strictEqual(logger.isLevelEnabled('info'), true)
58+
assert.equal(logger.isLevelEnabled('error'), true)
59+
assert.equal(logger.isLevelEnabled('warn'), true)
60+
assert.equal(logger.isLevelEnabled('info'), true)
6161
})
6262

6363
it('should return false for disabled levels', () => {
64-
assert.strictEqual(logger.isLevelEnabled('debug'), false)
65-
assert.strictEqual(logger.isLevelEnabled('verbose'), false)
64+
assert.equal(logger.isLevelEnabled('debug'), false)
65+
assert.equal(logger.isLevelEnabled('verbose'), false)
6666
})
6767

6868
it('should return false when level is explicitly disabled', () => {
6969
logger.levelsConfig = ['error', '!warn', 'info']
70-
assert.strictEqual(logger.isLevelEnabled('warn'), false)
70+
assert.equal(logger.isLevelEnabled('warn'), false)
7171
})
7272

7373
it('should give preference to explicit disable', () => {
7474
logger.levelsConfig = ['warn', '!warn']
75-
assert.strictEqual(logger.isLevelEnabled('warn'), false)
75+
assert.equal(logger.isLevelEnabled('warn'), false)
7676
})
7777
})
7878

79-
describe('getModuleOverrides()', () => {
79+
describe('#getModuleOverrides()', () => {
8080
let logger
8181

8282
beforeEach(() => {
@@ -88,7 +88,7 @@ describe('LoggerModule', () => {
8888
const result = logger.getModuleOverrides('error')
8989
assert.ok(result.includes('error.myModule'))
9090
assert.ok(result.includes('error.anotherModule'))
91-
assert.strictEqual(result.length, 2)
91+
assert.equal(result.length, 2)
9292
})
9393

9494
it('should include negative overrides', () => {
@@ -100,7 +100,7 @@ describe('LoggerModule', () => {
100100
it('should return empty array when no overrides exist', () => {
101101
logger.levelsConfig = ['error', 'warn']
102102
const result = logger.getModuleOverrides('info')
103-
assert.strictEqual(result.length, 0)
103+
assert.equal(result.length, 0)
104104
})
105105

106106
it('should not include overrides for other levels', () => {
@@ -110,7 +110,7 @@ describe('LoggerModule', () => {
110110
})
111111
})
112112

113-
describe('isLoggingEnabled()', () => {
113+
describe('#isLoggingEnabled()', () => {
114114
let logger
115115

116116
beforeEach(() => {
@@ -125,31 +125,31 @@ describe('LoggerModule', () => {
125125
})
126126

127127
it('should return true for enabled levels', () => {
128-
assert.strictEqual(logger.isLoggingEnabled('error', 'anyId'), true)
128+
assert.equal(logger.isLoggingEnabled('error', 'anyId'), true)
129129
})
130130

131131
it('should return false for disabled levels without overrides', () => {
132-
assert.strictEqual(logger.isLoggingEnabled('warn', 'generic'), false)
132+
assert.equal(logger.isLoggingEnabled('warn', 'generic'), false)
133133
})
134134

135135
it('should return true for disabled level with positive override', () => {
136-
assert.strictEqual(logger.isLoggingEnabled('warn', 'specific'), true)
136+
assert.equal(logger.isLoggingEnabled('warn', 'specific'), true)
137137
})
138138

139139
it('should return false for enabled level with negative override', () => {
140-
assert.strictEqual(logger.isLoggingEnabled('info', 'blocked'), false)
140+
assert.equal(logger.isLoggingEnabled('info', 'blocked'), false)
141141
})
142142

143143
it('should return true for enabled level without override', () => {
144-
assert.strictEqual(logger.isLoggingEnabled('info', 'allowed'), true)
144+
assert.equal(logger.isLoggingEnabled('info', 'allowed'), true)
145145
})
146146

147147
it('should handle missing level config gracefully', () => {
148-
assert.strictEqual(logger.isLoggingEnabled('nonexistent', 'id'), false)
148+
assert.equal(logger.isLoggingEnabled('nonexistent', 'id'), false)
149149
})
150150
})
151151

152-
describe('log()', () => {
152+
describe('#log()', () => {
153153
let logger
154154
let logOutput
155155
let originalConsoleLog
@@ -184,24 +184,24 @@ describe('LoggerModule', () => {
184184
it('should not log when muted', () => {
185185
logger.config.mute = true
186186
logger.log('info', 'test', 'message')
187-
assert.strictEqual(logOutput.length, 0)
187+
assert.equal(logOutput.length, 0)
188188
})
189189

190190
it('should not log when level is disabled', () => {
191191
logger.config.levels.debug.enable = false
192192
logger.log('debug', 'test', 'message')
193-
assert.strictEqual(logOutput.length, 0)
193+
assert.equal(logOutput.length, 0)
194194
})
195195

196196
it('should log message when enabled', () => {
197197
logger.log('info', 'testId', 'test message')
198-
assert.strictEqual(logOutput.length, 1)
198+
assert.equal(logOutput.length, 1)
199199
assert.ok(logOutput[0].args.some(arg => typeof arg === 'string' && arg.includes('testId')))
200200
})
201201

202202
it('should include multiple arguments', () => {
203203
logger.log('info', 'test', 'arg1', 'arg2', 'arg3')
204-
assert.strictEqual(logOutput.length, 1)
204+
assert.equal(logOutput.length, 1)
205205
const args = logOutput[0].args
206206
assert.ok(args.includes('arg1'))
207207
assert.ok(args.includes('arg2'))
@@ -210,7 +210,7 @@ describe('LoggerModule', () => {
210210

211211
it('should use correct console method for level', () => {
212212
logger.log('error', 'test', 'message')
213-
assert.strictEqual(logOutput[0].level, 'error')
213+
assert.equal(logOutput[0].level, 'error')
214214
})
215215

216216
it('should invoke logHook with correct parameters', () => {
@@ -220,20 +220,20 @@ describe('LoggerModule', () => {
220220
}
221221
logger.log('info', 'testId', 'message')
222222
assert.ok(hookArgs)
223-
assert.strictEqual(hookArgs[1], 'info')
224-
assert.strictEqual(hookArgs[2], 'testId')
225-
assert.strictEqual(hookArgs[3], 'message')
223+
assert.equal(hookArgs[1], 'info')
224+
assert.equal(hookArgs[2], 'testId')
225+
assert.equal(hookArgs[3], 'message')
226226
})
227227

228228
it('should colorise level in output', () => {
229229
logger.log('info', 'test', 'message')
230-
assert.strictEqual(logOutput.length, 1)
230+
assert.equal(logOutput.length, 1)
231231
assert.ok(logOutput[0].args[0].includes('info'))
232232
})
233233

234234
it('should colorise id in output', () => {
235235
logger.log('info', 'myModule', 'message')
236-
assert.strictEqual(logOutput.length, 1)
236+
assert.equal(logOutput.length, 1)
237237
assert.ok(logOutput[0].args[0].includes('myModule'))
238238
})
239239
})

0 commit comments

Comments
 (0)