Skip to content

Commit

Permalink
fix: Tolerate absence of source_location in compare-report
Browse files Browse the repository at this point in the history
  • Loading branch information
zermelo-wisen committed Apr 22, 2024
1 parent 48a9425 commit 2596f36
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
8 changes: 6 additions & 2 deletions packages/cli/resources/change-report/failed-tests/details.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@
{{#each testFailures}}
<details>
<summary>
{{ testLocation }}
{{#if testLocation}}
{{ testLocation }}
{{else}}
{{ appmap.metadata.name }}
{{/if}}
</summary>

<p/>

<!-- testLocation -->
{{ source_link testLocation }} failed with error:
{{#if testLocation}}{{ source_link testLocation }}{{/if}} failed with error:

{{#if failureMessage}}
<!-- failureMessage -->
Expand Down
7 changes: 6 additions & 1 deletion packages/cli/src/report/urlHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ export default function urlHelpers(options: URLOptions): Record<string, (...args
let { baseDir } = options;
if (!baseDir) baseDir = process.cwd();

const source_url = (location: string, fileLinenoSeparator = '#L') => {
const source_url = (location: string | undefined, fileLinenoSeparator = '#L') => {
// source_location is optional in AppMap spec. Since this helper
// is called directly from Handlebars templates, declaring location
// as "location: string" does not guarantee its presence.
if (!location) return;

if (typeof fileLinenoSeparator === 'object') {
fileLinenoSeparator = '#L';
}
Expand Down
37 changes: 37 additions & 0 deletions packages/cli/tests/unit/compareReport/ChangeReporter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,41 @@ describe('ChangeReporter', () => {
\`\`\`
(apiDiff) Validation errors in "head": Swagger schema validation failed.`);
});

it('tolerates absence of source_location, which is optional in spec', async () => {
const appmapURL = 'https://appmap.example.com';
const changeReportData: ChangeReport = {
testFailures: [
{
appmap: "tmp/appmap/jest/test/the_test_that_failed",
name: "the test that failed"
},
],
newAppMaps: [],
removedAppMaps: [],
changedAppMaps: [],
appMapMetadata: {
base: {},
head: {
"tmp/appmap/jest/test/the_test_that_failed": {
client: {
"name": "appmap-node",
"url": "https://github.com/getappmap/appmap-node"
},
recorder: {
name: "jest"
},
name: "the test that failed",
test_status: "failed",
// no source_location here
}
},
},
sequenceDiagramDiff: {},
};
const changeReporter = new ChangeReporter(appmapURL);
const report = await changeReporter.generateReport(changeReportData);
expect(report).toContain("the test that failed");

})
});

0 comments on commit 2596f36

Please sign in to comment.