@@ -231,43 +231,46 @@ describe('toUpperCaseDriveLetter', () => {
231231
232232describe ( 'shellQuote' , ( ) => {
233233 it . each `
234- platform | shell | str | expected
235- ${ 'win32' } | ${ undefined } | ${ 'plain text' } | ${ '"plain text"' }
236- ${ 'linux' } | ${ undefined } | ${ 'plain text' } | ${ 'plain\\ text' }
237- ${ 'win32' } | ${ 'powershell' } | ${ "with 'single quote'" } | ${ "'with ''single quote'''" }
238- ${ 'win32' } | ${ 'cmd.exe' } | ${ "with 'single quote'" } | ${ '"with \'single quote\'"' }
239- ${ 'linux' } | ${ '/bin/bash' } | ${ "with 'single quote'" } | ${ "with\\ \\'single\\ quote\\'" }
240- ${ 'darwin' } | ${ '/bin/zsh' } | ${ "with 'single quote'" } | ${ "with\\ \\'single\\ quote\\'" }
241- ${ 'darwin' } | ${ { path : '/bin/zsh' , args : [ '-l' ] } } | ${ "with 'single quote'" } | ${ "with\\ \\'single\\ quote\\'" }
242- ${ 'win32' } | ${ undefined } | ${ "with 'single quote'" } | ${ '"with \'single quote\'"' }
243- ${ 'linux' } | ${ undefined } | ${ "with 'single quote'" } | ${ "with\\ \\'single\\ quote\\'" }
244- ${ 'win32' } | ${ 'powershell' } | ${ 'with "double quote"' } | ${ '\'with ""double quote""\'' }
245- ${ 'win32' } | ${ 'cmd.exe' } | ${ 'with "double quote"' } | ${ '"with ""double quote"""' }
246- ${ 'linux' } | ${ 'bash' } | ${ 'with "double quote"' } | ${ 'with\\ \\"double\\ quote\\"' }
247- ${ 'win32' } | ${ 'powershell' } | ${ 'with $name.txt' } | ${ "'with $name.txt'" }
248- ${ 'win32' } | ${ 'cmd.exe' } | ${ 'with $name.txt' } | ${ '"with $name.txt"' }
249- ${ 'linux' } | ${ 'bash' } | ${ 'with $name.txt' } | ${ 'with\\ \\$name.txt' }
250- ${ 'win32' } | ${ 'powershell' } | ${ 'with \\$name\\.txt' } | ${ "'with \\$name\\.txt'" }
251- ${ 'win32' } | ${ 'cmd.exe' } | ${ 'with \\$name\\.txt' } | ${ '"with \\$name\\.txt"' }
252- ${ 'linux' } | ${ 'bash' } | ${ 'with \\$name\\.txt' } | ${ 'with\\ \\\\\\$name\\\\.txt' }
253- ${ 'linux' } | ${ { path : '/bin/sh' , args : [ '--login' ] } } | ${ 'with \\$name\\.txt' } | ${ 'with\\ \\\\\\$name\\\\.txt' }
254- ${ 'win32' } | ${ 'powershell' } | ${ '' } | ${ "''" }
255- ${ 'win32' } | ${ undefined } | ${ '' } | ${ '""' }
256- ${ 'darwin' } | ${ undefined } | ${ '' } | ${ '""' }
257- ${ 'win32' } | ${ 'powershell' } | ${ 'with \\ and \\\\' } | ${ "'with \\ and \\\\\\\\'" }
258- ${ 'win32' } | ${ undefined } | ${ 'with \\ and \\\\' } | ${ '"with \\ and \\\\\\\\"' }
259- ${ 'linux' } | ${ undefined } | ${ 'with \\ and \\\\' } | ${ 'with\\ \\\\\\ and\\ \\\\\\\\' }
260- ${ 'win32' } | ${ 'powershell' } | ${ 'something\\' } | ${ "'something\\'" }
261- ${ 'win32' } | ${ undefined } | ${ 'something\\' } | ${ 'something\\' }
262- ${ 'darwin' } | ${ undefined } | ${ 'something\\' } | ${ 'something\\\\' }
263- ${ 'win32' } | ${ 'powershell' } | ${ 'with `backtick' } | ${ "'with `backtick'" }
264- ${ 'win32' } | ${ undefined } | ${ 'with `backtick' } | ${ '"with `backtick"' }
265- ${ 'darwin' } | ${ undefined } | ${ 'with `backtick' } | ${ 'with\\ \\`backtick' }
266- ` ( 'can quote "$str" for $shell on $platform' , ( { platform, shell, str, expected } ) => {
267- jest . resetAllMocks ( ) ;
268- mockPlatform . mockReturnValueOnce ( platform ) ;
269- expect ( shellQuote ( str , shell ) ) . toEqual ( expected ) ;
270- } ) ;
234+ case | platform | shell | str | expected
235+ ${ 1 } | ${ 'win32' } | ${ undefined } | ${ 'plain text' } | ${ '"plain text"' }
236+ ${ 2 } | ${ 'linux' } | ${ undefined } | ${ 'plain text' } | ${ 'plain\\ text' }
237+ ${ 3 } | ${ 'win32' } | ${ 'powershell' } | ${ "with 'single quote'" } | ${ "'with ''single quote'''" }
238+ ${ 4 } | ${ 'win32' } | ${ 'cmd.exe' } | ${ "with 'single quote'" } | ${ '"with \'single quote\'"' }
239+ ${ 5 } | ${ 'linux' } | ${ '/bin/bash' } | ${ "with 'single quote'" } | ${ "with\\ \\'single\\ quote\\'" }
240+ ${ 6 } | ${ 'darwin' } | ${ '/bin/zsh' } | ${ "with 'single quote'" } | ${ "with\\ \\'single\\ quote\\'" }
241+ ${ 7 } | ${ 'darwin' } | ${ { path : '/bin/zsh' , args : [ '-l' ] } } | ${ "with 'single quote'" } | ${ "with\\ \\'single\\ quote\\'" }
242+ ${ 8 } | ${ 'win32' } | ${ undefined } | ${ "with 'single quote'" } | ${ '"with \'single quote\'"' }
243+ ${ 9 } | ${ 'linux' } | ${ undefined } | ${ "with 'single quote'" } | ${ "with\\ \\'single\\ quote\\'" }
244+ ${ 10 } | ${ 'win32' } | ${ 'powershell' } | ${ 'with "double quote"' } | ${ '\'with ""double quote""\'' }
245+ ${ 11 } | ${ 'win32' } | ${ 'cmd.exe' } | ${ 'with "double quote"' } | ${ '"with ""double quote"""' }
246+ ${ 12 } | ${ 'linux' } | ${ 'bash' } | ${ 'with "double quote"' } | ${ 'with\\ \\"double\\ quote\\"' }
247+ ${ 13 } | ${ 'win32' } | ${ 'powershell' } | ${ 'with $name.txt' } | ${ "'with $name.txt'" }
248+ ${ 14 } | ${ 'win32' } | ${ 'cmd.exe' } | ${ 'with $name.txt' } | ${ '"with $name.txt"' }
249+ ${ 15 } | ${ 'linux' } | ${ 'bash' } | ${ 'with $name.txt' } | ${ 'with\\ \\$name.txt' }
250+ ${ 16 } | ${ 'win32' } | ${ 'powershell' } | ${ 'with \\$name\\.txt' } | ${ "'with \\$name\\.txt'" }
251+ ${ 17 } | ${ 'win32' } | ${ 'cmd.exe' } | ${ 'with \\$name\\.txt' } | ${ '"with \\$name\\.txt"' }
252+ ${ 18 } | ${ 'linux' } | ${ 'bash' } | ${ 'with \\$name\\.txt' } | ${ 'with\\ \\\\\\$name\\\\.txt' }
253+ ${ 19 } | ${ 'linux' } | ${ { path : '/bin/sh' , args : [ '--login' ] } } | ${ 'with \\$name\\.txt' } | ${ 'with\\ \\\\\\$name\\\\.txt' }
254+ ${ 20 } | ${ 'win32' } | ${ 'powershell' } | ${ '' } | ${ "''" }
255+ ${ 21 } | ${ 'win32' } | ${ undefined } | ${ '' } | ${ '""' }
256+ ${ 22 } | ${ 'darwin' } | ${ undefined } | ${ '' } | ${ '""' }
257+ ${ 23 } | ${ 'win32' } | ${ 'powershell' } | ${ 'with \\ and \\\\' } | ${ "'with \\ and \\\\'\\" }
258+ ${ 24 } | ${ 'win32' } | ${ undefined } | ${ 'with \\ and \\\\' } | ${ '"with \\ and \\\\"' }
259+ ${ 25 } | ${ 'linux' } | ${ undefined } | ${ 'with \\ and \\\\' } | ${ 'with\\ \\\\\\ and\\ \\\\\\\\' }
260+ ${ 26 } | ${ 'win32' } | ${ 'powershell' } | ${ 'something\\' } | ${ "'something\\'\\" }
261+ ${ 27 } | ${ 'win32' } | ${ undefined } | ${ 'something\\' } | ${ '"something\\"' }
262+ ${ 28 } | ${ 'darwin' } | ${ undefined } | ${ 'something\\' } | ${ 'something\\\\' }
263+ ${ 29 } | ${ 'win32' } | ${ 'powershell' } | ${ 'with `backtick' } | ${ "'with `backtick'" }
264+ ${ 30 } | ${ 'win32' } | ${ undefined } | ${ 'with `backtick' } | ${ '"with `backtick"' }
265+ ${ 31 } | ${ 'darwin' } | ${ undefined } | ${ 'with `backtick' } | ${ 'with\\ \\`backtick' }
266+ ` (
267+ 'case $case: can quote "$str" for $shell on $platform' ,
268+ ( { platform, shell, str, expected } ) => {
269+ jest . resetAllMocks ( ) ;
270+ mockPlatform . mockReturnValueOnce ( platform ) ;
271+ expect ( shellQuote ( str , shell ) ) . toEqual ( expected ) ;
272+ }
273+ ) ;
271274} ) ;
272275it . each `
273276 name | e | matchString
@@ -481,3 +484,18 @@ describe('getValidJestCommand', () => {
481484 ] ) ;
482485 } ) ;
483486} ) ;
487+
488+ describe ( 'escapeQuotes' , ( ) => {
489+ it . each `
490+ case | inputString | expected
491+ ${ 'no quotes' } | ${ 'no quotes' } | ${ 'no quotes' }
492+ ${ 'single quotes' } | ${ "with 'single quotes'" } | ${ "with \\'single quotes\\'" }
493+ ${ 'double quotes' } | ${ 'with "double quotes"' } | ${ 'with \\"double quotes\\"' }
494+ ${ 'mixed quotes' } | ${ 'with "double" and \'single\'' } | ${ 'with \\"double\\" and \\\'single\\\'' }
495+ ${ 'escaped quotes' } | ${ 'with \\"escaped\\" quotes' } | ${ 'with \\\\"escaped\\\\" quotes' }
496+ ${ 'escaped quotes 2' } | ${ "with \\'escaped\\' quotes" } | ${ "with \\\\'escaped\\\\' quotes" }
497+ ${ 'escaped quotes 3' } | ${ 'with \\\'escaped\\\' and "quotes"' } | ${ 'with \\\\\'escaped\\\\\' and \\"quotes\\"' }
498+ ` ( '$case' , ( { inputString, expected } ) => {
499+ expect ( helper . escapeQuotes ( inputString ) ) . toEqual ( expected ) ;
500+ } ) ;
501+ } ) ;
0 commit comments