Skip to content

Commit

Permalink
test: add unit test that shows failure
Browse files Browse the repository at this point in the history
  • Loading branch information
teodora-sandu committed May 6, 2022
1 parent 9a3bef3 commit 6811138
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions test/jest/unit/lib/formatters/iac-output/v1/index.spec.ts
Expand Up @@ -2,6 +2,7 @@ import {
createSarifOutputForIac,
shareResultsOutput,
} from '../../../../../../../src/lib/formatters/iac-output';
import * as iacOutputUtils from '../../../../../../../src/lib/formatters/iac-output/v1/utils';
import {
IacTestResponse,
AnnotatedIacIssue,
Expand Down Expand Up @@ -108,6 +109,26 @@ describe('createSarifOutputForIac', () => {
});
expect(location?.physicalLocation?.region).not.toBeDefined();
});

it('uses the base path if git not present', () => {
const getRepoRootSpy = jest.spyOn(iacOutputUtils, 'getRepoRoot');
getRepoRootSpy.mockImplementation(() => {
throw new Error();
});

const issue = createResponseIssue(SEVERITY.HIGH, { lineNumber: undefined });
const sarif = createSarifOutputForIac([issue]);

expect(
sarif.runs?.[0]?.originalUriBaseIds?.PROJECTROOT?.uri?.endsWith('snyk/'),
).toBeTruthy();
const location = sarif.runs?.[0]?.results?.[0]?.locations?.[0];
expect(location?.physicalLocation?.artifactLocation).toEqual({
uri: 'target_file.tf',
uriBaseId: 'PROJECTROOT',
});
expect(location?.physicalLocation?.region).not.toBeDefined();
});
});

describe('shareResultsOutput', () => {
Expand Down

0 comments on commit 6811138

Please sign in to comment.