1
1
import defaultMessages from '@packages/frontend-shared/src/locales/en-US.json'
2
2
3
+ function getPathForPlatform ( posixPath : string ) {
4
+ if ( Cypress . platform === 'win32' ) return posixPath . replaceAll ( '/' , '\\' )
5
+
6
+ return posixPath
7
+ }
8
+
9
+ function getRunnerHref ( specPath : string ) {
10
+ specPath = getPathForPlatform ( specPath )
11
+
12
+ if ( Cypress . platform === 'win32' ) specPath = specPath . replaceAll ( '\\' , '%5C' )
13
+
14
+ return `#/specs/runner?file=${ specPath } `
15
+ }
16
+
3
17
describe ( 'App: Index' , ( ) => {
4
18
describe ( 'Testing Type: E2E' , ( ) => {
5
19
context ( 'project with default spec pattern' , ( ) => {
@@ -89,7 +103,7 @@ describe('App: Index', () => {
89
103
'waiting' ,
90
104
'window' ,
91
105
] . map ( ( file ) => `cypress/e2e/2-advanced-examples/${ file } .cy.js` ) ) ,
92
- ]
106
+ ] . map ( getPathForPlatform )
93
107
94
108
it ( 'scaffolds example files when card is clicked' , ( ) => {
95
109
cy . get ( '@ScaffoldCard' ) . click ( )
@@ -156,20 +170,20 @@ describe('App: Index', () => {
156
170
cy . findAllByLabelText ( defaultMessages . createSpec . e2e . importEmptySpec . inputPlaceholder )
157
171
. as ( 'enterSpecInput' )
158
172
159
- cy . get ( '@enterSpecInput' ) . invoke ( 'val' ) . should ( 'eq' , 'cypress/e2e/filename.cy.js' )
173
+ cy . get ( '@enterSpecInput' ) . invoke ( 'val' ) . should ( 'eq' , getPathForPlatform ( 'cypress/e2e/filename.cy.js' ) )
160
174
cy . contains ( defaultMessages . createSpec . e2e . importEmptySpec . invalidSpecWarning ) . should ( 'not.exist' )
161
175
cy . get ( '@enterSpecInput' ) . clear ( )
162
176
cy . contains ( defaultMessages . createSpec . e2e . importEmptySpec . invalidSpecWarning ) . should ( 'not.exist' )
163
177
164
178
// Shows entered file does not match spec pattern
165
- cy . get ( '@enterSpecInput' ) . type ( 'cypress/e2e/no-match' )
179
+ cy . get ( '@enterSpecInput' ) . type ( getPathForPlatform ( 'cypress/e2e/no-match' ) )
166
180
cy . contains ( defaultMessages . createSpec . e2e . importEmptySpec . invalidSpecWarning )
167
181
cy . contains ( 'button' , defaultMessages . createSpec . createSpec ) . should ( 'be.disabled' )
168
182
169
183
//Shows extension warning
170
- cy . get ( '@enterSpecInput' ) . clear ( ) . type ( 'cypress/e2e/MyTest.spec.j' )
184
+ cy . get ( '@enterSpecInput' ) . clear ( ) . type ( getPathForPlatform ( 'cypress/e2e/MyTest.spec.j' ) )
171
185
cy . intercept ( 'mutation-EmptyGenerator_MatchSpecFile' , ( req ) => {
172
- if ( req . body . variables . specFile === 'cypress/e2e/MyTest.spec.jx' ) {
186
+ if ( req . body . variables . specFile === getPathForPlatform ( 'cypress/e2e/MyTest.spec.jx' ) ) {
173
187
req . on ( 'before:response' , ( res ) => {
174
188
res . body . data . matchesSpecPattern = true
175
189
} )
@@ -181,11 +195,11 @@ describe('App: Index', () => {
181
195
cy . contains ( 'span' , '{filename}.cy.jx' )
182
196
183
197
// Create spec
184
- cy . get ( '@enterSpecInput' ) . clear ( ) . type ( 'cypress/e2e/MyTest.cy.js' )
198
+ cy . get ( '@enterSpecInput' ) . clear ( ) . type ( getPathForPlatform ( 'cypress/e2e/MyTest.cy.js' ) )
185
199
cy . contains ( 'button' , defaultMessages . createSpec . createSpec ) . should ( 'not.be.disabled' ) . click ( )
186
200
cy . contains ( 'h2' , defaultMessages . createSpec . successPage . header )
187
201
188
- cy . get ( '[data-cy="file-row"]' ) . contains ( 'cypress/e2e/MyTest.cy.js' ) . click ( )
202
+ cy . get ( '[data-cy="file-row"]' ) . contains ( getPathForPlatform ( 'cypress/e2e/MyTest.cy.js' ) ) . click ( )
189
203
190
204
// TODO: code rendering is flaky in CI
191
205
// cy.get('code').should('contain', 'describe(\'MyTest.cy.js\'')
@@ -279,11 +293,11 @@ describe('App: Index', () => {
279
293
it ( 'should create example files on an empty project' , ( ) => {
280
294
cy . contains ( '[data-cy="card"]' , defaultMessages . createSpec . e2e . importFromScaffold . header ) . click ( )
281
295
// TODO: Check that the popup stays open
282
- cy . withCtx ( async ( ctx ) => {
283
- const stats = await ctx . actions . file . checkIfFileExists ( 'cypress/e2e/1-getting-started/todo.cy.js' )
296
+ cy . withCtx ( async ( ctx , o ) => {
297
+ const stats = await ctx . actions . file . checkIfFileExists ( o . path )
284
298
285
299
expect ( stats ?. isFile ( ) ) . to . be . true
286
- } )
300
+ } , { path : getPathForPlatform ( 'cypress/e2e/1-getting-started/todo.cy.js' ) } )
287
301
} )
288
302
} )
289
303
} )
@@ -440,10 +454,10 @@ describe('App: Index', () => {
440
454
} ) . as ( 'SuccessDialog' ) . within ( ( ) => {
441
455
cy . validateExternalLink ( { name : 'Need help' , href : 'https://on.cypress.io' } )
442
456
cy . findByRole ( 'button' , { name : 'Close' } ) . should ( 'be.visible' )
443
- cy . contains ( 'src/stories/Button.stories.cy.jsx' ) . should ( 'be.visible' )
457
+ cy . contains ( getPathForPlatform ( 'src/stories/Button.stories.cy.jsx' ) ) . should ( 'be.visible' )
444
458
445
459
cy . findByRole ( 'link' , { name : 'Okay, run the spec' } )
446
- . should ( 'have.attr' , 'href' , '#/specs/runner?file= src/stories/Button.stories.cy.jsx')
460
+ . should ( 'have.attr' , 'href' , getRunnerHref ( ' src/stories/Button.stories.cy.jsx') )
447
461
448
462
cy . findByRole ( 'button' , { name : 'Create another spec' } ) . click ( )
449
463
} )
@@ -596,11 +610,11 @@ describe('App: Index', () => {
596
610
name : defaultMessages . createSpec . successPage . header ,
597
611
} ) . as ( 'SuccessDialog' ) . within ( ( ) => {
598
612
cy . validateExternalLink ( { name : 'Need help' , href : 'https://on.cypress.io' } )
599
- cy . contains ( 'src/App.cy.jsx' ) . should ( 'be.visible' )
613
+ cy . contains ( getPathForPlatform ( 'src/App.cy.jsx' ) ) . should ( 'be.visible' )
600
614
cy . findByRole ( 'button' , { name : 'Close' } ) . should ( 'be.visible' )
601
615
602
616
cy . findByRole ( 'link' , { name : 'Okay, run the spec' } )
603
- . should ( 'have.attr' , 'href' , '#/specs/runner?file= src/App.cy.jsx')
617
+ . should ( 'have.attr' , 'href' , getRunnerHref ( ' src/App.cy.jsx') )
604
618
605
619
cy . findByRole ( 'button' , { name : 'Create another spec' } ) . click ( )
606
620
} )
@@ -626,7 +640,7 @@ describe('App: Index', () => {
626
640
cy . findByRole ( 'dialog' , { name : defaultMessages . createSpec . successPage . header } ) . as ( 'SuccessDialog' ) . within ( ( ) => {
627
641
cy . findByRole ( 'link' , {
628
642
name : 'Okay, run the spec' ,
629
- } ) . should ( 'have.attr' , 'href' , '#/specs/runner?file= src/App.cy.jsx') . click ( )
643
+ } ) . should ( 'have.attr' , 'href' , getRunnerHref ( ' src/App.cy.jsx') ) . click ( )
630
644
} )
631
645
632
646
cy . findByTestId ( 'spec-gen-component-app' , { timeout : 5000 } ) . should ( 'be.visible' )
@@ -713,7 +727,7 @@ describe('App: Index', () => {
713
727
714
728
cy . get ( '[data-cy=file-list-row]' ) . first ( ) . click ( )
715
729
716
- cy . get ( 'input' ) . invoke ( 'val' ) . should ( 'eq' , 'src/App.cy.jsx' )
730
+ cy . get ( 'input' ) . invoke ( 'val' ) . should ( 'eq' , getPathForPlatform ( 'src/App.cy.jsx' ) )
717
731
cy . contains ( defaultMessages . createSpec . component . importEmptySpec . header )
718
732
719
733
cy . contains ( defaultMessages . components . button . cancel ) . click ( )
@@ -731,23 +745,23 @@ describe('App: Index', () => {
731
745
732
746
cy . get ( '[data-cy=file-list-row]' ) . first ( ) . click ( )
733
747
734
- cy . get ( 'input' ) . invoke ( 'val' ) . should ( 'eq' , 'src/App.cy.jsx' )
748
+ cy . get ( 'input' ) . invoke ( 'val' ) . should ( 'eq' , getPathForPlatform ( 'src/App.cy.jsx' ) )
735
749
cy . contains ( defaultMessages . createSpec . component . importEmptySpec . header )
736
750
cy . contains ( defaultMessages . createSpec . component . importEmptySpec . invalidComponentWarning )
737
751
cy . get ( 'input' ) . clear ( )
738
752
cy . contains ( defaultMessages . createSpec . component . importEmptySpec . invalidComponentWarning ) . should ( 'not.exist' )
739
753
cy . contains ( 'button' , defaultMessages . createSpec . createSpec ) . should ( 'be.disabled' )
740
754
741
- cy . get ( 'input' ) . clear ( ) . type ( 'src/specs-folder/MyTest.cy.jsx' )
755
+ cy . get ( 'input' ) . clear ( ) . type ( getPathForPlatform ( 'src/specs-folder/MyTest.cy.jsx' ) )
742
756
cy . contains ( 'button' , defaultMessages . createSpec . createSpec ) . should ( 'not.be.disabled' ) . click ( )
743
757
cy . contains ( 'h2' , defaultMessages . createSpec . successPage . header )
744
758
745
- cy . get ( '[data-cy="file-row"]' ) . contains ( 'src/specs-folder/MyTest.cy.jsx' ) . click ( )
759
+ cy . get ( '[data-cy="file-row"]' ) . contains ( getPathForPlatform ( 'src/specs-folder/MyTest.cy.jsx' ) ) . click ( )
746
760
747
761
cy . findByRole ( 'dialog' , { name : defaultMessages . createSpec . successPage . header } ) . as ( 'SuccessDialog' ) . within ( ( ) => {
748
762
cy . findByRole ( 'link' , {
749
763
name : 'Okay, run the spec' ,
750
- } ) . should ( 'have.attr' , 'href' , '#/specs/runner?file= src/specs-folder/MyTest.cy.jsx')
764
+ } ) . should ( 'have.attr' , 'href' , getRunnerHref ( ' src/specs-folder/MyTest.cy.jsx') )
751
765
} )
752
766
} )
753
767
@@ -761,23 +775,23 @@ describe('App: Index', () => {
761
775
762
776
cy . get ( '[data-cy=file-list-row]' ) . first ( ) . click ( )
763
777
764
- cy . get ( 'input' ) . invoke ( 'val' ) . should ( 'eq' , 'src/stories/Button.stories.cy.jsx' )
778
+ cy . get ( 'input' ) . invoke ( 'val' ) . should ( 'eq' , getPathForPlatform ( 'src/stories/Button.stories.cy.jsx' ) )
765
779
cy . contains ( defaultMessages . createSpec . component . importEmptySpec . header )
766
780
cy . contains ( defaultMessages . createSpec . component . importEmptySpec . invalidComponentWarning )
767
781
cy . get ( 'input' ) . clear ( )
768
782
cy . contains ( defaultMessages . createSpec . component . importEmptySpec . invalidComponentWarning ) . should ( 'not.exist' )
769
783
cy . contains ( 'button' , defaultMessages . createSpec . createSpec ) . should ( 'be.disabled' )
770
784
771
- cy . get ( 'input' ) . clear ( ) . type ( 'src/specs-folder/Button.stories.cy.jsx' )
785
+ cy . get ( 'input' ) . clear ( ) . type ( getPathForPlatform ( 'src/specs-folder/Button.stories.cy.jsx' ) )
772
786
cy . contains ( 'button' , defaultMessages . createSpec . createSpec ) . should ( 'not.be.disabled' ) . click ( )
773
787
cy . contains ( 'h2' , defaultMessages . createSpec . successPage . header )
774
788
775
- cy . get ( '[data-cy="file-row"]' ) . contains ( 'src/specs-folder/Button.stories.cy.jsx' ) . click ( )
789
+ cy . get ( '[data-cy="file-row"]' ) . contains ( getPathForPlatform ( 'src/specs-folder/Button.stories.cy.jsx' ) ) . click ( )
776
790
777
791
cy . findByRole ( 'dialog' , { name : defaultMessages . createSpec . successPage . header } ) . as ( 'SuccessDialog' ) . within ( ( ) => {
778
792
cy . findByRole ( 'link' , {
779
793
name : 'Okay, run the spec' ,
780
- } ) . should ( 'have.attr' , 'href' , '#/specs/runner?file= src/specs-folder/Button.stories.cy.jsx')
794
+ } ) . should ( 'have.attr' , 'href' , getRunnerHref ( ' src/specs-folder/Button.stories.cy.jsx') )
781
795
} )
782
796
} )
783
797
} )
@@ -821,15 +835,15 @@ describe('App: Index', () => {
821
835
. clear ( ) . type ( componentGlob , { parseSpecialCharSequences : false } )
822
836
823
837
cy . contains ( 'Button.jsx' ) . click ( )
824
- cy . findByTestId ( 'file-row' ) . contains ( 'src/stories/Button.cy.js' ) . click ( )
838
+ cy . findByTestId ( 'file-row' ) . contains ( getPathForPlatform ( 'src/stories/Button.cy.js' ) ) . click ( )
825
839
826
- cy . withCtx ( async ( ctx ) => {
840
+ cy . withCtx ( async ( ctx , o ) => {
827
841
const spec = (
828
842
await ctx . project . findSpecs ( ctx . currentProject ?? '' , 'component' , [ '**/*.cy.jsx' ] , [ ] , [ ] )
829
- ) . find ( ( spec ) => spec . relative === 'src/stories/Button.cy.jsx' )
843
+ ) . find ( ( spec ) => spec . relative === o . path )
830
844
831
845
expect ( spec ) . to . exist
832
- } )
846
+ } , { path : getPathForPlatform ( 'src/stories/Button.cy.jsx' ) } )
833
847
} )
834
848
835
849
it ( 'should generate spec from story' , ( ) => {
@@ -842,15 +856,15 @@ describe('App: Index', () => {
842
856
checkCodeGenCandidates ( [ 'Button.stories.jsx' ] )
843
857
844
858
cy . contains ( 'Button.stories.jsx' ) . click ( )
845
- cy . findByTestId ( 'file-row' ) . contains ( 'src/stories/Button.stories.cy.js' ) . click ( )
859
+ cy . findByTestId ( 'file-row' ) . contains ( getPathForPlatform ( 'src/stories/Button.stories.cy.js' ) ) . click ( )
846
860
cy . contains ( 'composeStories' )
847
861
848
- cy . withCtx ( async ( ctx ) => {
862
+ cy . withCtx ( async ( ctx , o ) => {
849
863
const spec = ( await ctx . project . findSpecs ( ctx . currentProject ?? '' , 'component' , [ '**/*.cy.jsx' ] , [ ] , [ ] ) )
850
- . find ( ( spec ) => spec . relative === 'src/stories/Button.stories.cy.jsx' )
864
+ . find ( ( spec ) => spec . relative === o . path )
851
865
852
866
expect ( spec ) . to . exist
853
- } )
867
+ } , { path : getPathForPlatform ( 'src/stories/Button.stories.cy.jsx' ) } )
854
868
} )
855
869
} )
856
870
} )
0 commit comments