-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from joomcode/fix/error-in-interface-stabiliza…
…tion fix: error in interface stabilization mechanism
- Loading branch information
Showing
29 changed files
with
277 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* eslint-disable no-console */ | ||
|
||
import {it} from 'autotests'; | ||
import {E2edReportExample} from 'autotests/pageObjects/pages'; | ||
import {createClientFunction, expect} from 'e2ed'; | ||
import { | ||
getBrowserConsoleMessages, | ||
getBrowserJsErrors, | ||
navigateToPage, | ||
setPageElementsIgnoredOnInterfaceStabilization, | ||
waitForInterfaceStabilization, | ||
} from 'e2ed/actions'; | ||
|
||
it('correctly read data from browser', {meta: {testId: '14'}}, async () => { | ||
await navigateToPage(E2edReportExample); | ||
|
||
await setPageElementsIgnoredOnInterfaceStabilization(['.retry']); | ||
|
||
await waitForInterfaceStabilization(100); | ||
|
||
await createClientFunction(() => { | ||
console.error('error'); | ||
console.info('info'); | ||
console.log('log'); | ||
console.warn('warn'); | ||
|
||
const key = Symbol.for('e2ed:PageElementsIgnoredOnInterfaceStabilization'); | ||
const global = globalThis as {[key]?: readonly string[] | undefined}; | ||
|
||
console.log(global[key]); | ||
|
||
setTimeout(() => { | ||
throw new Error('foo'); | ||
}, 8); | ||
setTimeout(() => { | ||
throw new Error('bar'); | ||
}, 32); | ||
})(); | ||
|
||
const {error, info, log, warn} = await getBrowserConsoleMessages(); | ||
|
||
await expect( | ||
error[0] === 'error' && info[0] === 'info' && log[0] === 'log' && warn[0] === 'warn', | ||
'`getBrowserConsoleMessages` read all of messages', | ||
).eql(true); | ||
|
||
await expect(log[1], '`setPageElementsIgnoredOnInterfaceStabilization` works correct').eql( | ||
'.retry', | ||
); | ||
|
||
const jsErrors = await getBrowserJsErrors(); | ||
|
||
await expect( | ||
jsErrors.length === 2 && jsErrors[0]?.message === 'foo' && jsErrors[1]?.message === 'bar', | ||
'`getBrowserJsErrors` read JS errors', | ||
).eql(true); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import {LogEventType} from '../constants/internal'; | ||
import {createClientFunction} from '../createClientFunction'; | ||
import {log} from '../utils/log'; | ||
|
||
import type {BrowserJsError} from '../types/internal'; | ||
|
||
const clientGetBrowserJsErrors = createClientFunction( | ||
(): readonly BrowserJsError[] => { | ||
const key = Symbol.for('e2ed:JsErrors'); | ||
const global = window as {[key]?: BrowserJsError[]}; | ||
// eslint-disable-next-line no-multi-assign | ||
const errors = (global[key] ??= []); | ||
const copyOfErrors = [...errors]; | ||
|
||
errors.length = 0; | ||
|
||
return copyOfErrors; | ||
}, | ||
{name: 'getBrowserJsErrors'}, | ||
); | ||
|
||
/** | ||
* Get browser JS errors. | ||
*/ | ||
export const getBrowserJsErrors = (): Promise<readonly BrowserJsError[]> => { | ||
log('Get browser JS errors', LogEventType.InternalAction); | ||
|
||
return clientGetBrowserJsErrors(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/actions/setPageElementsIgnoredOnInterfaceStabilization.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import {LogEventType} from '../constants/internal'; | ||
import {createClientFunction} from '../createClientFunction'; | ||
import {log} from '../utils/log'; | ||
|
||
const clientSetPageElementsIgnoredOnInterfaceStabilization = createClientFunction( | ||
(elementsCssSelectors: readonly string[]) => { | ||
const key = Symbol.for('e2ed:PageElementsIgnoredOnInterfaceStabilization'); | ||
const global = globalThis as {[key]?: readonly string[] | undefined}; | ||
|
||
global[key] = elementsCssSelectors; | ||
}, | ||
{name: 'setPageElementsIgnoredOnInterfaceStabilization'}, | ||
); | ||
|
||
/** | ||
* Set an array of elements (by their string CSS selectors) that will be ignored | ||
* when determining the end of interface stabilization (these are usually animated elements). | ||
*/ | ||
export const setPageElementsIgnoredOnInterfaceStabilization = ( | ||
elementsCssSelectors: readonly string[], | ||
): Promise<void> => { | ||
log( | ||
'Set page element that will be ignored when determining the end of interface stabilization', | ||
{elementsCssSelectors}, | ||
LogEventType.InternalAction, | ||
); | ||
|
||
return clientSetPageElementsIgnoredOnInterfaceStabilization(elementsCssSelectors); | ||
}; |
Oops, something went wrong.