Skip to content

Commit 6a8ad25

Browse files
authored
refactor(testing): add custom snapshot serializer and serializer option to snapshotTest (#594)
1 parent 184e2ee commit 6a8ad25

23 files changed

+338
-280
lines changed

command/test/integration/__snapshots__/test.ts.snap

Lines changed: 91 additions & 101 deletions
Large diffs are not rendered by default.

prompt/test/integration/__snapshots__/checkbox_test.ts.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
export const snapshot = {};
22

33
snapshot[`checkbox prompt > should check an option 1`] = `
4-
"stdout:
5-
? Select an option
4+
stdout:
5+
"? Select an option
66
❯ ✘ Foo
77
✘ Bar
88
✘ Baz\\x1b[3A\\x1b[19G\\x1b[?25l\\x1b[G\\x1b[0J
@@ -19,7 +19,7 @@ snapshot[`checkbox prompt > should check an option 1`] = `
1919
✘ Bar
2020
❯ ✔ Baz\\x1b[3A\\x1b[19G\\x1b[?25l\\x1b[G\\x1b[0J
2121
? Select an option › Baz
22-
\\x1b[?25h\\x1b[?25h
22+
\\x1b[?25h\\x1b[?25h"
2323
stderr:
24-
"
24+
""
2525
`;

prompt/test/integration/__snapshots__/checkbox_test.ts.windows.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
export const snapshot = {};
22

33
snapshot[`checkbox prompt > should check an option 1`] = `
4-
"stdout:
5-
? Select an option
4+
stdout:
5+
"? Select an option
66
❯ × Foo
77
× Bar
88
× Baz\\x1b[3A\\x1b[19G\\x1b[?25l\\x1b[G\\x1b[0J
@@ -19,7 +19,7 @@ snapshot[`checkbox prompt > should check an option 1`] = `
1919
× Bar
2020
❯ √ Baz\\x1b[3A\\x1b[19G\\x1b[?25l\\x1b[G\\x1b[0J
2121
? Select an option » Baz
22-
\\x1b[?25h\\x1b[?25h
22+
\\x1b[?25h\\x1b[?25h"
2323
stderr:
24-
"
24+
""
2525
`;
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
export const snapshot = {};
22

33
snapshot[`confirm prompt > should confirm 1`] = `
4-
"stdout:
5-
? Please confirm (y/N) ›
4+
stdout:
5+
"? Please confirm (y/N) ›
66
❯ some hint\\x1b[1A\\x1b[26G\\x1b[G\\x1b[0J
77
? Please confirm (y/N) › yes
88
❯ some hint\\x1b[1A\\x1b[27G\\x1b[G\\x1b[0J
99
? Please confirm (y/N) › Yes
10-
\\x1b[?25h\\x1b[?25h
10+
\\x1b[?25h\\x1b[?25h"
1111
stderr:
12-
"
12+
""
1313
`;
1414

1515
snapshot[`confirm prompt > should not confirm 1`] = `
16-
"stdout:
17-
? Please confirm (y/N) ›
16+
stdout:
17+
"? Please confirm (y/N) ›
1818
❯ some hint\\x1b[1A\\x1b[26G\\x1b[G\\x1b[0J
1919
? Please confirm (y/N) › no
2020
❯ some hint\\x1b[1A\\x1b[27G\\x1b[G\\x1b[0J
2121
? Please confirm (y/N) › No
22-
\\x1b[?25h\\x1b[?25h
22+
\\x1b[?25h\\x1b[?25h"
2323
stderr:
24-
"
24+
""
2525
`;
2626

2727
snapshot[`confirm prompt > should not confirm by default 1`] = `
28-
"stdout:
29-
? Please confirm (y/N) ›
28+
stdout:
29+
"? Please confirm (y/N) ›
3030
❯ some hint\\x1b[1A\\x1b[26G\\x1b[G\\x1b[0J
3131
? Please confirm (y/N) › No
32-
\\x1b[?25h\\x1b[?25h
32+
\\x1b[?25h\\x1b[?25h"
3333
stderr:
34-
"
34+
""
3535
`;
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
export const snapshot = {};
22

33
snapshot[`confirm prompt > should confirm 1`] = `
4-
"stdout:
5-
? Please confirm (y/N) »
4+
stdout:
5+
"? Please confirm (y/N) »
66
❯ some hint\\x1b[1A\\x1b[26G\\x1b[G\\x1b[0J
77
? Please confirm (y/N) » yes
88
❯ some hint\\x1b[1A\\x1b[27G\\x1b[G\\x1b[0J
99
? Please confirm (y/N) » Yes
10-
\\x1b[?25h\\x1b[?25h
10+
\\x1b[?25h\\x1b[?25h"
1111
stderr:
12-
"
12+
""
1313
`;
1414

1515
snapshot[`confirm prompt > should not confirm 1`] = `
16-
"stdout:
17-
? Please confirm (y/N) »
16+
stdout:
17+
"? Please confirm (y/N) »
1818
❯ some hint\\x1b[1A\\x1b[26G\\x1b[G\\x1b[0J
1919
? Please confirm (y/N) » no
2020
❯ some hint\\x1b[1A\\x1b[27G\\x1b[G\\x1b[0J
2121
? Please confirm (y/N) » No
22-
\\x1b[?25h\\x1b[?25h
22+
\\x1b[?25h\\x1b[?25h"
2323
stderr:
24-
"
24+
""
2525
`;
2626

2727
snapshot[`confirm prompt > should not confirm by default 1`] = `
28-
"stdout:
29-
? Please confirm (y/N) »
28+
stdout:
29+
"? Please confirm (y/N) »
3030
❯ some hint\\x1b[1A\\x1b[26G\\x1b[G\\x1b[0J
3131
? Please confirm (y/N) » No
32-
\\x1b[?25h\\x1b[?25h
32+
\\x1b[?25h\\x1b[?25h"
3333
stderr:
34-
"
34+
""
3535
`;
Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,65 @@
11
export const snapshot = {};
22

33
snapshot[`input prompt > should enter some text 1`] = `
4-
"stdout:
5-
? Whats your name? (foo) › \\x1b[28G\\x1b[G\\x1b[0J
4+
stdout:
5+
"? Whats your name? (foo) › \\x1b[28G\\x1b[G\\x1b[0J
66
? Whats your name? (foo) › foo bar\\x1b[35G\\x1b[G\\x1b[0J
77
? Whats your name? (foo) › foo bar
8-
\\x1b[?25h\\x1b[?25h
8+
\\x1b[?25h\\x1b[?25h"
99
stderr:
10-
"
10+
""
1111
`;
1212

1313
snapshot[`input prompt with suggestions > should enable suggestions and list 1`] = `
14-
"stdout:
15-
? Whats your name? (foo) ›
14+
stdout:
15+
"? Whats your name? (foo) ›
1616
foo
1717
bar
1818
baz\\x1b[3A\\x1b[28G\\x1b[G\\x1b[0J
1919
? Whats your name? (foo) › foo
2020
❯ foo\\x1b[1A\\x1b[31G\\x1b[G\\x1b[0J
2121
? Whats your name? (foo) › foo
22-
\\x1b[?25h\\x1b[?25h
22+
\\x1b[?25h\\x1b[?25h"
2323
stderr:
24-
"
24+
""
2525
`;
2626

2727
snapshot[`input prompt with prefix > should change prefix 1`] = `
28-
"stdout:
29-
PREFIX Whats your name? (foo) › \\x1b[33G\\x1b[G\\x1b[0J
28+
stdout:
29+
"PREFIX Whats your name? (foo) › \\x1b[33G\\x1b[G\\x1b[0J
3030
PREFIX Whats your name? (foo) › bar\\x1b[36G\\x1b[G\\x1b[0J
3131
PREFIX Whats your name? (foo) › bar
32-
\\x1b[?25h\\x1b[?25h
32+
\\x1b[?25h\\x1b[?25h"
3333
stderr:
34-
"
34+
""
3535
`;
3636

3737
snapshot[`input prompt with writer set to stderr > should enter some text 1`] = `
38-
"stdout:
39-
38+
stdout:
39+
""
4040
stderr:
41-
? Whats your name? (foo) › \\x1b[28G\\x1b[G\\x1b[0J
41+
"? Whats your name? (foo) › \\x1b[28G\\x1b[G\\x1b[0J
4242
? Whats your name? (foo) › foo bar\\x1b[35G\\x1b[G\\x1b[0J
4343
? Whats your name? (foo) › foo bar
4444
\\x1b[?25h\\x1b[?25h"
4545
`;
4646

4747
snapshot[`input prompt without prefix > should disable prefix 1`] = `
48-
"stdout:
49-
Whats your name? (foo) › \\x1b[26G\\x1b[G\\x1b[0J
48+
stdout:
49+
"Whats your name? (foo) › \\x1b[26G\\x1b[G\\x1b[0J
5050
Whats your name? (foo) › bar\\x1b[29G\\x1b[G\\x1b[0J
5151
Whats your name? (foo) › bar
52-
\\x1b[?25h\\x1b[?25h
52+
\\x1b[?25h\\x1b[?25h"
5353
stderr:
54-
"
54+
""
5555
`;
5656

5757
snapshot[`input prompt with no location flag > should work without --location flag 1`] = `
58-
"stdout:
59-
? Works without --location? (hope so) › \\x1b[41G\\x1b[G\\x1b[0J
58+
stdout:
59+
"? Works without --location? (hope so) › \\x1b[41G\\x1b[G\\x1b[0J
6060
? Works without --location? (hope so) › yes\\x1b[44G\\x1b[G\\x1b[0J
6161
? Works without --location? (hope so) › yes
62-
\\x1b[?25h\\x1b[?25h
62+
\\x1b[?25h\\x1b[?25h"
6363
stderr:
64-
"
64+
""
6565
`;
Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,65 @@
11
export const snapshot = {};
22

33
snapshot[`input prompt > should enter some text 1`] = `
4-
"stdout:
5-
? Whats your name? (foo) » \\x1b[28G\\x1b[G\\x1b[0J
4+
stdout:
5+
"? Whats your name? (foo) » \\x1b[28G\\x1b[G\\x1b[0J
66
? Whats your name? (foo) » foo bar\\x1b[35G\\x1b[G\\x1b[0J
77
? Whats your name? (foo) » foo bar
8-
\\x1b[?25h\\x1b[?25h
8+
\\x1b[?25h\\x1b[?25h"
99
stderr:
10-
"
10+
""
1111
`;
1212

1313
snapshot[`input prompt with suggestions > should enable suggestions and list 1`] = `
14-
"stdout:
15-
? Whats your name? (foo) »
14+
stdout:
15+
"? Whats your name? (foo) »
1616
foo
1717
bar
1818
baz\\x1b[3A\\x1b[28G\\x1b[G\\x1b[0J
1919
? Whats your name? (foo) » foo
2020
❯ foo\\x1b[1A\\x1b[31G\\x1b[G\\x1b[0J
2121
? Whats your name? (foo) » foo
22-
\\x1b[?25h\\x1b[?25h
22+
\\x1b[?25h\\x1b[?25h"
2323
stderr:
24-
"
24+
""
2525
`;
2626

2727
snapshot[`input prompt with prefix > should change prefix 1`] = `
28-
"stdout:
29-
PREFIX Whats your name? (foo) » \\x1b[33G\\x1b[G\\x1b[0J
28+
stdout:
29+
"PREFIX Whats your name? (foo) » \\x1b[33G\\x1b[G\\x1b[0J
3030
PREFIX Whats your name? (foo) » bar\\x1b[36G\\x1b[G\\x1b[0J
3131
PREFIX Whats your name? (foo) » bar
32-
\\x1b[?25h\\x1b[?25h
32+
\\x1b[?25h\\x1b[?25h"
3333
stderr:
34-
"
34+
""
3535
`;
3636

3737
snapshot[`input prompt with writer set to stderr > should enter some text 1`] = `
38-
"stdout:
39-
38+
stdout:
39+
""
4040
stderr:
41-
? Whats your name? (foo) » \\x1b[28G\\x1b[G\\x1b[0J
41+
"? Whats your name? (foo) » \\x1b[28G\\x1b[G\\x1b[0J
4242
? Whats your name? (foo) » foo bar\\x1b[35G\\x1b[G\\x1b[0J
4343
? Whats your name? (foo) » foo bar
4444
\\x1b[?25h\\x1b[?25h"
4545
`;
4646

4747
snapshot[`input prompt without prefix > should disable prefix 1`] = `
48-
"stdout:
49-
Whats your name? (foo) » \\x1b[26G\\x1b[G\\x1b[0J
48+
stdout:
49+
"Whats your name? (foo) » \\x1b[26G\\x1b[G\\x1b[0J
5050
Whats your name? (foo) » bar\\x1b[29G\\x1b[G\\x1b[0J
5151
Whats your name? (foo) » bar
52-
\\x1b[?25h\\x1b[?25h
52+
\\x1b[?25h\\x1b[?25h"
5353
stderr:
54-
"
54+
""
5555
`;
5656

5757
snapshot[`input prompt with no location flag > should work without --location flag 1`] = `
58-
"stdout:
59-
? Works without --location? (hope so) » \\x1b[41G\\x1b[G\\x1b[0J
58+
stdout:
59+
"? Works without --location? (hope so) » \\x1b[41G\\x1b[G\\x1b[0J
6060
? Works without --location? (hope so) » yes\\x1b[44G\\x1b[G\\x1b[0J
6161
? Works without --location? (hope so) » yes
62-
\\x1b[?25h\\x1b[?25h
62+
\\x1b[?25h\\x1b[?25h"
6363
stderr:
64-
"
64+
""
6565
`;
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
export const snapshot = {};
22

33
snapshot[`list prompt > should enter some keywords 1`] = `
4-
"stdout:
5-
? Enter some keywords (foo, far) ›
4+
stdout:
5+
"? Enter some keywords (foo, far) ›
66
❯ some hint...\\x1b[1A\\x1b[36G\\x1b[G\\x1b[0J
77
? Enter some keywords (foo, far) › foo, bar
88
❯ some hint...\\x1b[1A\\x1b[44G\\x1b[G\\x1b[0J
99
? Enter some keywords (foo, far) › foo, bar
10-
\\x1b[?25h\\x1b[?25h
10+
\\x1b[?25h\\x1b[?25h"
1111
stderr:
12-
"
12+
""
1313
`;
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
export const snapshot = {};
22

33
snapshot[`list prompt > should enter some keywords 1`] = `
4-
"stdout:
5-
? Enter some keywords (foo, far) »
4+
stdout:
5+
"? Enter some keywords (foo, far) »
66
❯ some hint...\\x1b[1A\\x1b[36G\\x1b[G\\x1b[0J
77
? Enter some keywords (foo, far) » foo, bar
88
❯ some hint...\\x1b[1A\\x1b[44G\\x1b[G\\x1b[0J
99
? Enter some keywords (foo, far) » foo, bar
10-
\\x1b[?25h\\x1b[?25h
10+
\\x1b[?25h\\x1b[?25h"
1111
stderr:
12-
"
12+
""
1313
`;
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
export const snapshot = {};
22

33
snapshot[`number prompt > should enter a number 1`] = `
4-
"stdout:
5-
? How old are you? (7) › \\x1b[26G\\x1b[G\\x1b[0J
4+
stdout:
5+
"? How old are you? (7) › \\x1b[26G\\x1b[G\\x1b[0J
66
? How old are you? (7) › 19\\x1b[28G\\x1b[G\\x1b[0J
77
? How old are you? (7) › 20\\x1b[27G\\x1b[G\\x1b[0J
88
? How old are you? (7) › 21\\x1b[27G\\x1b[G\\x1b[0J
@@ -14,21 +14,21 @@ snapshot[`number prompt > should enter a number 1`] = `
1414
? How old are you? (7) › 19\\x1b[27G\\x1b[G\\x1b[0J
1515
? How old are you? (7) › 20\\x1b[27G\\x1b[G\\x1b[0J
1616
? How old are you? (7) › 20
17-
\\x1b[?25h\\x1b[?25h
17+
\\x1b[?25h\\x1b[?25h"
1818
stderr:
19-
"
19+
""
2020
`;
2121

2222
snapshot[`number prompt with float > should enter a floating number 1`] = `
23-
"stdout:
24-
? How old are you? (7) › \\x1b[26G\\x1b[G\\x1b[0J
23+
stdout:
24+
"? How old are you? (7) › \\x1b[26G\\x1b[G\\x1b[0J
2525
? How old are you? (7) › 19.\\x1b[29G\\x1b[G\\x1b[0J
2626
? How old are you? (7) › 19.1\\x1b[29G\\x1b[G\\x1b[0J
2727
? How old are you? (7) › 19.2\\x1b[29G\\x1b[G\\x1b[0J
2828
? How old are you? (7) › 19.3\\x1b[29G\\x1b[G\\x1b[0J
2929
? How old are you? (7) › 19.4\\x1b[29G\\x1b[G\\x1b[0J
3030
? How old are you? (7) › 19.4
31-
\\x1b[?25h\\x1b[?25h
31+
\\x1b[?25h\\x1b[?25h"
3232
stderr:
33-
"
33+
""
3434
`;

0 commit comments

Comments
 (0)