@@ -6,6 +6,7 @@ import assert from "node:assert";
66import { JsSourceParser } from "../../src/JsSourceParser.js" ;
77import { AstAnalyser } from "../../src/AstAnalyser.js" ;
88import { ProbeSignals } from "../../src/ProbeRunner.js" ;
9+ import { runASTAnalysis } from "../../index.js" ;
910
1011/**
1112 * @see https://github.com/NodeSecure/js-x-ray/issues/221
@@ -37,7 +38,7 @@ const customProbes = [
3738] ;
3839
3940test ( "should append to list of probes (default)" , ( ) => {
40- const analyser = new AstAnalyser ( new JsSourceParser ( ) , customProbes ) ;
41+ const analyser = new AstAnalyser ( new JsSourceParser ( ) , { customProbes } ) ;
4142 const result = analyser . analyse ( kIncriminedCodeSample ) ;
4243
4344 assert . equal ( result . warnings [ 0 ] . kind , kWarningUnsafeDanger ) ;
@@ -47,9 +48,26 @@ test("should append to list of probes (default)", () => {
4748} ) ;
4849
4950test ( "should replace list of probes" , ( ) => {
50- const analyser = new AstAnalyser ( new JsSourceParser ( ) , customProbes , "replace" ) ;
51+ const analyser = new AstAnalyser ( new JsSourceParser ( ) , { customProbes, isReplacing : true } ) ;
5152 const result = analyser . analyse ( kIncriminedCodeSample ) ;
5253
5354 assert . equal ( result . warnings [ 0 ] . kind , kWarningUnsafeDanger ) ;
5455 assert . equal ( result . warnings . length , 1 ) ;
5556} ) ;
57+
58+
59+ test ( "should append list of probes using runASTAnalysis" , ( ) => {
60+ const result = runASTAnalysis ( kIncriminedCodeSample , { astOptions : { isReplacing : false , customProbes } } ) ;
61+
62+ assert . equal ( result . warnings [ 0 ] . kind , kWarningUnsafeDanger ) ;
63+ assert . equal ( result . warnings [ 1 ] . kind , kWarningUnsafeImport ) ;
64+ assert . equal ( result . warnings [ 2 ] . kind , kWarningUnsafeStmt ) ;
65+ assert . equal ( result . warnings . length , 3 ) ;
66+ } ) ;
67+
68+ test ( "should replace list of probes using runASTAnalysis" , ( ) => {
69+ const result = runASTAnalysis ( kIncriminedCodeSample , { astOptions : { isReplacing : true , customProbes } } ) ;
70+
71+ assert . equal ( result . warnings [ 0 ] . kind , kWarningUnsafeDanger ) ;
72+ assert . equal ( result . warnings . length , 1 ) ;
73+ } ) ;
0 commit comments