| 
									
										
										
											
												feat(test runner): tags/annotations (#29248)
API changes:
- `test(title, details, body)` where details contain `tag` and
`annotation`.
- similar `details` property added to `test.skip`, `test.fail`,
`test.fixme`, `test.only`, `test.describe` and other `test.describe.*`
variations.
- `TestProject.tagFilter`/`TestConfig.tagFilter` that supports logical
tag expressions with `(`, `)`, `and`, `or` and `not`.
- `--tag` CLI option to filter by tags.
- New annotations are available in `TestInfo.annotations` and
`TestCase.annotations`.
- New tags are available in `TestCase.tags`.
    
Reporter changes:
- `json` reporter includes new tags in addition to old `@smoke`-style
tags. **Breaking**: tags are now listed with the leading `@` symbol.
- `html` reporter filters by old and new tags with the same `@smoke`
token.
Fixes #29229, fixes #23180.
											
										 
											2024-02-07 16:31:25 -08: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. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import { test, expect } from './playwright-test-fixtures'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test('should have correct tags', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |     'reporter.ts': `
 | 
					
						
							|  |  |  |       export default class Reporter { | 
					
						
							|  |  |  |         onBegin(config, suite) { | 
					
						
							|  |  |  |           const visit = suite => { | 
					
						
							|  |  |  |             for (const test of suite.tests || []) | 
					
						
							|  |  |  |               console.log('\\n%%title=' + test.title + ', tags=' + test.tags.join(',')); | 
					
						
							|  |  |  |             for (const child of suite.suites || []) | 
					
						
							|  |  |  |               visit(child); | 
					
						
							|  |  |  |           }; | 
					
						
							|  |  |  |           visit(suite); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         onError(error) { | 
					
						
							|  |  |  |           console.log(error); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     `,
 | 
					
						
							|  |  |  |     'playwright.config.ts': `
 | 
					
						
							|  |  |  |       module.exports = { | 
					
						
							|  |  |  |         reporter: './reporter', | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  |     `,
 | 
					
						
							|  |  |  |     'stdio.spec.js': `
 | 
					
						
							|  |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							|  |  |  |       test('no-tags', () => { | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2024-02-15 11:37:16 -08:00
										 |  |  |       test('foo-tag @inline', { tag: '@foo' }, () => { | 
					
						
							| 
									
										
										
											
												feat(test runner): tags/annotations (#29248)
API changes:
- `test(title, details, body)` where details contain `tag` and
`annotation`.
- similar `details` property added to `test.skip`, `test.fail`,
`test.fixme`, `test.only`, `test.describe` and other `test.describe.*`
variations.
- `TestProject.tagFilter`/`TestConfig.tagFilter` that supports logical
tag expressions with `(`, `)`, `and`, `or` and `not`.
- `--tag` CLI option to filter by tags.
- New annotations are available in `TestInfo.annotations` and
`TestCase.annotations`.
- New tags are available in `TestCase.tags`.
    
Reporter changes:
- `json` reporter includes new tags in addition to old `@smoke`-style
tags. **Breaking**: tags are now listed with the leading `@` symbol.
- `html` reporter filters by old and new tags with the same `@smoke`
token.
Fixes #29229, fixes #23180.
											
										 
											2024-02-07 16:31:25 -08:00
										 |  |  |       }); | 
					
						
							|  |  |  |       test('foo-bar-tags', { tag: ['@foo', '@bar'] }, () => { | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       test.skip('skip-foo-tag', { tag: '@foo' }, () => { | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       test.fixme('fixme-bar-tag', { tag: '@bar' }, () => { | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       test.fail('fail-foo-bar-tags', { tag: ['@foo', '@bar'] }, () => { | 
					
						
							|  |  |  |         expect(1).toBe(2); | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2024-02-15 11:37:16 -08:00
										 |  |  |       test.describe('suite @inline', { tag: '@foo' }, () => { | 
					
						
							| 
									
										
										
											
												feat(test runner): tags/annotations (#29248)
API changes:
- `test(title, details, body)` where details contain `tag` and
`annotation`.
- similar `details` property added to `test.skip`, `test.fail`,
`test.fixme`, `test.only`, `test.describe` and other `test.describe.*`
variations.
- `TestProject.tagFilter`/`TestConfig.tagFilter` that supports logical
tag expressions with `(`, `)`, `and`, `or` and `not`.
- `--tag` CLI option to filter by tags.
- New annotations are available in `TestInfo.annotations` and
`TestCase.annotations`.
- New tags are available in `TestCase.tags`.
    
Reporter changes:
- `json` reporter includes new tags in addition to old `@smoke`-style
tags. **Breaking**: tags are now listed with the leading `@` symbol.
- `html` reporter filters by old and new tags with the same `@smoke`
token.
Fixes #29229, fixes #23180.
											
										 
											2024-02-07 16:31:25 -08:00
										 |  |  |         test('foo-suite', () => { | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |         test.describe('inner', { tag: '@bar' }, () => { | 
					
						
							|  |  |  |           test('foo-bar-suite', () => { | 
					
						
							|  |  |  |           }); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       test.describe.skip('skip-foo-suite', { tag: '@foo' }, () => { | 
					
						
							|  |  |  |         test('skip-foo-suite', () => { | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       test.describe.fixme('fixme-bar-suite', { tag: '@bar' }, () => { | 
					
						
							|  |  |  |         test('fixme-bar-suite', () => { | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     `
 | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  |   expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  |   expect(result.outputLines).toEqual([ | 
					
						
							|  |  |  |     `title=no-tags, tags=`, | 
					
						
							| 
									
										
										
										
											2024-02-15 11:37:16 -08:00
										 |  |  |     `title=foo-tag @inline, tags=@inline,@foo`, | 
					
						
							| 
									
										
										
											
												feat(test runner): tags/annotations (#29248)
API changes:
- `test(title, details, body)` where details contain `tag` and
`annotation`.
- similar `details` property added to `test.skip`, `test.fail`,
`test.fixme`, `test.only`, `test.describe` and other `test.describe.*`
variations.
- `TestProject.tagFilter`/`TestConfig.tagFilter` that supports logical
tag expressions with `(`, `)`, `and`, `or` and `not`.
- `--tag` CLI option to filter by tags.
- New annotations are available in `TestInfo.annotations` and
`TestCase.annotations`.
- New tags are available in `TestCase.tags`.
    
Reporter changes:
- `json` reporter includes new tags in addition to old `@smoke`-style
tags. **Breaking**: tags are now listed with the leading `@` symbol.
- `html` reporter filters by old and new tags with the same `@smoke`
token.
Fixes #29229, fixes #23180.
											
										 
											2024-02-07 16:31:25 -08:00
										 |  |  |     `title=foo-bar-tags, tags=@foo,@bar`, | 
					
						
							|  |  |  |     `title=skip-foo-tag, tags=@foo`, | 
					
						
							|  |  |  |     `title=fixme-bar-tag, tags=@bar`, | 
					
						
							|  |  |  |     `title=fail-foo-bar-tags, tags=@foo,@bar`, | 
					
						
							| 
									
										
										
										
											2024-02-15 11:37:16 -08:00
										 |  |  |     `title=foo-suite, tags=@inline,@foo`, | 
					
						
							|  |  |  |     `title=foo-bar-suite, tags=@inline,@foo,@bar`, | 
					
						
							| 
									
										
										
											
												feat(test runner): tags/annotations (#29248)
API changes:
- `test(title, details, body)` where details contain `tag` and
`annotation`.
- similar `details` property added to `test.skip`, `test.fail`,
`test.fixme`, `test.only`, `test.describe` and other `test.describe.*`
variations.
- `TestProject.tagFilter`/`TestConfig.tagFilter` that supports logical
tag expressions with `(`, `)`, `and`, `or` and `not`.
- `--tag` CLI option to filter by tags.
- New annotations are available in `TestInfo.annotations` and
`TestCase.annotations`.
- New tags are available in `TestCase.tags`.
    
Reporter changes:
- `json` reporter includes new tags in addition to old `@smoke`-style
tags. **Breaking**: tags are now listed with the leading `@` symbol.
- `html` reporter filters by old and new tags with the same `@smoke`
token.
Fixes #29229, fixes #23180.
											
										 
											2024-02-07 16:31:25 -08:00
										 |  |  |     `title=skip-foo-suite, tags=@foo`, | 
					
						
							|  |  |  |     `title=fixme-bar-suite, tags=@bar`, | 
					
						
							|  |  |  |   ]); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-15 11:37:16 -08:00
										 |  |  | test('config.grep should work', async ({ runInlineTest }) => { | 
					
						
							| 
									
										
										
											
												feat(test runner): tags/annotations (#29248)
API changes:
- `test(title, details, body)` where details contain `tag` and
`annotation`.
- similar `details` property added to `test.skip`, `test.fail`,
`test.fixme`, `test.only`, `test.describe` and other `test.describe.*`
variations.
- `TestProject.tagFilter`/`TestConfig.tagFilter` that supports logical
tag expressions with `(`, `)`, `and`, `or` and `not`.
- `--tag` CLI option to filter by tags.
- New annotations are available in `TestInfo.annotations` and
`TestCase.annotations`.
- New tags are available in `TestCase.tags`.
    
Reporter changes:
- `json` reporter includes new tags in addition to old `@smoke`-style
tags. **Breaking**: tags are now listed with the leading `@` symbol.
- `html` reporter filters by old and new tags with the same `@smoke`
token.
Fixes #29229, fixes #23180.
											
										 
											2024-02-07 16:31:25 -08:00
										 |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |     'playwright.config.ts': `
 | 
					
						
							| 
									
										
										
										
											2024-02-15 11:37:16 -08:00
										 |  |  |       module.exports = { grep: /@tag1/ }; | 
					
						
							| 
									
										
										
											
												feat(test runner): tags/annotations (#29248)
API changes:
- `test(title, details, body)` where details contain `tag` and
`annotation`.
- similar `details` property added to `test.skip`, `test.fail`,
`test.fixme`, `test.only`, `test.describe` and other `test.describe.*`
variations.
- `TestProject.tagFilter`/`TestConfig.tagFilter` that supports logical
tag expressions with `(`, `)`, `and`, `or` and `not`.
- `--tag` CLI option to filter by tags.
- New annotations are available in `TestInfo.annotations` and
`TestCase.annotations`.
- New tags are available in `TestCase.tags`.
    
Reporter changes:
- `json` reporter includes new tags in addition to old `@smoke`-style
tags. **Breaking**: tags are now listed with the leading `@` symbol.
- `html` reporter filters by old and new tags with the same `@smoke`
token.
Fixes #29229, fixes #23180.
											
										 
											2024-02-07 16:31:25 -08:00
										 |  |  |     `,
 | 
					
						
							|  |  |  |     'a.test.ts': `
 | 
					
						
							|  |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							|  |  |  |       test('test1', { tag: '@tag1' }, async () => { console.log('\\n%% test1'); }); | 
					
						
							|  |  |  |       test('test2', async () => { console.log('\\n%% test2'); }); | 
					
						
							|  |  |  |     `,
 | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  |   expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  |   expect(result.passed).toBe(1); | 
					
						
							|  |  |  |   expect(result.outputLines).toEqual(['test1']); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-15 11:37:16 -08:00
										 |  |  | test('config.project.grep should work', async ({ runInlineTest }) => { | 
					
						
							| 
									
										
										
											
												feat(test runner): tags/annotations (#29248)
API changes:
- `test(title, details, body)` where details contain `tag` and
`annotation`.
- similar `details` property added to `test.skip`, `test.fail`,
`test.fixme`, `test.only`, `test.describe` and other `test.describe.*`
variations.
- `TestProject.tagFilter`/`TestConfig.tagFilter` that supports logical
tag expressions with `(`, `)`, `and`, `or` and `not`.
- `--tag` CLI option to filter by tags.
- New annotations are available in `TestInfo.annotations` and
`TestCase.annotations`.
- New tags are available in `TestCase.tags`.
    
Reporter changes:
- `json` reporter includes new tags in addition to old `@smoke`-style
tags. **Breaking**: tags are now listed with the leading `@` symbol.
- `html` reporter filters by old and new tags with the same `@smoke`
token.
Fixes #29229, fixes #23180.
											
										 
											2024-02-07 16:31:25 -08:00
										 |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |     'playwright.config.ts': `
 | 
					
						
							|  |  |  |       module.exports = { projects: [ | 
					
						
							|  |  |  |         { name: 'p1' }, | 
					
						
							| 
									
										
										
										
											2024-02-15 11:37:16 -08:00
										 |  |  |         { name: 'p2', grep: /@tag1/ } | 
					
						
							| 
									
										
										
											
												feat(test runner): tags/annotations (#29248)
API changes:
- `test(title, details, body)` where details contain `tag` and
`annotation`.
- similar `details` property added to `test.skip`, `test.fail`,
`test.fixme`, `test.only`, `test.describe` and other `test.describe.*`
variations.
- `TestProject.tagFilter`/`TestConfig.tagFilter` that supports logical
tag expressions with `(`, `)`, `and`, `or` and `not`.
- `--tag` CLI option to filter by tags.
- New annotations are available in `TestInfo.annotations` and
`TestCase.annotations`.
- New tags are available in `TestCase.tags`.
    
Reporter changes:
- `json` reporter includes new tags in addition to old `@smoke`-style
tags. **Breaking**: tags are now listed with the leading `@` symbol.
- `html` reporter filters by old and new tags with the same `@smoke`
token.
Fixes #29229, fixes #23180.
											
										 
											2024-02-07 16:31:25 -08:00
										 |  |  |       ] }; | 
					
						
							|  |  |  |     `,
 | 
					
						
							|  |  |  |     'a.test.ts': `
 | 
					
						
							|  |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							|  |  |  |       test('test1', { tag: '@tag1' }, async () => { console.log('\\n%% test1-' + test.info().project.name); }); | 
					
						
							|  |  |  |       test('test2', async () => { console.log('\\n%% test2-' + test.info().project.name); }); | 
					
						
							|  |  |  |     `,
 | 
					
						
							|  |  |  |   }, { workers: 1 }); | 
					
						
							|  |  |  |   expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  |   expect(result.passed).toBe(3); | 
					
						
							|  |  |  |   expect(result.outputLines).toEqual(['test1-p1', 'test2-p1', 'test1-p2']); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-15 11:37:16 -08:00
										 |  |  | test('--grep should work', async ({ runInlineTest }) => { | 
					
						
							| 
									
										
										
											
												feat(test runner): tags/annotations (#29248)
API changes:
- `test(title, details, body)` where details contain `tag` and
`annotation`.
- similar `details` property added to `test.skip`, `test.fail`,
`test.fixme`, `test.only`, `test.describe` and other `test.describe.*`
variations.
- `TestProject.tagFilter`/`TestConfig.tagFilter` that supports logical
tag expressions with `(`, `)`, `and`, `or` and `not`.
- `--tag` CLI option to filter by tags.
- New annotations are available in `TestInfo.annotations` and
`TestCase.annotations`.
- New tags are available in `TestCase.tags`.
    
Reporter changes:
- `json` reporter includes new tags in addition to old `@smoke`-style
tags. **Breaking**: tags are now listed with the leading `@` symbol.
- `html` reporter filters by old and new tags with the same `@smoke`
token.
Fixes #29229, fixes #23180.
											
										 
											2024-02-07 16:31:25 -08:00
										 |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |     'a.test.ts': `
 | 
					
						
							|  |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							|  |  |  |       test('test1', { tag: '@tag1' }, async () => { console.log('\\n%% test1'); }); | 
					
						
							|  |  |  |       test('test2', async () => { console.log('\\n%% test2'); }); | 
					
						
							|  |  |  |     `,
 | 
					
						
							| 
									
										
										
										
											2024-02-15 11:37:16 -08:00
										 |  |  |   }, { grep: '@tag1' }); | 
					
						
							| 
									
										
										
											
												feat(test runner): tags/annotations (#29248)
API changes:
- `test(title, details, body)` where details contain `tag` and
`annotation`.
- similar `details` property added to `test.skip`, `test.fail`,
`test.fixme`, `test.only`, `test.describe` and other `test.describe.*`
variations.
- `TestProject.tagFilter`/`TestConfig.tagFilter` that supports logical
tag expressions with `(`, `)`, `and`, `or` and `not`.
- `--tag` CLI option to filter by tags.
- New annotations are available in `TestInfo.annotations` and
`TestCase.annotations`.
- New tags are available in `TestCase.tags`.
    
Reporter changes:
- `json` reporter includes new tags in addition to old `@smoke`-style
tags. **Breaking**: tags are now listed with the leading `@` symbol.
- `html` reporter filters by old and new tags with the same `@smoke`
token.
Fixes #29229, fixes #23180.
											
										 
											2024-02-07 16:31:25 -08:00
										 |  |  |   expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  |   expect(result.passed).toBe(1); | 
					
						
							|  |  |  |   expect(result.outputLines).toEqual(['test1']); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test('should enforce @ symbol', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |     'stdio.spec.js': `
 | 
					
						
							|  |  |  |       import { test, expect } from '@playwright/test'; | 
					
						
							|  |  |  |       test('test1', { tag: 'foo' }, () => { | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     `
 | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  |   expect(result.exitCode).toBe(1); | 
					
						
							|  |  |  |   expect(result.output).toContain(`Error: Tag must start with "@" symbol, got "foo" instead.`); | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2024-03-06 17:33:06 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | test('should be included in testInfo', async ({ runInlineTest }, testInfo) => { | 
					
						
							|  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |     'a.test.ts': `
 | 
					
						
							|  |  |  |     import { test, expect } from '@playwright/test'; | 
					
						
							|  |  |  |     test('test without tag', async ({}, testInfo) => { | 
					
						
							|  |  |  |       expect(testInfo.tags).toStrictEqual([]); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |     test('test with tag',{ tag: '@tag1' }, async ({}, testInfo) => { | 
					
						
							|  |  |  |       expect(testInfo.tags).toStrictEqual(["@tag1"]); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |     `,
 | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  |   expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test('should be included in testInfo if comming from describe', async ({ runInlineTest }, testInfo) => { | 
					
						
							|  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |     'a.test.ts': `
 | 
					
						
							|  |  |  |     import { test, expect } from '@playwright/test'; | 
					
						
							|  |  |  |     test.describe('describe with tag', { tag: '@tag2' }, async ()=>{ | 
					
						
							|  |  |  |       test('test with tag', async ({}, testInfo) => { | 
					
						
							|  |  |  |         expect(testInfo.tags).toStrictEqual(["@tag2"]); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |     `,
 | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  |   expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  | }); |