-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[scout] unique runId for reporting, disabled failed test reporter locally #209507
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,26 +7,35 @@ | |
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
|
|
||
| import { SCOUT_REPORTER_ENABLED, SCOUT_SERVERS_ROOT } from '@kbn/scout-info'; | ||
| import { SCOUT_SERVERS_ROOT } from '@kbn/scout-info'; | ||
| import { scoutPlaywrightReporter, scoutFailedTestsReporter } from '@kbn/scout-reporting'; | ||
| import { createPlaywrightConfig } from './create_config'; | ||
| import { VALID_CONFIG_MARKER } from '../types'; | ||
| import { generateTestRunId } from '@kbn/scout-reporting'; | ||
|
|
||
| jest.mock('@kbn/scout-reporting', () => ({ | ||
| ...jest.requireActual('@kbn/scout-reporting'), | ||
| generateTestRunId: jest.fn(), | ||
| scoutPlaywrightReporter: jest.fn(), | ||
| scoutFailedTestsReporter: jest.fn(), | ||
| })); | ||
|
|
||
| describe('createPlaywrightConfig', () => { | ||
| const mockedRunId = 'mocked-run-id'; | ||
| const mockGenerateTestRunId = generateTestRunId as jest.Mock; | ||
| const mockedScoutPlaywrightReporter = scoutPlaywrightReporter as jest.Mock; | ||
| const mockedScoutFailedTestsReporter = scoutFailedTestsReporter as jest.Mock; | ||
|
|
||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| delete process.env.TEST_RUN_ID; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had no idea you could do this...deleting an env var that was on the cli? Pretty cool
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I found few examples of it online: not sure if it is the most optimal, but it works |
||
| }); | ||
|
|
||
| it('should return a valid default Playwright configuration', () => { | ||
| const testRunId = 'test-run-id'; | ||
| mockGenerateTestRunId.mockImplementationOnce(() => testRunId); | ||
| mockGenerateTestRunId.mockImplementationOnce(() => mockedRunId); | ||
| // Scout reporters are disabled by default | ||
| mockedScoutPlaywrightReporter.mockReturnValueOnce(['null']); | ||
| mockedScoutFailedTestsReporter.mockReturnValueOnce(['null']); | ||
|
|
||
| const testDir = './my_tests'; | ||
| const config = createPlaywrightConfig({ testDir }); | ||
|
|
@@ -49,28 +58,63 @@ describe('createPlaywrightConfig', () => { | |
| expect(config.reporter).toEqual([ | ||
| ['html', { open: 'never', outputFolder: './output/reports' }], | ||
| ['json', { outputFile: './output/reports/test-results.json' }], | ||
| SCOUT_REPORTER_ENABLED | ||
| ? [ | ||
| '@kbn/scout-reporting/src/reporting/playwright/events', | ||
| { name: 'scout-playwright', runId: testRunId }, | ||
| ] | ||
| : ['null'], | ||
| [ | ||
| '@kbn/scout-reporting/src/reporting/playwright/failed_test', | ||
| { name: 'scout-playwright-failed-tests', runId: testRunId }, | ||
| ], | ||
| ['null'], | ||
| ['null'], | ||
| ]); | ||
| expect(config.timeout).toBe(60000); | ||
| expect(config.expect?.timeout).toBe(10000); | ||
| expect(config.outputDir).toBe('./output/test-artifacts'); | ||
| expect(config.projects![0].name).toEqual('chromium'); | ||
| }); | ||
|
|
||
| it('should return a Playwright configuration with Scout reporters', () => { | ||
| mockGenerateTestRunId.mockImplementationOnce(() => mockedRunId); | ||
| mockedScoutPlaywrightReporter.mockReturnValueOnce([ | ||
| '@kbn/scout-reporting/src/reporting/playwright/events', | ||
| { name: 'scout-playwright', runId: mockedRunId }, | ||
| ]); | ||
| mockedScoutFailedTestsReporter.mockReturnValueOnce([ | ||
| '@kbn/scout-reporting/src/reporting/playwright/failed_test', | ||
| { name: 'scout-playwright-failed-tests', runId: mockedRunId }, | ||
| ]); | ||
|
|
||
| const testDir = './my_tests'; | ||
| const config = createPlaywrightConfig({ testDir }); | ||
|
|
||
| expect(mockGenerateTestRunId).toHaveBeenCalledTimes(1); | ||
| expect(config.reporter).toEqual([ | ||
| ['html', { open: 'never', outputFolder: './output/reports' }], | ||
| ['json', { outputFile: './output/reports/test-results.json' }], | ||
| [ | ||
| '@kbn/scout-reporting/src/reporting/playwright/events', | ||
| { name: 'scout-playwright', runId: mockedRunId }, | ||
| ], | ||
| [ | ||
| '@kbn/scout-reporting/src/reporting/playwright/failed_test', | ||
| { name: 'scout-playwright-failed-tests', runId: mockedRunId }, | ||
| ], | ||
| ]); | ||
| }); | ||
|
|
||
| it(`should override 'workers' count in Playwright configuration`, () => { | ||
| const testDir = './my_tests'; | ||
| const workers = 2; | ||
|
|
||
| const config = createPlaywrightConfig({ testDir, workers }); | ||
| expect(config.workers).toBe(workers); | ||
| }); | ||
|
|
||
| it('should generate and cache runId in process.env.TEST_RUN_ID', () => { | ||
| mockGenerateTestRunId.mockReturnValue(mockedRunId); | ||
|
|
||
| // First call to create config | ||
| createPlaywrightConfig({ testDir: 'tests' }); | ||
| expect(process.env.TEST_RUN_ID).toBe(mockedRunId); | ||
|
|
||
| // Second call (should use the cached value) | ||
| createPlaywrightConfig({ testDir: 'tests' }); | ||
|
|
||
| expect(generateTestRunId).toHaveBeenCalledTimes(1); | ||
| expect(process.env.TEST_RUN_ID).toBe(mockedRunId); | ||
| }); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this an array?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is by design https://playwright.dev/docs/api/class-reporter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I presume it's to contain more than one reporter much like other test runners. Cool