@@ -9,14 +9,18 @@ const defaultNpmModules = [
99
1010describe ( 'dependency-parser - parser()' , ( ) => {
1111 it ( 'should handle JS file with no dependencies' , ( ) => {
12- const parser = new Parser ( defaultNpmModules )
12+ const parser = new Parser ( {
13+ supportedNpmModules : defaultNpmModules ,
14+ } )
1315 const { dependencies } = parser . parse ( path . join ( __dirname , 'check-parser-fixtures' , 'no-dependencies.js' ) )
1416 expect ( dependencies . map ( d => d . filePath ) ) . toHaveLength ( 0 )
1517 } )
1618
1719 it ( 'should handle JS file with dependencies' , ( ) => {
1820 const toAbsolutePath = ( ...filepath : string [ ] ) => path . join ( __dirname , 'check-parser-fixtures' , 'simple-example' , ...filepath )
19- const parser = new Parser ( defaultNpmModules )
21+ const parser = new Parser ( {
22+ supportedNpmModules : defaultNpmModules ,
23+ } )
2024 const { dependencies } = parser . parse ( toAbsolutePath ( 'entrypoint.js' ) )
2125 expect ( dependencies . map ( d => d . filePath ) . sort ( ) ) . toEqual ( [
2226 toAbsolutePath ( 'dep1.js' ) ,
@@ -31,7 +35,9 @@ describe('dependency-parser - parser()', () => {
3135 it ( 'should report a missing entrypoint file' , ( ) => {
3236 const missingEntrypoint = path . join ( __dirname , 'check-parser-fixtures' , 'does-not-exist.js' )
3337 try {
34- const parser = new Parser ( defaultNpmModules )
38+ const parser = new Parser ( {
39+ supportedNpmModules : defaultNpmModules ,
40+ } )
3541 parser . parse ( missingEntrypoint )
3642 } catch ( err ) {
3743 expect ( err ) . toMatchObject ( { missingFiles : [ missingEntrypoint ] } )
@@ -41,7 +47,9 @@ describe('dependency-parser - parser()', () => {
4147 it ( 'should report missing check dependencies' , ( ) => {
4248 const toAbsolutePath = ( ...filepath : string [ ] ) => path . join ( __dirname , 'check-parser-fixtures' , ...filepath )
4349 try {
44- const parser = new Parser ( defaultNpmModules )
50+ const parser = new Parser ( {
51+ supportedNpmModules : defaultNpmModules ,
52+ } )
4553 parser . parse ( toAbsolutePath ( 'missing-dependencies.js' ) )
4654 } catch ( err ) {
4755 expect ( err ) . toMatchObject ( { missingFiles : [ toAbsolutePath ( 'does-not-exist.js' ) , toAbsolutePath ( 'does-not-exist2.js' ) ] } )
@@ -51,7 +59,9 @@ describe('dependency-parser - parser()', () => {
5159 it ( 'should report syntax errors' , ( ) => {
5260 const entrypoint = path . join ( __dirname , 'check-parser-fixtures' , 'syntax-error.js' )
5361 try {
54- const parser = new Parser ( defaultNpmModules )
62+ const parser = new Parser ( {
63+ supportedNpmModules : defaultNpmModules ,
64+ } )
5565 parser . parse ( entrypoint )
5666 } catch ( err ) {
5767 expect ( err ) . toMatchObject ( { parseErrors : [ { file : entrypoint , error : 'Unexpected token (4:70)' } ] } )
@@ -61,16 +71,29 @@ describe('dependency-parser - parser()', () => {
6171 it ( 'should report unsupported dependencies' , ( ) => {
6272 const entrypoint = path . join ( __dirname , 'check-parser-fixtures' , 'unsupported-dependencies.js' )
6373 try {
64- const parser = new Parser ( defaultNpmModules )
74+ const parser = new Parser ( {
75+ supportedNpmModules : defaultNpmModules ,
76+ } )
6577 parser . parse ( entrypoint )
6678 } catch ( err ) {
6779 expect ( err ) . toMatchObject ( { unsupportedNpmDependencies : [ { file : entrypoint , unsupportedDependencies : [ 'left-pad' , 'right-pad' ] } ] } )
6880 }
6981 } )
7082
83+ it ( 'should allow unsupported dependencies if configured to do so' , ( ) => {
84+ const entrypoint = path . join ( __dirname , 'check-parser-fixtures' , 'unsupported-dependencies.js' )
85+ const parser = new Parser ( {
86+ supportedNpmModules : defaultNpmModules ,
87+ checkUnsupportedModules : false ,
88+ } )
89+ parser . parse ( entrypoint )
90+ } )
91+
7192 it ( 'should handle circular dependencies' , ( ) => {
7293 const toAbsolutePath = ( ...filepath : string [ ] ) => path . join ( __dirname , 'check-parser-fixtures' , 'circular-dependencies' , ...filepath )
73- const parser = new Parser ( defaultNpmModules )
94+ const parser = new Parser ( {
95+ supportedNpmModules : defaultNpmModules ,
96+ } )
7497 const { dependencies } = parser . parse ( toAbsolutePath ( 'entrypoint.js' ) )
7598
7699 // Circular dependencies are allowed in Node.js
@@ -84,7 +107,9 @@ describe('dependency-parser - parser()', () => {
84107
85108 it ( 'should parse typescript dependencies' , ( ) => {
86109 const toAbsolutePath = ( ...filepath : string [ ] ) => path . join ( __dirname , 'check-parser-fixtures' , 'typescript-example' , ...filepath )
87- const parser = new Parser ( defaultNpmModules )
110+ const parser = new Parser ( {
111+ supportedNpmModules : defaultNpmModules ,
112+ } )
88113 const { dependencies } = parser . parse ( toAbsolutePath ( 'entrypoint.ts' ) )
89114 expect ( dependencies . map ( d => d . filePath ) . sort ( ) ) . toEqual ( [
90115 toAbsolutePath ( 'dep1.ts' ) ,
@@ -102,7 +127,9 @@ describe('dependency-parser - parser()', () => {
102127
103128 it ( 'should handle ES Modules' , ( ) => {
104129 const toAbsolutePath = ( ...filepath : string [ ] ) => path . join ( __dirname , 'check-parser-fixtures' , 'esmodules-example' , ...filepath )
105- const parser = new Parser ( defaultNpmModules )
130+ const parser = new Parser ( {
131+ supportedNpmModules : defaultNpmModules ,
132+ } )
106133 const { dependencies } = parser . parse ( toAbsolutePath ( 'entrypoint.js' ) )
107134 expect ( dependencies . map ( d => d . filePath ) . sort ( ) ) . toEqual ( [
108135 toAbsolutePath ( 'dep1.js' ) ,
@@ -113,7 +140,9 @@ describe('dependency-parser - parser()', () => {
113140
114141 it ( 'should handle Common JS and ES Modules' , ( ) => {
115142 const toAbsolutePath = ( ...filepath : string [ ] ) => path . join ( __dirname , 'check-parser-fixtures' , 'common-esm-example' , ...filepath )
116- const parser = new Parser ( defaultNpmModules )
143+ const parser = new Parser ( {
144+ supportedNpmModules : defaultNpmModules ,
145+ } )
117146 const { dependencies } = parser . parse ( toAbsolutePath ( 'entrypoint.mjs' ) )
118147 expect ( dependencies . map ( d => d . filePath ) . sort ( ) ) . toEqual ( [
119148 toAbsolutePath ( 'dep1.js' ) ,
@@ -130,21 +159,27 @@ describe('dependency-parser - parser()', () => {
130159 */
131160 it . skip ( 'should ignore cases where require is reassigned' , ( ) => {
132161 const entrypoint = path . join ( __dirname , 'check-parser-fixtures' , 'reassign-require.js' )
133- const parser = new Parser ( defaultNpmModules )
162+ const parser = new Parser ( {
163+ supportedNpmModules : defaultNpmModules ,
164+ } )
134165 parser . parse ( entrypoint )
135166 } )
136167
137168 // Checks run on Checkly are wrapped to support top level await.
138169 // For consistency with checks created via the UI, the CLI should support this as well.
139170 it ( 'should allow top-level await' , ( ) => {
140171 const entrypoint = path . join ( __dirname , 'check-parser-fixtures' , 'top-level-await.js' )
141- const parser = new Parser ( defaultNpmModules )
172+ const parser = new Parser ( {
173+ supportedNpmModules : defaultNpmModules ,
174+ } )
142175 parser . parse ( entrypoint )
143176 } )
144177
145178 it ( 'should allow top-level await in TypeScript' , ( ) => {
146179 const entrypoint = path . join ( __dirname , 'check-parser-fixtures' , 'top-level-await.ts' )
147- const parser = new Parser ( defaultNpmModules )
180+ const parser = new Parser ( {
181+ supportedNpmModules : defaultNpmModules ,
182+ } )
148183 parser . parse ( entrypoint )
149184 } )
150185} )
0 commit comments