Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/snapshot-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ function formatEntry(snapshot, index) {
concordance.formatDescriptor(concordance.deserialize(data), concordanceOptions) :
'<No Data>';

return `> ${label}\n\n${indentString(description, 4)}`;
const blockquote = label.split(/\n/).map(line => '> ' + line).join('\n');

return `${blockquote}\n\n${indentString(description, 4)}`;
}

function combineEntries({blocks}) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
14 changes: 14 additions & 0 deletions test/snapshot-tests/fixtures/multiline-snapshot-label/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const test = require(process.env.TEST_AVA_IMPORT_FROM);

const f = () => {
return [
'Hello',
'World!'
].join(', ');
};

test('snapshot with a multiline label', t => {
const result = f();
const label = '```javascript\n' + f.toString() + '\n```';
t.snapshot(result, label);
});
24 changes: 24 additions & 0 deletions test/snapshot-tests/formatting.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import fs from 'fs';
import path from 'path';

import test from '@ava/test';

import {cwd, fixture} from '../helpers/exec.js';
import {withTemporaryFixture} from '../helpers/with-temporary-fixture.js';

test('multiline snapshot label should be formatted correctly in the report', async t => {
await withTemporaryFixture(cwd('multiline-snapshot-label'), async cwd => {
// Run test fixture
await fixture(['--update-snapshots'], {
cwd,
env: {
AVA_FORCE_CI: 'not-ci'
}
});

// Assert report is unchanged
const reportPath = path.join(cwd, 'test.js.md');
const report = fs.readFileSync(reportPath, {encoding: 'utf8'});
t.snapshot(report, 'resulting snapshot report');
});
});
29 changes: 29 additions & 0 deletions test/snapshot-tests/snapshots/formatting.js.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Snapshot report for `test/snapshot-tests/formatting.js`

The actual snapshot is saved in `formatting.js.snap`.

Generated by [AVA](https://avajs.dev).

## multiline snapshot label should be formatted correctly in the report

> resulting snapshot report

`# Snapshot report for \`test.js\`␊
The actual snapshot is saved in \`test.js.snap\`.␊
Generated by [AVA](https://avajs.dev).␊
## snapshot with a multiline label␊
> \`\`\`javascript␊
> () => {␊
> return [␊
> 'Hello',␊
> 'World!'␊
> ].join(', ');␊
> }␊
> \`\`\`␊
'Hello, World!'␊
`
Binary file added test/snapshot-tests/snapshots/formatting.js.snap
Binary file not shown.