Skip to content

Commit adeb213

Browse files
committed
fix(Snapshot): add cwd replacement for snapshots so it works in CI
1 parent 955a97b commit adeb213

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

test/snapshots/test.ts.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Generated by [AVA](https://ava.li).
66

77
## it edits the file in place, embedding code snippets
88

9-
> File content matches
9+
> File content does not match
1010
1111
`# File types␊
1212
@@ -525,7 +525,7 @@ Generated by [AVA](https://ava.li).
525525
```␊
526526
`
527527

528-
> stdout matches
528+
> stdout does not match
529529
530530
`Embedding...␊
531531
Skipped 0 files ignored in '.gitignore'␊
@@ -572,15 +572,15 @@ Generated by [AVA](https://ava.li).
572572
test/fixtures/fixture-in-place.md#L461-L463 Unsupported file extension [binary], supported extensions are txt, ts, js, scss, rust, java, cpp, c, html, xml, md, yaml, json, json5, py, bash, sh, go, objectivec, php, cs, swift, rb, kotlin, scala, cr, puml, mermaid, cmake, proto, sql, hs, skipping code block␊
573573
test/fixtures/fixture-in-place.md#L467-L469 No code extension detected, skipping code block...␊
574574
test/fixtures/fixture-in-place.md#L473-L475 No comment detected in first line for block with extension ts␊
575-
test/fixtures/fixture-in-place.md#L479-L481 Found filename also-not-a-file in comment in first line, but file does not exist at /Users/zak/repos/embedme/test/fixtures/also-not-a-file!␊
576-
test/fixtures/fixture-in-place.md#L485-L487 Found filename this-file-does-not-exist.txt in comment in first line, but file does not exist at /Users/zak/repos/embedme/test/fixtures/this-file-does-not-exist.txt!␊
577-
test/fixtures/fixture-in-place.md#L491-L493 Found filename contains-codefence.md in comment in first line, but file does not exist at /Users/zak/repos/embedme/test/fixtures/contains-codefence.md!␊
578-
test/fixtures/fixture-in-place.md#L497-L503 Found filename contains-codefence.md in comment in first line, but file does not exist at /Users/zak/repos/embedme/test/fixtures/contains-codefence.md!␊
575+
test/fixtures/fixture-in-place.md#L479-L481 Found filename also-not-a-file in comment in first line, but file does not exist at ${cwd}/test/fixtures/also-not-a-file!␊
576+
test/fixtures/fixture-in-place.md#L485-L487 Found filename this-file-does-not-exist.txt in comment in first line, but file does not exist at ${cwd}/test/fixtures/this-file-does-not-exist.txt!␊
577+
test/fixtures/fixture-in-place.md#L491-L493 Found filename contains-codefence.md in comment in first line, but file does not exist at ${cwd}/test/fixtures/contains-codefence.md!␊
578+
test/fixtures/fixture-in-place.md#L497-L503 Found filename contains-codefence.md in comment in first line, but file does not exist at ${cwd}/test/fixtures/contains-codefence.md!␊
579579
test/fixtures/fixture-in-place.md#L507-L509 Incorrectly formatted line numbering string snippets/sample.ts#L1-2, Expecting Github formatting e.g. #L10-L20␊
580580
test/fixtures/fixture-in-place.md#L513-L515 Code block is empty & no preceding embedme comment, skipping...␊
581581
Writing test/fixtures/fixture-in-place.md with embedded changes.␊
582582
`
583583

584-
> stderr matches
584+
> stderr does not match
585585
586586
''

test/snapshots/test.ts.snap

-8 Bytes
Binary file not shown.

test/test.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import * as util from 'util';
55

66
const execAsync = util.promisify(exec);
77

8+
function stripCwd(str: string): string {
9+
return str.replace(new RegExp(process.cwd(), 'g'), '${cwd}');
10+
}
11+
812
// @see https://github.com/tj/commander.js/issues/561
913
test.failing('it aborts on unrecognised flags', async t => {
1014
await t.throwsAsync(() => execAsync(`node dist/embedme.js test/fixtures/fixture.md --this-is-not-a-valid-flag`));
@@ -42,9 +46,9 @@ test('it edits the file in place, embedding code snippets', async t => {
4246
// these assertions are expected to fail when output or supported files changes.
4347
// run yarn test:update to update the snapshots. This is useful in code reviews
4448
// to interpret what has changed in output.
45-
t.snapshot(after, 'File content matches');
46-
t.snapshot(stdout, 'stdout matches');
47-
t.snapshot(stderr, 'stderr matches');
49+
t.snapshot(after, 'File content does not match');
50+
t.snapshot(stripCwd(stdout), 'stdout does not match');
51+
t.snapshot(stderr, 'stderr does not match');
4852
});
4953

5054
test('it does not change source file with --dry-run', async t => {

0 commit comments

Comments
 (0)