11// Import Node.js Dependencies
2- import { describe , it } from "node:test" ;
32import assert from "node:assert" ;
4- import path from "node:path" ;
53import fs from "node:fs" ;
4+ import path from "node:path" ;
5+ import { describe , it } from "node:test" ;
66
77// Import Internal Dependencies
8- import {
9- Extractors ,
10- type ManifestProbeNextCallback ,
11- type PackumentProbeNextCallback ,
12- type Payload
13- } from "../../src/index.js" ;
8+ import { type ExtractorCallbackParams } from "../../src/extractors/payload.js" ;
9+ import { Extractors , type Payload } from "../../src/index.js" ;
1410
1511// CONSTANTS
1612const kFixturePath = path . join ( "fixtures" , "extractors" ) ;
@@ -220,30 +216,23 @@ describe("Extractors.Probes", () => {
220216 }
221217 } ;
222218
223- const extractor = new Extractors . Payload (
224- fakePayload ,
225- [
226- new Extractors . Probes . Vulnerabilities ( )
227- ]
228- ) ;
219+ const extractor = new Extractors . Payload ( fakePayload , [
220+ new Extractors . Probes . Vulnerabilities ( )
221+ ] ) ;
229222
230- const {
231- vulnerabilities
232- } = extractor . extractAndMerge ( ) ;
223+ const { vulnerabilities } = extractor . extractAndMerge ( ) ;
233224
234225 assert . strictEqual ( vulnerabilities . length , 2 ) ;
235226 assert . deepEqual ( vulnerabilities , [ "foo" , "bar" ] ) ;
236227 } ) ;
237228 } ) ;
238229
239230 it ( "should extract data with multiple extractors in once" , ( ) => {
240- const extractor = new Extractors . Payload (
241- expressNodesecurePayload ,
242- [
243- new Extractors . Probes . Size ( ) ,
244- new Extractors . Probes . Contacts ( ) ,
245- new Extractors . Probes . Licenses ( )
246- ]
231+ const extractor = new Extractors . Payload ( expressNodesecurePayload , [
232+ new Extractors . Probes . Size ( ) ,
233+ new Extractors . Probes . Contacts ( ) ,
234+ new Extractors . Probes . Licenses ( )
235+ ]
247236 ) ;
248237
249238 const arrResult = extractor . extract ( ) ;
@@ -258,9 +247,6 @@ describe("Extractors.Probes", () => {
258247} ) ;
259248
260249describe ( "Extractors.Payload events" , ( ) => {
261- type ManifestEvent = Parameters < ManifestProbeNextCallback > ;
262- type PackumentEvent = Parameters < PackumentProbeNextCallback > ;
263-
264250 it ( "should emits packument and manifest events" , ( ) => {
265251 const extractor = new Extractors . Payload (
266252 expressNodesecurePayload ,
@@ -270,14 +256,14 @@ describe("Extractors.Payload events", () => {
270256 ]
271257 ) ;
272258
273- const manifestEvents : ManifestEvent [ ] = [ ] ;
274- const packumentEvents : PackumentEvent [ ] = [ ] ;
259+ const manifestEvents : ExtractorCallbackParams < "manifest" > [ ] = [ ] ;
260+ const packumentEvents : ExtractorCallbackParams < "packument" > [ ] = [ ] ;
275261
276- extractor . on ( "manifest" , ( ...event : ManifestEvent ) => {
262+ extractor . on ( "manifest" , ( ...event ) => {
277263 manifestEvents . push ( event ) ;
278264 } ) ;
279265
280- extractor . on ( "packument" , ( ...event : PackumentEvent ) => {
266+ extractor . on ( "packument" , ( ...event ) => {
281267 packumentEvents . push ( event ) ;
282268 } ) ;
283269
@@ -301,20 +287,18 @@ describe("Extractors.Callbacks", () => {
301287 it ( "should extract name and versions for all packages" , ( ) => {
302288 const packages = new Map < string , string [ ] > ( ) ;
303289
304- const extractor = new Extractors . Payload (
305- expressNodesecurePayload ,
306- [
307- Extractors . Callbacks . packument ( ( name ) => {
308- if ( ! packages . has ( name ) ) {
309- packages . set ( name , [ ] ) ;
310- }
311- } ) ,
312- Extractors . Callbacks . manifest ( ( spec , _ , parent ) => {
313- if ( packages . has ( parent . name ) ) {
314- packages . get ( parent . name ) ! . push ( spec ) ;
315- }
316- } )
317- ]
290+ const extractor = new Extractors . Payload ( expressNodesecurePayload , [
291+ Extractors . Callbacks . packument ( ( name ) => {
292+ if ( ! packages . has ( name ) ) {
293+ packages . set ( name , [ ] ) ;
294+ }
295+ } ) ,
296+ Extractors . Callbacks . manifest ( ( spec , _ , parent ) => {
297+ if ( packages . has ( parent . name ) ) {
298+ packages . get ( parent . name ) ! . push ( spec ) ;
299+ }
300+ } )
301+ ]
318302 ) ;
319303
320304 extractor . extract ( ) ;
0 commit comments