| 
									
										
										
										
											2022-05-24 13:54:12 -07:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Copyright (c) Microsoft Corporation. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Licensed under the Apache License, Version 2.0 (the "License"); | 
					
						
							|  |  |  |  * you may not use this file except in compliance with the License. | 
					
						
							|  |  |  |  * You may obtain a copy of the License at | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * http://www.apache.org/licenses/LICENSE-2.0
 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Unless required by applicable law or agreed to in writing, software | 
					
						
							|  |  |  |  * distributed under the License is distributed on an "AS IS" BASIS, | 
					
						
							|  |  |  |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
					
						
							|  |  |  |  * See the License for the specific language governing permissions and | 
					
						
							|  |  |  |  * limitations under the License. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-05 16:47:39 -08:00
										 |  |  | import { test, expect, playwrightCtConfigText } from './playwright-test-fixtures'; | 
					
						
							| 
									
										
										
										
											2022-05-24 13:54:12 -07:00
										 |  |  | import fs from 'fs'; | 
					
						
							| 
									
										
										
										
											2024-03-25 23:50:45 +01:00
										 |  |  | import path from 'path'; | 
					
						
							| 
									
										
										
										
											2022-05-24 13:54:12 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | test.describe.configure({ mode: 'parallel' }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test('should work with the empty component list', async ({ runInlineTest }, testInfo) => { | 
					
						
							|  |  |  |   const result = await runInlineTest({ | 
					
						
							| 
									
										
										
										
											2024-02-05 16:47:39 -08:00
										 |  |  |     'playwright.config.ts': playwrightCtConfigText, | 
					
						
							| 
									
										
										
										
											2022-10-20 04:41:21 +02:00
										 |  |  |     'playwright/index.html': `<script type="module" src="./index.js"></script>`, | 
					
						
							| 
									
										
										
										
											2022-05-24 13:54:12 -07:00
										 |  |  |     'playwright/index.js': ``, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     'a.test.ts': `
 | 
					
						
							|  |  |  |       import { test, expect } from '@playwright/experimental-ct-react'; | 
					
						
							|  |  |  |       test('pass', async ({ mount }) => {}); | 
					
						
							|  |  |  |     `,
 | 
					
						
							|  |  |  |   }, { workers: 1 }); | 
					
						
							|  |  |  |   expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  |   expect(result.passed).toBe(1); | 
					
						
							| 
									
										
										
										
											2023-02-07 15:11:44 -08:00
										 |  |  |   const output = result.output; | 
					
						
							| 
									
										
										
										
											2022-05-24 13:54:12 -07:00
										 |  |  |   expect(output).toContain('transforming...'); | 
					
						
							| 
									
										
										
										
											2024-01-23 09:40:05 -08:00
										 |  |  |   expect(output.replace(/\\+/g, '/')).toContain('.cache/index.html'); | 
					
						
							| 
									
										
										
										
											2022-05-24 13:54:12 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   const metainfo = JSON.parse(fs.readFileSync(testInfo.outputPath('playwright/.cache/metainfo.json'), 'utf-8')); | 
					
						
							| 
									
										
										
										
											2022-09-15 15:24:01 -07:00
										 |  |  |   expect(metainfo.version).toEqual(require('playwright-core/package.json').version); | 
					
						
							|  |  |  |   expect(metainfo.viteVersion).toEqual(require('vite/package.json').version); | 
					
						
							| 
									
										
										
										
											2024-01-16 19:31:19 -08:00
										 |  |  |   expect(Object.entries(metainfo.deps)).toHaveLength(0); | 
					
						
							| 
									
										
										
										
											2023-03-03 23:28:33 +01:00
										 |  |  |   expect(Object.entries(metainfo.sources)).toHaveLength(9); | 
					
						
							| 
									
										
										
										
											2022-05-24 13:54:12 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test('should extract component list', async ({ runInlineTest }, testInfo) => { | 
					
						
							|  |  |  |   const result = await runInlineTest({ | 
					
						
							| 
									
										
										
										
											2024-02-05 16:47:39 -08:00
										 |  |  |     'playwright.config.ts': playwrightCtConfigText, | 
					
						
							| 
									
										
										
										
											2022-10-20 04:41:21 +02:00
										 |  |  |     'playwright/index.html': `<script type="module" src="./index.ts"></script>`, | 
					
						
							| 
									
										
										
										
											2022-05-24 13:54:12 -07:00
										 |  |  |     'playwright/index.ts': ``, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     'src/button.tsx': `
 | 
					
						
							|  |  |  |       export const Button = () => <button>Button</button>; | 
					
						
							|  |  |  |     `,
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     'src/components.tsx': `
 | 
					
						
							|  |  |  |       export const Component1 = () => <div>Component 1</div>; | 
					
						
							|  |  |  |       export const Component2 = () => <div>Component 2</div>; | 
					
						
							|  |  |  |     `,
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     'src/defaultExport.tsx': `
 | 
					
						
							|  |  |  |       export default () => <div>Default export</div>; | 
					
						
							|  |  |  |     `,
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     'src/clashingNames1.tsx': `
 | 
					
						
							|  |  |  |       export const ClashingName = () => <div>Clashing name 1</div>; | 
					
						
							|  |  |  |     `,
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     'src/clashingNames2.tsx': `
 | 
					
						
							|  |  |  |       export const ClashingName = () => <div>Clashing name 2</div>; | 
					
						
							|  |  |  |     `,
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     'src/one-import.spec.tsx': `
 | 
					
						
							|  |  |  |       import { test, expect } from '@playwright/experimental-ct-react'; | 
					
						
							|  |  |  |       import { Button } from './button'; | 
					
						
							|  |  |  |       test('pass', async ({ mount }) => { | 
					
						
							|  |  |  |         const component = await mount(<Button></Button>); | 
					
						
							|  |  |  |         await expect(component).toHaveText('Button'); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     `,
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     'src/named-imports.spec.tsx': `
 | 
					
						
							|  |  |  |       import { test, expect } from '@playwright/experimental-ct-react'; | 
					
						
							|  |  |  |       import { Component1, Component2 } from './components'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       test('pass 1', async ({ mount }) => { | 
					
						
							|  |  |  |         const component = await mount(<Component1></Component1>); | 
					
						
							|  |  |  |         await expect(component).toHaveText('Component 1'); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       test('pass 2', async ({ mount }) => { | 
					
						
							|  |  |  |         const component = await mount(<Component2></Component2>); | 
					
						
							|  |  |  |         await expect(component).toHaveText('Component 2'); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     `,
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     'src/default-import.spec.tsx': `
 | 
					
						
							|  |  |  |       import { test, expect } from '@playwright/experimental-ct-react'; | 
					
						
							|  |  |  |       import DefaultComponent from './defaultExport'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       test('named', async ({ mount }) => { | 
					
						
							|  |  |  |         const component = await mount(<DefaultComponent></DefaultComponent>); | 
					
						
							|  |  |  |         await expect(component).toHaveText('Default export'); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     `,
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     'src/clashing-imports.spec.tsx': `
 | 
					
						
							|  |  |  |       import { test, expect } from '@playwright/experimental-ct-react'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       import DefaultComponent from './defaultExport.tsx'; | 
					
						
							|  |  |  |       import { ClashingName as CN1 } from './clashingNames1'; | 
					
						
							|  |  |  |       import { ClashingName as CN2 } from './clashingNames2'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       test('named', async ({ mount }) => { | 
					
						
							|  |  |  |         const component = await mount(<CN1></CN1>); | 
					
						
							|  |  |  |         await expect(component).toHaveText('Clashing name 1'); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       test('pass 2', async ({ mount }) => { | 
					
						
							|  |  |  |         const component = await mount(<CN2></CN2>); | 
					
						
							|  |  |  |         await expect(component).toHaveText('Clashing name 2'); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     `,
 | 
					
						
							| 
									
										
										
										
											2024-03-25 23:50:45 +01:00
										 |  |  |     'src/relative-import-different-folders/one/index.tsx': `
 | 
					
						
							|  |  |  |       export default () => <button>Button</button>; | 
					
						
							|  |  |  |     `,
 | 
					
						
							|  |  |  |     'src/relative-import-different-folders/one/one.spec.tsx': `
 | 
					
						
							|  |  |  |       import { test, expect } from '@playwright/experimental-ct-react'; | 
					
						
							|  |  |  |       import Button from '.'; | 
					
						
							|  |  |  |       test('pass', async ({ mount }) => { | 
					
						
							|  |  |  |         const component = await mount(<Button></Button>); | 
					
						
							|  |  |  |         await expect(component).toHaveText('Button'); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     `,
 | 
					
						
							|  |  |  |     'src/relative-import-different-folders/two/index.tsx': `
 | 
					
						
							|  |  |  |       export default () => <button>Button</button>; | 
					
						
							|  |  |  |     `,
 | 
					
						
							|  |  |  |     'src/relative-import-different-folders/two/two.spec.tsx': `
 | 
					
						
							|  |  |  |       import { test, expect } from '@playwright/experimental-ct-react'; | 
					
						
							|  |  |  |       import Button from '.'; | 
					
						
							|  |  |  |       test('pass', async ({ mount }) => { | 
					
						
							|  |  |  |         const component = await mount(<Button></Button>); | 
					
						
							|  |  |  |         await expect(component).toHaveText('Button'); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     `,
 | 
					
						
							| 
									
										
										
										
											2022-05-24 13:54:12 -07:00
										 |  |  |   }, { workers: 1 }); | 
					
						
							|  |  |  |   expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const metainfo = JSON.parse(fs.readFileSync(testInfo.outputPath('playwright/.cache/metainfo.json'), 'utf-8')); | 
					
						
							|  |  |  |   metainfo.components.sort((a, b) => { | 
					
						
							| 
									
										
										
										
											2024-02-07 20:39:45 -08:00
										 |  |  |     return (a.importSource + '/' + a.importedName).localeCompare(b.importSource + '/' + b.importedName); | 
					
						
							| 
									
										
										
										
											2022-05-24 13:54:12 -07:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   expect(metainfo.components).toEqual([{ | 
					
						
							| 
									
										
										
										
											2024-02-07 20:39:45 -08:00
										 |  |  |     id: expect.stringContaining('button_Button'), | 
					
						
							| 
									
										
										
										
											2024-01-12 20:02:27 -08:00
										 |  |  |     remoteName: 'Button', | 
					
						
							| 
									
										
										
										
											2024-02-07 20:39:45 -08:00
										 |  |  |     importSource: expect.stringContaining('./button'), | 
					
						
							|  |  |  |     filename: expect.stringContaining('one-import.spec.tsx'), | 
					
						
							| 
									
										
										
										
											2022-05-24 13:54:12 -07:00
										 |  |  |   }, { | 
					
						
							| 
									
										
										
										
											2024-02-07 20:39:45 -08:00
										 |  |  |     id: expect.stringContaining('clashingNames1_ClashingName'), | 
					
						
							| 
									
										
										
										
											2024-01-12 20:02:27 -08:00
										 |  |  |     remoteName: 'ClashingName', | 
					
						
							| 
									
										
										
										
											2024-02-07 20:39:45 -08:00
										 |  |  |     importSource: expect.stringContaining('./clashingNames1'), | 
					
						
							|  |  |  |     filename: expect.stringContaining('clashing-imports.spec.tsx'), | 
					
						
							| 
									
										
										
										
											2022-05-24 13:54:12 -07:00
										 |  |  |   }, { | 
					
						
							| 
									
										
										
										
											2024-02-07 20:39:45 -08:00
										 |  |  |     id: expect.stringContaining('clashingNames2_ClashingName'), | 
					
						
							| 
									
										
										
										
											2024-01-12 20:02:27 -08:00
										 |  |  |     remoteName: 'ClashingName', | 
					
						
							| 
									
										
										
										
											2024-02-07 20:39:45 -08:00
										 |  |  |     importSource: expect.stringContaining('./clashingNames2'), | 
					
						
							|  |  |  |     filename: expect.stringContaining('clashing-imports.spec.tsx'), | 
					
						
							| 
									
										
										
										
											2022-05-24 13:54:12 -07:00
										 |  |  |   }, { | 
					
						
							| 
									
										
										
										
											2024-02-07 20:39:45 -08:00
										 |  |  |     id: expect.stringContaining('components_Component1'), | 
					
						
							| 
									
										
										
										
											2024-01-12 20:02:27 -08:00
										 |  |  |     remoteName: 'Component1', | 
					
						
							| 
									
										
										
										
											2024-02-07 20:39:45 -08:00
										 |  |  |     importSource: expect.stringContaining('./components'), | 
					
						
							|  |  |  |     filename: expect.stringContaining('named-imports.spec.tsx'), | 
					
						
							| 
									
										
										
										
											2022-05-24 13:54:12 -07:00
										 |  |  |   }, { | 
					
						
							| 
									
										
										
										
											2024-02-07 20:39:45 -08:00
										 |  |  |     id: expect.stringContaining('components_Component2'), | 
					
						
							| 
									
										
										
										
											2024-01-12 20:02:27 -08:00
										 |  |  |     remoteName: 'Component2', | 
					
						
							| 
									
										
										
										
											2024-02-07 20:39:45 -08:00
										 |  |  |     importSource: expect.stringContaining('./components'), | 
					
						
							|  |  |  |     filename: expect.stringContaining('named-imports.spec.tsx'), | 
					
						
							| 
									
										
										
										
											2022-05-24 13:54:12 -07:00
										 |  |  |   }, { | 
					
						
							| 
									
										
										
										
											2024-02-07 20:39:45 -08:00
										 |  |  |     id: expect.stringContaining('defaultExport'), | 
					
						
							|  |  |  |     importSource: expect.stringContaining('./defaultExport'), | 
					
						
							|  |  |  |     filename: expect.stringContaining('default-import.spec.tsx'), | 
					
						
							| 
									
										
										
										
											2024-03-25 23:50:45 +01:00
										 |  |  |   }, { | 
					
						
							|  |  |  |     id: expect.stringContaining('_one'), | 
					
						
							|  |  |  |     importSource: expect.stringContaining('.'), | 
					
						
							|  |  |  |     filename: expect.stringContaining(`one${path.sep}one.spec.tsx`), | 
					
						
							|  |  |  |   }, { | 
					
						
							|  |  |  |     id: expect.stringContaining('_two'), | 
					
						
							|  |  |  |     importSource: expect.stringContaining('.'), | 
					
						
							|  |  |  |     filename: expect.stringContaining(`two${path.sep}two.spec.tsx`), | 
					
						
							| 
									
										
										
										
											2022-05-24 13:54:12 -07:00
										 |  |  |   }]); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-16 19:31:19 -08:00
										 |  |  |   for (const [, value] of Object.entries(metainfo.deps)) | 
					
						
							|  |  |  |     (value as string[]).sort(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   expect(Object.entries(metainfo.deps)).toEqual([ | 
					
						
							|  |  |  |     [expect.stringContaining('clashingNames1.tsx'), [ | 
					
						
							|  |  |  |       expect.stringContaining('jsx-runtime.js'), | 
					
						
							|  |  |  |       expect.stringContaining('clashingNames1.tsx'), | 
					
						
							|  |  |  |     ]], | 
					
						
							|  |  |  |     [expect.stringContaining('clashingNames2.tsx'), [ | 
					
						
							|  |  |  |       expect.stringContaining('jsx-runtime.js'), | 
					
						
							|  |  |  |       expect.stringContaining('clashingNames2.tsx'), | 
					
						
							|  |  |  |     ]], | 
					
						
							|  |  |  |     [expect.stringContaining('defaultExport.tsx'), [ | 
					
						
							|  |  |  |       expect.stringContaining('jsx-runtime.js'), | 
					
						
							|  |  |  |       expect.stringContaining('defaultExport.tsx'), | 
					
						
							|  |  |  |     ]], | 
					
						
							|  |  |  |     [expect.stringContaining('components.tsx'), [ | 
					
						
							|  |  |  |       expect.stringContaining('jsx-runtime.js'), | 
					
						
							|  |  |  |       expect.stringContaining('components.tsx'), | 
					
						
							|  |  |  |     ]], | 
					
						
							|  |  |  |     [expect.stringContaining('button.tsx'), [ | 
					
						
							|  |  |  |       expect.stringContaining('jsx-runtime.js'), | 
					
						
							|  |  |  |       expect.stringContaining('button.tsx'), | 
					
						
							|  |  |  |     ]], | 
					
						
							| 
									
										
										
										
											2024-03-25 23:50:45 +01:00
										 |  |  |     [expect.stringContaining(`one${path.sep}index.tsx`), [ | 
					
						
							|  |  |  |       expect.stringContaining('jsx-runtime.js'), | 
					
						
							|  |  |  |       expect.stringContaining(`one${path.sep}index.tsx`), | 
					
						
							|  |  |  |     ]], | 
					
						
							|  |  |  |     [expect.stringContaining(`two${path.sep}index.tsx`), [ | 
					
						
							|  |  |  |       expect.stringContaining('jsx-runtime.js'), | 
					
						
							|  |  |  |       expect.stringContaining(`two${path.sep}index.tsx`), | 
					
						
							|  |  |  |     ]], | 
					
						
							| 
									
										
										
										
											2024-01-16 19:31:19 -08:00
										 |  |  |   ]); | 
					
						
							| 
									
										
										
										
											2022-05-24 13:54:12 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test('should cache build', async ({ runInlineTest }, testInfo) => { | 
					
						
							| 
									
										
										
										
											2022-09-27 13:09:05 -07:00
										 |  |  |   test.slow(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-24 13:54:12 -07:00
										 |  |  |   await test.step('original test', async () => { | 
					
						
							|  |  |  |     const result = await runInlineTest({ | 
					
						
							| 
									
										
										
										
											2024-02-05 16:47:39 -08:00
										 |  |  |       'playwright.config.ts': playwrightCtConfigText, | 
					
						
							| 
									
										
										
										
											2022-10-20 04:41:21 +02:00
										 |  |  |       'playwright/index.html': `<script type="module" src="./index.ts"></script>`, | 
					
						
							| 
									
										
										
										
											2022-05-24 13:54:12 -07:00
										 |  |  |       'playwright/index.ts': ``, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       'src/button.tsx': `
 | 
					
						
							|  |  |  |         export const Button = () => <button>Button</button>; | 
					
						
							|  |  |  |       `,
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       'src/button.test.tsx': `
 | 
					
						
							| 
									
										
										
										
											2023-02-14 19:20:56 -08:00
										 |  |  |           import { test, expect } from '@playwright/experimental-ct-react'; | 
					
						
							| 
									
										
										
										
											2022-05-24 13:54:12 -07:00
										 |  |  |         import { Button } from './button.tsx'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         test('pass', async ({ mount }) => { | 
					
						
							|  |  |  |           const component = await mount(<Button></Button>); | 
					
						
							|  |  |  |           await expect(component).toHaveText('Button'); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       `,
 | 
					
						
							|  |  |  |     }, { workers: 1 }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  |     expect(result.passed).toBe(1); | 
					
						
							| 
									
										
										
										
											2023-02-07 15:11:44 -08:00
										 |  |  |     const output = result.output; | 
					
						
							| 
									
										
										
										
											2022-05-24 13:54:12 -07:00
										 |  |  |     expect(output, 'should rebuild bundle').toContain('modules transformed'); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   await test.step('re-run same test', async () => { | 
					
						
							| 
									
										
										
										
											2023-01-22 15:04:29 -08:00
										 |  |  |     const result = await runInlineTest({ | 
					
						
							| 
									
										
										
										
											2024-02-05 16:47:39 -08:00
										 |  |  |       'playwright.config.ts': playwrightCtConfigText, | 
					
						
							| 
									
										
										
										
											2023-01-22 15:04:29 -08:00
										 |  |  |     }, { workers: 1 }); | 
					
						
							| 
									
										
										
										
											2022-05-24 13:54:12 -07:00
										 |  |  |     expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  |     expect(result.passed).toBe(1); | 
					
						
							| 
									
										
										
										
											2023-02-07 15:11:44 -08:00
										 |  |  |     const output = result.output; | 
					
						
							| 
									
										
										
										
											2022-05-24 13:54:12 -07:00
										 |  |  |     expect(output, 'should not rebuild bundle').not.toContain('modules transformed'); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   await test.step('modify test', async () => { | 
					
						
							|  |  |  |     const result = await runInlineTest({ | 
					
						
							| 
									
										
										
										
											2024-02-05 16:47:39 -08:00
										 |  |  |       'playwright.config.ts': playwrightCtConfigText, | 
					
						
							| 
									
										
										
										
											2022-05-24 13:54:12 -07:00
										 |  |  |       'src/button.test.tsx': `
 | 
					
						
							| 
									
										
										
										
											2023-02-14 19:20:56 -08:00
										 |  |  |           import { test, expect } from '@playwright/experimental-ct-react'; | 
					
						
							| 
									
										
										
										
											2022-05-24 13:54:12 -07:00
										 |  |  |         import { Button } from './button.tsx'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         test('pass updated', async ({ mount }) => { | 
					
						
							|  |  |  |           const component = await mount(<Button></Button>); | 
					
						
							|  |  |  |           await expect(component).toHaveText('Button 2', { timeout: 200 }); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       `,
 | 
					
						
							|  |  |  |     }, { workers: 1 }); | 
					
						
							|  |  |  |     expect(result.exitCode).toBe(1); | 
					
						
							|  |  |  |     expect(result.passed).toBe(0); | 
					
						
							| 
									
										
										
										
											2023-02-07 15:11:44 -08:00
										 |  |  |     const output = result.output; | 
					
						
							| 
									
										
										
										
											2022-05-24 13:54:12 -07:00
										 |  |  |     expect(output, 'should not rebuild bundle').not.toContain('modules transformed'); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   await test.step('modify source', async () => { | 
					
						
							|  |  |  |     const result = await runInlineTest({ | 
					
						
							| 
									
										
										
										
											2024-02-05 16:47:39 -08:00
										 |  |  |       'playwright.config.ts': playwrightCtConfigText, | 
					
						
							| 
									
										
										
										
											2022-05-24 13:54:12 -07:00
										 |  |  |       'src/button.tsx': `
 | 
					
						
							|  |  |  |         export const Button = () => <button>Button 2</button>; | 
					
						
							|  |  |  |       `,
 | 
					
						
							|  |  |  |     }, { workers: 1 }); | 
					
						
							|  |  |  |     expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  |     expect(result.passed).toBe(1); | 
					
						
							| 
									
										
										
										
											2023-02-07 15:11:44 -08:00
										 |  |  |     const output = result.output; | 
					
						
							| 
									
										
										
										
											2022-05-24 13:54:12 -07:00
										 |  |  |     expect(output, 'should rebuild bundle').toContain('modules transformed'); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2022-08-12 10:37:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-09 18:39:20 -08:00
										 |  |  | test('should grow cache', async ({ runInlineTest }, testInfo) => { | 
					
						
							|  |  |  |   test.slow(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   await test.step('original test', async () => { | 
					
						
							|  |  |  |     const result = await runInlineTest({ | 
					
						
							| 
									
										
										
										
											2024-02-05 16:47:39 -08:00
										 |  |  |       'playwright.config.ts': playwrightCtConfigText, | 
					
						
							| 
									
										
										
										
											2023-02-09 18:39:20 -08:00
										 |  |  |       'playwright/index.html': `<script type="module" src="./index.ts"></script>`, | 
					
						
							|  |  |  |       'playwright/index.ts': ``, | 
					
						
							|  |  |  |       'src/button1.tsx': `
 | 
					
						
							|  |  |  |         export const Button1 = () => <button>Button 1</button>; | 
					
						
							|  |  |  |       `,
 | 
					
						
							|  |  |  |       'src/button2.tsx': `
 | 
					
						
							|  |  |  |         export const Button2 = () => <button>Button 2</button>; | 
					
						
							|  |  |  |       `,
 | 
					
						
							|  |  |  |       'src/button1.test.tsx': `
 | 
					
						
							| 
									
										
										
										
											2023-02-14 19:20:56 -08:00
										 |  |  |           import { test, expect } from '@playwright/experimental-ct-react'; | 
					
						
							| 
									
										
										
										
											2023-02-09 18:39:20 -08:00
										 |  |  |         import { Button1 } from './button1.tsx'; | 
					
						
							|  |  |  |         test('pass', async ({ mount }) => { | 
					
						
							|  |  |  |           const component = await mount(<Button1></Button1>); | 
					
						
							|  |  |  |           await expect(component).toHaveText('Button 1'); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       `,
 | 
					
						
							|  |  |  |       'src/button2.test.tsx': `
 | 
					
						
							| 
									
										
										
										
											2023-02-14 19:20:56 -08:00
										 |  |  |           import { test, expect } from '@playwright/experimental-ct-react'; | 
					
						
							| 
									
										
										
										
											2023-02-09 18:39:20 -08:00
										 |  |  |         import { Button2 } from './button2.tsx'; | 
					
						
							|  |  |  |         test('pass', async ({ mount }) => { | 
					
						
							|  |  |  |           const component = await mount(<Button2></Button2>); | 
					
						
							|  |  |  |           await expect(component).toHaveText('Button 2'); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       `,
 | 
					
						
							|  |  |  |     }, { workers: 1 }, undefined, { additionalArgs: ['button1'] }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  |     expect(result.passed).toBe(1); | 
					
						
							|  |  |  |     const output = result.output; | 
					
						
							|  |  |  |     expect(output).toContain('modules transformed'); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   await test.step('run second test', async () => { | 
					
						
							|  |  |  |     const result = await runInlineTest({ | 
					
						
							| 
									
										
										
										
											2024-02-05 16:47:39 -08:00
										 |  |  |       'playwright.config.ts': playwrightCtConfigText, | 
					
						
							| 
									
										
										
										
											2023-02-09 18:39:20 -08:00
										 |  |  |     }, { workers: 1 }, undefined, { additionalArgs: ['button2'] }); | 
					
						
							|  |  |  |     expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  |     expect(result.passed).toBe(1); | 
					
						
							|  |  |  |     const output = result.output; | 
					
						
							|  |  |  |     expect(output).toContain('modules transformed'); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   await test.step('run first test again', async () => { | 
					
						
							|  |  |  |     const result = await runInlineTest({ | 
					
						
							| 
									
										
										
										
											2024-02-05 16:47:39 -08:00
										 |  |  |       'playwright.config.ts': playwrightCtConfigText, | 
					
						
							| 
									
										
										
										
											2023-02-09 18:39:20 -08:00
										 |  |  |     }, { workers: 1 }, undefined, { additionalArgs: ['button2'] }); | 
					
						
							|  |  |  |     expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  |     expect(result.passed).toBe(1); | 
					
						
							|  |  |  |     const output = result.output; | 
					
						
							|  |  |  |     expect(output).not.toContain('modules transformed'); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-12 10:37:35 -07:00
										 |  |  | test('should not use global config for preview', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |   const result1 = await runInlineTest({ | 
					
						
							| 
									
										
										
										
											2024-02-05 16:47:39 -08:00
										 |  |  |     'playwright.config.ts': playwrightCtConfigText, | 
					
						
							| 
									
										
										
										
											2022-10-20 04:41:21 +02:00
										 |  |  |     'playwright/index.html': `<script type="module" src="./index.js"></script>`, | 
					
						
							| 
									
										
										
										
											2022-08-12 10:37:35 -07:00
										 |  |  |     'playwright/index.js': ``, | 
					
						
							|  |  |  |     'vite.config.js': `
 | 
					
						
							|  |  |  |       export default { | 
					
						
							|  |  |  |         plugins: [{ | 
					
						
							|  |  |  |           configurePreviewServer: () => { | 
					
						
							|  |  |  |             throw new Error('Original preview throws'); | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         }] | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  |     `,
 | 
					
						
							|  |  |  |     'a.test.ts': `
 | 
					
						
							|  |  |  |       import { test, expect } from '@playwright/experimental-ct-react'; | 
					
						
							|  |  |  |       test('pass', async ({ mount }) => {}); | 
					
						
							|  |  |  |     `,
 | 
					
						
							|  |  |  |   }, { workers: 1 }); | 
					
						
							|  |  |  |   expect(result1.exitCode).toBe(0); | 
					
						
							|  |  |  |   expect(result1.passed).toBe(1); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-22 15:04:29 -08:00
										 |  |  |   const result2 = await runInlineTest({ | 
					
						
							| 
									
										
										
										
											2024-02-05 16:47:39 -08:00
										 |  |  |     'playwright.config.ts': playwrightCtConfigText, | 
					
						
							| 
									
										
										
										
											2023-01-22 15:04:29 -08:00
										 |  |  |   }, { workers: 1 }); | 
					
						
							| 
									
										
										
										
											2022-08-12 10:37:35 -07:00
										 |  |  |   expect(result2.exitCode).toBe(0); | 
					
						
							|  |  |  |   expect(result2.passed).toBe(1); | 
					
						
							| 
									
										
										
										
											2022-12-29 02:04:23 +01:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test('should work with https enabled', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |     'playwright/index.html': `<script type="module" src="./index.js"></script>`, | 
					
						
							| 
									
										
										
										
											2023-02-14 19:20:56 -08:00
										 |  |  |     'playwright/index.js': ``, | 
					
						
							| 
									
										
										
										
											2022-12-29 02:04:23 +01:00
										 |  |  |     'playwright.config.js': `
 | 
					
						
							| 
									
										
										
										
											2023-01-22 15:04:29 -08:00
										 |  |  |       import { defineConfig } from '@playwright/experimental-ct-react'; | 
					
						
							| 
									
										
										
										
											2022-12-29 02:04:23 +01:00
										 |  |  |       import basicSsl from '@vitejs/plugin-basic-ssl'; | 
					
						
							| 
									
										
										
										
											2023-01-22 15:04:29 -08:00
										 |  |  |       export default defineConfig({ | 
					
						
							| 
									
										
										
										
											2022-12-29 02:04:23 +01:00
										 |  |  |         use: { | 
					
						
							|  |  |  |           ignoreHTTPSErrors: true, | 
					
						
							|  |  |  |           ctViteConfig: { | 
					
						
							|  |  |  |             plugins: [basicSsl()], | 
					
						
							|  |  |  |             preview: { | 
					
						
							|  |  |  |               https: true | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2023-01-22 15:04:29 -08:00
										 |  |  |       }); | 
					
						
							| 
									
										
										
										
											2022-12-29 02:04:23 +01:00
										 |  |  |     `,
 | 
					
						
							|  |  |  |     'http.test.tsx': `
 | 
					
						
							|  |  |  |       import { test, expect } from '@playwright/experimental-ct-react'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       test('pass', async ({ page }) => { | 
					
						
							|  |  |  |         await expect(page).toHaveURL(/https:.*/); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     `,
 | 
					
						
							|  |  |  |   }, { workers: 1 }); | 
					
						
							|  |  |  |   expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  |   expect(result.passed).toBe(1); | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2023-05-11 21:09:15 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | test('list compilation cache should not clash with the run one', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |   const listResult = await runInlineTest({ | 
					
						
							| 
									
										
										
										
											2024-02-05 16:47:39 -08:00
										 |  |  |     'playwright.config.ts': playwrightCtConfigText, | 
					
						
							| 
									
										
										
										
											2023-05-11 21:09:15 -07:00
										 |  |  |     'playwright/index.html': `<script type="module" src="./index.ts"></script>`, | 
					
						
							|  |  |  |     'playwright/index.ts': ``, | 
					
						
							|  |  |  |     'src/button.tsx': `
 | 
					
						
							|  |  |  |       export const Button = () => <button>Button</button>; | 
					
						
							|  |  |  |     `,
 | 
					
						
							|  |  |  |     'src/button.spec.tsx': `
 | 
					
						
							|  |  |  |       import { test, expect } from '@playwright/experimental-ct-react'; | 
					
						
							|  |  |  |       import { Button } from './button'; | 
					
						
							|  |  |  |       test('pass', async ({ mount }) => { | 
					
						
							|  |  |  |         const component = await mount(<Button></Button>); | 
					
						
							|  |  |  |         await expect(component).toHaveText('Button'); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     `,
 | 
					
						
							|  |  |  |   }, { workers: 1 }, {}, { additionalArgs: ['--list'] }); | 
					
						
							|  |  |  |   expect(listResult.exitCode).toBe(0); | 
					
						
							|  |  |  |   expect(listResult.passed).toBe(0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const runResult = await runInlineTest({}, { workers: 1 }); | 
					
						
							|  |  |  |   expect(runResult.exitCode).toBe(0); | 
					
						
							|  |  |  |   expect(runResult.passed).toBe(1); | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2023-08-24 16:19:57 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | test('should retain deps when test changes', async ({ runInlineTest }, testInfo) => { | 
					
						
							|  |  |  |   test.slow(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   await test.step('original test', async () => { | 
					
						
							|  |  |  |     const result = await runInlineTest({ | 
					
						
							| 
									
										
										
										
											2024-02-05 16:47:39 -08:00
										 |  |  |       'playwright.config.ts': playwrightCtConfigText, | 
					
						
							| 
									
										
										
										
											2023-08-24 16:19:57 -07:00
										 |  |  |       'playwright/index.html': `<script type="module" src="./index.ts"></script>`, | 
					
						
							|  |  |  |       'playwright/index.ts': ``, | 
					
						
							|  |  |  |       'src/button.tsx': `
 | 
					
						
							|  |  |  |         export const Button = () => <button>Button</button>; | 
					
						
							|  |  |  |       `,
 | 
					
						
							|  |  |  |       'src/button.test.tsx': `
 | 
					
						
							|  |  |  |         import { test, expect } from '@playwright/experimental-ct-react'; | 
					
						
							|  |  |  |         import { Button } from './button.tsx'; | 
					
						
							|  |  |  |         test('pass', async ({ mount }) => { | 
					
						
							|  |  |  |           const component = await mount(<Button></Button>); | 
					
						
							|  |  |  |           await expect(component).toHaveText('Button'); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       `,
 | 
					
						
							|  |  |  |     }, { workers: 1 }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  |     expect(result.passed).toBe(1); | 
					
						
							|  |  |  |     const output = result.output; | 
					
						
							|  |  |  |     expect(output).toContain('modules transformed'); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   await test.step('modify test and run it again', async () => { | 
					
						
							|  |  |  |     const result = await runInlineTest({ | 
					
						
							|  |  |  |       'src/button.test.tsx': `
 | 
					
						
							|  |  |  |         import { test, expect } from '@playwright/experimental-ct-react'; | 
					
						
							|  |  |  |         import { Button } from './button.tsx'; | 
					
						
							|  |  |  |         test('pass', async ({ mount }) => { | 
					
						
							|  |  |  |           const component1 = await mount(<Button></Button>); | 
					
						
							|  |  |  |           await expect(component1).toHaveText('Button'); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       `,
 | 
					
						
							|  |  |  |     }, { workers: 1 }); | 
					
						
							|  |  |  |     expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  |     expect(result.passed).toBe(1); | 
					
						
							|  |  |  |     const output = result.output; | 
					
						
							|  |  |  |     expect(output).not.toContain('modules transformed'); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const metainfo = JSON.parse(fs.readFileSync(testInfo.outputPath('playwright/.cache/metainfo.json'), 'utf-8')); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   expect(metainfo.components).toEqual([{ | 
					
						
							| 
									
										
										
										
											2024-02-07 20:39:45 -08:00
										 |  |  |     id: expect.stringContaining('button_tsx_Button'), | 
					
						
							| 
									
										
										
										
											2024-01-12 20:02:27 -08:00
										 |  |  |     remoteName: 'Button', | 
					
						
							| 
									
										
										
										
											2024-02-07 20:39:45 -08:00
										 |  |  |     importSource: expect.stringContaining('button.tsx'), | 
					
						
							|  |  |  |     filename: expect.stringContaining('button.test.tsx'), | 
					
						
							| 
									
										
										
										
											2023-08-24 16:19:57 -07:00
										 |  |  |   }]); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-16 19:31:19 -08:00
										 |  |  |   for (const [, value] of Object.entries(metainfo.deps)) | 
					
						
							|  |  |  |     (value as string[]).sort(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   expect(Object.entries(metainfo.deps)).toEqual([ | 
					
						
							| 
									
										
										
										
											2023-08-24 16:19:57 -07:00
										 |  |  |     [ | 
					
						
							| 
									
										
										
										
											2024-01-16 19:31:19 -08:00
										 |  |  |       expect.stringContaining('button.tsx'), | 
					
						
							|  |  |  |       [ | 
					
						
							|  |  |  |         expect.stringContaining('jsx-runtime.js'), | 
					
						
							|  |  |  |         expect.stringContaining('button.tsx'), | 
					
						
							|  |  |  |       ], | 
					
						
							| 
									
										
										
										
											2023-08-24 16:19:57 -07:00
										 |  |  |     ] | 
					
						
							|  |  |  |   ]); | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2024-01-16 19:31:19 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | test('should render component via re-export', async ({ runInlineTest }, testInfo) => { | 
					
						
							|  |  |  |   const result = await runInlineTest({ | 
					
						
							| 
									
										
										
										
											2024-02-05 16:47:39 -08:00
										 |  |  |     'playwright.config.ts': playwrightCtConfigText, | 
					
						
							| 
									
										
										
										
											2024-01-16 19:31:19 -08:00
										 |  |  |     'playwright/index.html': `<script type="module" src="./index.ts"></script>`, | 
					
						
							|  |  |  |     'playwright/index.ts': ``, | 
					
						
							|  |  |  |     'src/button.tsx': `
 | 
					
						
							|  |  |  |       export const Button = () => <button>Button</button>; | 
					
						
							|  |  |  |     `,
 | 
					
						
							|  |  |  |     'src/buttonHelper.ts': `
 | 
					
						
							|  |  |  |       import { Button } from './button.tsx'; | 
					
						
							|  |  |  |       export { Button }; | 
					
						
							|  |  |  |     `,
 | 
					
						
							|  |  |  |     'src/button.test.tsx': `
 | 
					
						
							|  |  |  |       import { test, expect } from '@playwright/experimental-ct-react'; | 
					
						
							|  |  |  |       import { Button } from './buttonHelper'; | 
					
						
							|  |  |  |       test('pass', async ({ mount }) => { | 
					
						
							|  |  |  |         const component = await mount(<Button></Button>); | 
					
						
							|  |  |  |         await expect(component).toHaveText('Button'); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     `,
 | 
					
						
							|  |  |  |   }, { workers: 1 }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  |   expect(result.passed).toBe(1); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-25 07:41:54 -07:00
										 |  |  | test('should import json', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |     'playwright.config.ts': playwrightCtConfigText, | 
					
						
							|  |  |  |     'playwright/index.html': `<script type="module" src="./index.ts"></script>`, | 
					
						
							|  |  |  |     'playwright/index.ts': ``, | 
					
						
							|  |  |  |     'src/some.json': `{ "some": "value" }`, | 
					
						
							|  |  |  |     'src/button.test.tsx': `
 | 
					
						
							|  |  |  |       import { test, expect } from '@playwright/experimental-ct-react'; | 
					
						
							|  |  |  |       import json from './some.json'; | 
					
						
							|  |  |  |       test('pass', async ({}) => { | 
					
						
							|  |  |  |         expect(json.some).toBe('value'); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     `,
 | 
					
						
							|  |  |  |   }, { workers: 1 }); | 
					
						
							|  |  |  |   expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  |   expect(result.passed).toBe(1); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-16 19:31:19 -08:00
										 |  |  | test('should render component exported via fixture', async ({ runInlineTest }, testInfo) => { | 
					
						
							|  |  |  |   const result = await runInlineTest({ | 
					
						
							| 
									
										
										
										
											2024-02-05 16:47:39 -08:00
										 |  |  |     'playwright.config.ts': playwrightCtConfigText, | 
					
						
							| 
									
										
										
										
											2024-01-16 19:31:19 -08:00
										 |  |  |     'playwright/index.html': `<script type="module" src="./index.ts"></script>`, | 
					
						
							|  |  |  |     'playwright/index.ts': ``, | 
					
						
							|  |  |  |     'src/button.tsx': `
 | 
					
						
							|  |  |  |       export const Button = () => <button>Button</button>; | 
					
						
							|  |  |  |     `,
 | 
					
						
							|  |  |  |     'src/buttonFixture.tsx': `
 | 
					
						
							|  |  |  |       import { Button } from './button'; | 
					
						
							|  |  |  |       import { test as baseTest } from '@playwright/experimental-ct-react'; | 
					
						
							|  |  |  |       export { expect } from '@playwright/experimental-ct-react'; | 
					
						
							|  |  |  |       export const test = baseTest.extend({ | 
					
						
							|  |  |  |         button: async ({ mount }, use) => { | 
					
						
							|  |  |  |           await use(await mount(<Button></Button>)); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     `,
 | 
					
						
							|  |  |  |     'src/button.test.tsx': `
 | 
					
						
							|  |  |  |       import { test, expect } from './buttonFixture'; | 
					
						
							|  |  |  |       test('pass', async ({ button }) => { | 
					
						
							|  |  |  |         await expect(button).toHaveText('Button'); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     `,
 | 
					
						
							|  |  |  |   }, { workers: 1 }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  |   expect(result.passed).toBe(1); | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2024-01-17 09:06:02 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | test('should pass imported images from test to component', async ({ runInlineTest }, testInfo) => { | 
					
						
							|  |  |  |   const result = await runInlineTest({ | 
					
						
							| 
									
										
										
										
											2024-02-05 16:47:39 -08:00
										 |  |  |     'playwright.config.ts': playwrightCtConfigText, | 
					
						
							| 
									
										
										
										
											2024-01-17 09:06:02 -08:00
										 |  |  |     'playwright/index.html': `<script type="module" src="./index.ts"></script>`, | 
					
						
							|  |  |  |     'playwright/index.ts': ``, | 
					
						
							|  |  |  |     'src/image.png': Buffer.from('iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAQAAAD9CzEMAAACMElEQVRYw+1XT0tCQRD/9Qci0Cw7mp1C6BMYnt5niMhPEEFCh07evNk54XnuGkhFehA/QxHkqYMEFWXpscMTipri7fqeu+vbfY+EoBkQ3Zn5zTo7MzsL/NNfoClkUUQNN3jCJ/ETfavRSpYkkSmFQzz8wMr4gaSp8OBJ2HCU4Iwd0kqGgd9GPxCccZ+0jWgWVW1wxlWy0qR51I3hv7lOllq7b4SC/+aGzr+QBadjEKgAykvzJGXwr/Lj4JfRk5hUSLKIa00HPUJRki0xeMWSWxVXmi5sddXKymqTyxdwquXAUVV3WREeLx3gTcNFWQY/jXtB8QIzgt4qTvAR4OCe0ATKCmrnmFMEM0Pp2BvrIisaFUdUjgKKZgYWSjjDLR5J+x13lATHuHSti6JBzQP+gq2QHXjfRaiJojbPgYqbmGFow0VpiyIW0/VIF9QKLzeBWA2MHmwCu8QJQV++Ps/joHQQH4HpuO0uobUeVztgIcr4Vnf4we9orWfUIWKHbEVyYKkPmaVpIVKICuo0ZYXWjHTITXWhsVYxkIDpUoKsla1i2Oz2QjvYG9fshu36GbFQ8DGyHNOuvRdOKZSDUtCFM7wyHeSM4XN8e7bOpd9F2gg+TRYal753bGkbuEjzMg0YW/yDV1czUDm+e43Byz86OnRwsYDMKXlmkYbeAOwffrtU/nGpXpwkXfPhVza+D9AiMAtrtOMYfVr0q8Wr1nh8n8ADZCJPqAk8AifyjP2n36cvkA6/Wln9MokAAAAASUVORK5CYII=', 'base64'), | 
					
						
							|  |  |  |     'src/image.test.tsx': `
 | 
					
						
							|  |  |  |       import { test, expect } from '@playwright/experimental-ct-react'; | 
					
						
							|  |  |  |       import imageSrc from './image.png'; | 
					
						
							|  |  |  |       test('pass', async ({ mount }) => { | 
					
						
							|  |  |  |         const component = await mount(<img src={imageSrc}></img>); | 
					
						
							|  |  |  |         await expect(component).toHaveJSProperty('naturalWidth', 48); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     `,
 | 
					
						
							|  |  |  |   }, { workers: 1 }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  |   expect(result.passed).toBe(1); | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2024-01-17 20:43:28 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | test('should pass dates, regex, urls and bigints', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |   const result = await runInlineTest({ | 
					
						
							| 
									
										
										
										
											2024-02-05 16:47:39 -08:00
										 |  |  |     'playwright.config.ts': playwrightCtConfigText, | 
					
						
							| 
									
										
										
										
											2024-01-17 20:43:28 -08:00
										 |  |  |     'playwright/index.html': `<script type="module" src="./index.ts"></script>`, | 
					
						
							|  |  |  |     'playwright/index.ts': ``, | 
					
						
							|  |  |  |     'src/button.tsx': `
 | 
					
						
							|  |  |  |       export const Button = ({ props }: any) => { | 
					
						
							|  |  |  |         const { date, url, bigint, regex } = props; | 
					
						
							|  |  |  |         const types = [ | 
					
						
							|  |  |  |           date instanceof Date, | 
					
						
							|  |  |  |           url instanceof URL, | 
					
						
							|  |  |  |           typeof bigint === 'bigint', | 
					
						
							|  |  |  |           regex instanceof RegExp, | 
					
						
							|  |  |  |         ]; | 
					
						
							|  |  |  |         return <div>{types.join(' ')}</div>; | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  |     `,
 | 
					
						
							|  |  |  |     'src/component.spec.tsx': `
 | 
					
						
							|  |  |  |       import { test, expect } from '@playwright/experimental-ct-react'; | 
					
						
							|  |  |  |       import { Button } from './button'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       test('renders props with builtin types', async ({ mount, page }) => { | 
					
						
							|  |  |  |         const component = await mount(<Button props={{ | 
					
						
							|  |  |  |           date: new Date(), | 
					
						
							|  |  |  |           url: new URL('https://example.com'), | 
					
						
							|  |  |  |           bigint: BigInt(42), | 
					
						
							|  |  |  |           regex: /foo/, | 
					
						
							|  |  |  |         }} />); | 
					
						
							|  |  |  |         await expect(component).toHaveText('true true true true'); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     `,
 | 
					
						
							|  |  |  |   }, { workers: 1 }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  |   expect(result.passed).toBe(1); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test('should pass undefined value as param', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |   const result = await runInlineTest({ | 
					
						
							| 
									
										
										
										
											2024-02-05 16:47:39 -08:00
										 |  |  |     'playwright.config.ts': playwrightCtConfigText, | 
					
						
							| 
									
										
										
										
											2024-01-17 20:43:28 -08:00
										 |  |  |     'playwright/index.html': `<script type="module" src="./index.ts"></script>`, | 
					
						
							|  |  |  |     'playwright/index.ts': ``, | 
					
						
							|  |  |  |     'src/component.tsx': `
 | 
					
						
							|  |  |  |       export const Component = ({ value }: { value?: number }) => { | 
					
						
							|  |  |  |         return <div>{typeof value}</div>; | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  |     `,
 | 
					
						
							|  |  |  |     'src/component.spec.tsx': `
 | 
					
						
							|  |  |  |       import { test, expect } from '@playwright/experimental-ct-react'; | 
					
						
							|  |  |  |       import { Component } from './component'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       test('renders props with undefined type', async ({ mount, page }) => { | 
					
						
							|  |  |  |         const component = await mount(<Component value={undefined} />); | 
					
						
							|  |  |  |         await expect(component).toHaveText('undefined'); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     `,
 | 
					
						
							|  |  |  |   }, { workers: 1 }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  |   expect(result.passed).toBe(1); | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2024-04-24 12:32:28 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | test('should resolve components imported from node_modules', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |     'package.json': `{ "name": "test-project" }`, | 
					
						
							|  |  |  |     'playwright.config.ts': playwrightCtConfigText, | 
					
						
							|  |  |  |     'playwright/index.html': `<script type="module" src="./index.js"></script>`, | 
					
						
							|  |  |  |     'playwright/index.js': ``, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     'node_modules/@mui/material/index.js': `
 | 
					
						
							|  |  |  |       const TextField = () => 'input'; | 
					
						
							|  |  |  |       module.exports = { TextField }; | 
					
						
							|  |  |  |     `,
 | 
					
						
							|  |  |  |     'node_modules/@mui/material/package.json': JSON.stringify({ | 
					
						
							|  |  |  |       name: '@mui/material', | 
					
						
							|  |  |  |       main: './index.js', | 
					
						
							|  |  |  |     }), | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     'src/component.spec.tsx': `
 | 
					
						
							|  |  |  |       import { test } from '@playwright/experimental-ct-react'; | 
					
						
							|  |  |  |       import { TextField } from '@mui/material'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       test("passes", async ({ mount }) => { | 
					
						
							|  |  |  |         await mount(<TextField />); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     `,
 | 
					
						
							|  |  |  |   }, { workers: 1 }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  |   expect(result.passed).toBe(1); | 
					
						
							|  |  |  | }); |