Skip to content

Commit c7c8861

Browse files
novemberbornkevva
authored andcommitted
Add integration test for appending to an existing snapshot file
Doesn't verify that the generated Markdown changes, but at least the code paths are exercised.
1 parent d3139ac commit c7c8861

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

test/cli.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,42 @@ for (const obj of [
587587
});
588588
}
589589

590+
test('appends to existing snapshots', t => {
591+
const cliPath = require.resolve('../cli.js');
592+
const avaPath = require.resolve('../');
593+
594+
const cwd = uniqueTempDir({create: true});
595+
fs.writeFileSync(path.join(cwd, 'package.json'), '{}');
596+
597+
const initial = `import test from ${JSON.stringify(avaPath)}
598+
test('one', t => {
599+
t.snapshot({one: true})
600+
})`;
601+
fs.writeFileSync(path.join(cwd, 'test.js'), initial);
602+
603+
const run = () => execa(process.execPath, [cliPath, '--verbose', '--no-color'], {cwd, reject: false});
604+
return run().then(result => {
605+
t.match(result.stderr, /1 test passed/);
606+
607+
fs.writeFileSync(path.join(cwd, 'test.js'), `${initial}
608+
test('two', t => {
609+
t.snapshot({two: true})
610+
})`);
611+
return run();
612+
}).then(result => {
613+
t.match(result.stderr, /2 tests passed/);
614+
615+
fs.writeFileSync(path.join(cwd, 'test.js'), `${initial}
616+
test('two', t => {
617+
t.snapshot({two: false})
618+
})`);
619+
620+
return run();
621+
}).then(result => {
622+
t.match(result.stderr, /1 test failed/);
623+
});
624+
});
625+
590626
test('outdated snapshot version is reported to the console', t => {
591627
const snapPath = path.join(__dirname, 'fixture', 'snapshots', 'test.js.snap');
592628
fs.writeFileSync(snapPath, Buffer.from([0x0A, 0x00, 0x00]));

0 commit comments

Comments
 (0)