1+ import { version } from 'process'
12import { inspect } from 'util'
23
34import test from 'ava'
5+ import semver from 'semver'
46import sinon from 'sinon'
57import { each } from 'test-each'
68
79import { EVENTS } from './helpers/events/main.js'
810import { startLogging } from './helpers/init.js'
911import { LEVELS } from './helpers/level.js'
1012import { normalizeMessage } from './helpers/normalize.js'
13+ // eslint-disable-next-line import/max-dependencies
1114import { removeProcessListeners } from './helpers/remove.js'
1215
1316removeProcessListeners ( )
@@ -22,7 +25,10 @@ const snapshotArgs = function ([error, level, mainValue]) {
2225 ]
2326}
2427
25- each ( EVENTS , ( { title } , { eventName, emit } ) => {
28+ // Stack traces change with this Node.js version
29+ const MIN_STACK_VERSION = '14.0.0'
30+
31+ each ( [ EVENTS [ 0 ] ] , ( { title } , { eventName, emit } ) => {
2632 test . serial ( `should fire opts.log() | ${ title } ` , async ( t ) => {
2733 const { stopLogging, log } = startLogging ( { log : 'spy' } )
2834
@@ -47,18 +53,23 @@ each(EVENTS, ({ title }, { eventName, emit }) => {
4753 stopLogging ( )
4854 } )
4955
50- test . serial ( `should fire opts.log() with arguments | ${ title } ` , async ( t ) => {
51- const { stopLogging, log } = startLogging ( { log : 'spy' , eventName } )
56+ if ( semver . gte ( version , MIN_STACK_VERSION ) ) {
57+ test . serial (
58+ `should fire opts.log() with arguments | ${ title } ` ,
59+ async ( t ) => {
60+ const { stopLogging, log } = startLogging ( { log : 'spy' , eventName } )
5261
53- await emit ( { all : true } )
62+ await emit ( { all : true } )
5463
55- t . true ( log . called )
64+ t . true ( log . called )
5665
57- const snapshot = log . args . flatMap ( snapshotArgs )
58- t . snapshot ( snapshot )
66+ const snapshot = log . args . flatMap ( snapshotArgs )
67+ t . snapshot ( snapshot )
5968
60- stopLogging ( )
61- } )
69+ stopLogging ( )
70+ } ,
71+ )
72+ }
6273} )
6374
6475each ( EVENTS , LEVELS , ( { title } , { eventName, emit } , level ) => {
0 commit comments