-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lib: add diagnostics_channel events to module loading
- Loading branch information
Stephen Belanger
committed
Dec 15, 2022
1 parent
f00969e
commit 99f0481
Showing
6 changed files
with
253 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
test/parallel/test-diagnostics-channel-module-import-error.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const dc = require('diagnostics_channel'); | ||
|
||
const trace = dc.tracingChannel('module.import'); | ||
const events = []; | ||
let lastEvent; | ||
|
||
function track(name) { | ||
return (event) => { | ||
// Verify every event after the first is the same object | ||
if (events.length) { | ||
assert.strictEqual(event, lastEvent); | ||
} | ||
lastEvent = event; | ||
|
||
events.push({ name, ...event }); | ||
} | ||
} | ||
|
||
trace.subscribe({ | ||
start: common.mustCall(track('start')), | ||
end: common.mustCall(track('end')), | ||
asyncStart: common.mustCall(track('asyncStart')), | ||
asyncEnd: common.mustCall(track('asyncEnd')), | ||
error: common.mustCall(track('error')), | ||
}); | ||
|
||
import('does-not-exist').then( | ||
common.mustNotCall(), | ||
common.mustCall((error) => { | ||
// Verify order and contents of each event | ||
assert.deepStrictEqual(events, [ | ||
{ | ||
name: 'start', | ||
parentURL: `file://${module.filename}`, | ||
url: 'does-not-exist', | ||
}, | ||
{ | ||
name: 'end', | ||
parentURL: `file://${module.filename}`, | ||
url: 'does-not-exist', | ||
}, | ||
{ | ||
name: 'error', | ||
parentURL: `file://${module.filename}`, | ||
url: 'does-not-exist', | ||
error, | ||
}, | ||
{ | ||
name: 'asyncStart', | ||
parentURL: `file://${module.filename}`, | ||
url: 'does-not-exist', | ||
error, | ||
}, | ||
{ | ||
name: 'asyncEnd', | ||
parentURL: `file://${module.filename}`, | ||
url: 'does-not-exist', | ||
error, | ||
}, | ||
]); | ||
}) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const dc = require('diagnostics_channel'); | ||
|
||
const trace = dc.tracingChannel('module.import'); | ||
const events = []; | ||
let lastEvent; | ||
|
||
function track (name) { | ||
return (event) => { | ||
// Verify every event after the first is the same object | ||
if (events.length) { | ||
assert.strictEqual(event, lastEvent); | ||
} | ||
lastEvent = event; | ||
|
||
events.push({ name, ...event }); | ||
} | ||
} | ||
|
||
trace.subscribe({ | ||
start: common.mustCall(track('start')), | ||
end: common.mustCall(track('end')), | ||
asyncStart: common.mustCall(track('asyncStart')), | ||
asyncEnd: common.mustCall(track('asyncEnd')), | ||
error: common.mustNotCall(track('error')), | ||
}); | ||
|
||
import('http').then( | ||
common.mustCall((result) => { | ||
// Verify order and contents of each event | ||
assert.deepStrictEqual(events, [ | ||
{ | ||
name: 'start', | ||
parentURL: `file://${module.filename}`, | ||
url: 'http', | ||
}, | ||
{ | ||
name: 'end', | ||
parentURL: `file://${module.filename}`, | ||
url: 'http', | ||
}, | ||
{ | ||
name: 'asyncStart', | ||
parentURL: `file://${module.filename}`, | ||
url: 'http', | ||
result, | ||
}, | ||
{ | ||
name: 'asyncEnd', | ||
parentURL: `file://${module.filename}`, | ||
url: 'http', | ||
result, | ||
}, | ||
]); | ||
}), | ||
common.mustNotCall(), | ||
); |
56 changes: 56 additions & 0 deletions
56
test/parallel/test-diagnostics-channel-module-require-error.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const dc = require('diagnostics_channel'); | ||
|
||
const trace = dc.tracingChannel('module.require'); | ||
const events = []; | ||
let lastEvent; | ||
|
||
function track (name) { | ||
return (event) => { | ||
// Verify every event after the first is the same object | ||
if (events.length) { | ||
assert.strictEqual(event, lastEvent); | ||
} | ||
lastEvent = event; | ||
|
||
events.push({ name, ...event }); | ||
} | ||
} | ||
|
||
trace.subscribe({ | ||
start: common.mustCall(track('start')), | ||
end: common.mustCall(track('end')), | ||
asyncStart: common.mustNotCall(track('asyncStart')), | ||
asyncEnd: common.mustNotCall(track('asyncEnd')), | ||
error: common.mustCall(track('error')), | ||
}); | ||
|
||
let error; | ||
try { | ||
require('does-not-exist'); | ||
} catch (err) { | ||
error = err; | ||
} | ||
|
||
// Verify order and contents of each event | ||
assert.deepStrictEqual(events, [ | ||
{ | ||
name: 'start', | ||
parentFilename: module.filename, | ||
id: 'does-not-exist', | ||
}, | ||
{ | ||
name: 'error', | ||
parentFilename: module.filename, | ||
id: 'does-not-exist', | ||
error, | ||
}, | ||
{ | ||
name: 'end', | ||
parentFilename: module.filename, | ||
id: 'does-not-exist', | ||
error, | ||
}, | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const dc = require('diagnostics_channel'); | ||
|
||
const trace = dc.tracingChannel('module.require'); | ||
const events = []; | ||
let lastEvent; | ||
|
||
function track (name) { | ||
return (event) => { | ||
// Verify every event after the first is the same object | ||
if (events.length) { | ||
assert.strictEqual(event, lastEvent); | ||
} | ||
lastEvent = event; | ||
|
||
events.push({ name, ...event }); | ||
} | ||
} | ||
|
||
trace.subscribe({ | ||
start: common.mustCall(track('start')), | ||
end: common.mustCall(track('end')), | ||
asyncStart: common.mustNotCall(track('asyncStart')), | ||
asyncEnd: common.mustNotCall(track('asyncEnd')), | ||
error: common.mustNotCall(track('error')), | ||
}); | ||
|
||
const result = require('http'); | ||
|
||
// Verify order and contents of each event | ||
assert.deepStrictEqual(events, [ | ||
{ | ||
name: 'start', | ||
parentFilename: module.filename, | ||
id: 'http', | ||
}, | ||
{ | ||
name: 'end', | ||
parentFilename: module.filename, | ||
id: 'http', | ||
result, | ||
}, | ||
]); | ||
|