1- import {
2- EmptyManifestError ,
3- inspect ,
4- RequiredPackagesMissingError ,
5- } from '../../lib' ;
1+ import { inspect } from '../../lib' ;
62import * as testUtils from '../test-utils' ;
73import { chdirWorkspaces , ensureVirtualenv } from '../test-utils' ;
84import * as depGraphLib from '@snyk/dep-graph' ;
@@ -12,6 +8,7 @@ import * as subProcess from '../../lib/dependencies/sub-process';
128import { SpawnSyncReturns } from 'child_process' ;
139import * as fs from 'fs' ;
1410import * as path from 'path' ;
11+ import { OpenSourceEcosystems } from '@snyk/error-catalog-nodejs-public' ;
1512
1613// Usually the setup of virtual environments can run for a while
1714jest . setTimeout ( 180000 ) ;
@@ -741,7 +738,7 @@ describe('inspect', () => {
741738
742739 await expect (
743740 async ( ) => await inspect ( '.' , FILENAMES . pip . manifest )
744- ) . rejects . toThrow ( 'Required packages missing: markupsafe ' ) ;
741+ ) . rejects . toThrow ( 'Missing required packages ' ) ;
745742 } ) ;
746743
747744 it ( 'should fail on nonexistent referenced local depedency' , async ( ) => {
@@ -751,7 +748,7 @@ describe('inspect', () => {
751748 tearDown = testUtils . activateVirtualenv ( workspace ) ;
752749
753750 await expect ( inspect ( '.' , FILENAMES . pip . manifest ) ) . rejects . toThrow (
754- 'Unparsable requirement line (Requirement line ./lib/nonexistent is a local path, but could not be parsed) '
751+ 'Unable to parse manifest file '
755752 ) ;
756753 } ) ;
757754
@@ -1101,7 +1098,7 @@ describe('inspect', () => {
11011098 testUtils . chdirWorkspaces ( 'pipfile-empty' ) ;
11021099 await expect (
11031100 async ( ) => await inspect ( '.' , FILENAMES . pipenv . manifest )
1104- ) . rejects . toThrow ( 'No dependencies detected in manifest' ) ;
1101+ ) . rejects . toThrow ( 'Empty manifest file ' ) ;
11051102 } ) ;
11061103 } ) ;
11071104
@@ -1227,31 +1224,48 @@ describe('inspect', () => {
12271224 } ) ;
12281225
12291226 describe ( 'manifest file is empty' , ( ) => {
1230- it ( 'should throw EmptyManifestError ' , async ( ) => {
1227+ it ( 'should throw PythonEmptyManifestError ' , async ( ) => {
12311228 mockedExecute . mockResolvedValueOnce ( 'Python 3.9.5' ) ;
12321229 mockedExecute . mockRejectedValueOnce (
12331230 'No dependencies detected in manifest.'
12341231 ) ;
12351232 const manifestFilePath = 'path/to/requirements.txt' ;
12361233
1237- await expect ( inspect ( '.' , manifestFilePath ) ) . rejects . toThrowError (
1238- new EmptyManifestError ( 'No dependencies detected in manifest.' )
1239- ) ;
1234+ const err = await inspect ( '.' , manifestFilePath ) . catch ( ( e ) => e ) ;
1235+
1236+ expect ( err ) . toBeInstanceOf ( OpenSourceEcosystems . EmptyManifestError ) ;
1237+ expect ( err ) . toMatchObject ( {
1238+ message : 'Empty manifest file' ,
1239+ detail : 'No dependencies detected in manifest.' ,
1240+ metadata : {
1241+ errorCode : 'SNYK-OS-0012' ,
1242+ } ,
1243+ isErrorCatalogError : true ,
1244+ } ) ;
12401245 } ) ;
12411246 } ) ;
12421247
12431248 describe ( 'required packages were not installed' , ( ) => {
1244- it ( 'should throw RequiredPackagesMissingError ' , async ( ) => {
1249+ it ( 'should throw PythonRequiredPackagesMissingError ' , async ( ) => {
12451250 mockedExecute . mockResolvedValueOnce ( 'Python 3.9.5' ) ;
12461251 mockedExecute . mockRejectedValueOnce ( 'Required packages missing' ) ;
12471252 const manifestFilePath = 'path/to/requirements.txt' ;
12481253
1249- await expect ( inspect ( '.' , manifestFilePath ) ) . rejects . toThrowError (
1250- new RequiredPackagesMissingError (
1251- 'Required packages missing\n' +
1252- 'Please run `pip install -r path/to/requirements.txt`. If the issue persists try again with --skip-unresolved.'
1253- )
1254+ const err = await inspect ( '.' , manifestFilePath ) . catch ( ( e ) => e ) ;
1255+
1256+ expect ( err ) . toBeInstanceOf (
1257+ OpenSourceEcosystems . PythonRequiredPackagesMissingError
12541258 ) ;
1259+ expect ( err ) . toMatchObject ( {
1260+ message : 'Missing required packages' ,
1261+ detail :
1262+ 'Required packages missing\n' +
1263+ 'Please run `pip install -r path/to/requirements.txt`. If the issue persists try again with --skip-unresolved.' ,
1264+ metadata : {
1265+ errorCode : 'SNYK-OS-PYTHON-0013' ,
1266+ } ,
1267+ isErrorCatalogError : true ,
1268+ } ) ;
12551269 } ) ;
12561270 } ) ;
12571271 } ) ;
0 commit comments