Skip to content

Commit bfbfa67

Browse files
authored
Merge pull request #671 from gemini-testing/TESTPLANE-555.cannot_read_perBrowser
fix: do not fail if test statistics is empty
2 parents a67b002 + b33bd1a commit bfbfa67

File tree

4 files changed

+31
-11
lines changed

4 files changed

+31
-11
lines changed

lib/static/modules/reducers/stats.js renamed to lib/static/modules/reducers/stats.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
import actionNames from '../action-names';
2+
import {State} from '@/static/new-ui/types/store';
3+
import {SomeAction} from '@/static/modules/actions/types';
4+
import {applyStateUpdate} from '../utils';
25

3-
export default (state, action) => {
6+
export default (state: State, action: SomeAction): State => {
47
switch (action.type) {
58
case actionNames.INIT_STATIC_REPORT: {
69
const {stats} = action.payload;
7-
const {perBrowser, ...restStats} = stats;
10+
const {perBrowser, ...restStats} = stats || {};
811

9-
return {
10-
...state,
12+
return applyStateUpdate(state, {
1113
stats: {
1214
all: restStats,
1315
perBrowser
1416
}
15-
};
17+
});
1618
}
1719

1820
default:

lib/static/new-ui/types/store.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {AcceptableImage} from '@/static/modules/static-image-accepter';
1515
import {CheckStatus} from '@/constants/checked-statuses';
1616
import {EntityType} from '@/static/new-ui/features/suites/components/SuitesPage/types';
1717
import {DbDetails} from '@/db-utils/common';
18+
import {Stats, PerBrowserStats} from '@/tests-tree-builder/static';
1819

1920
export interface GroupEntity {
2021
id: string;
@@ -342,6 +343,7 @@ export interface State {
342343
};
343344
timestamp: number;
344345
fetchDbDetails: DbDetails[];
346+
stats: {all: Stats | Record<string, never>, perBrowser: PerBrowserStats | undefined} | null;
345347
}
346348

347349
declare module 'react-redux' {

lib/tests-tree-builder/static.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,22 @@ import {ReporterTestResult} from '../adapters/test-result';
55
import {SqliteTestResultAdapter} from '../adapters/test-result/sqlite';
66
import {BrowserItem, RawSuitesRow} from '../types';
77

8-
interface Stats {
8+
export interface Stats {
99
total: number;
1010
passed: number;
1111
failed: number;
1212
skipped: number;
1313
retries: number;
1414
}
1515

16-
export type FinalStats = Stats & {
17-
perBrowser: {
18-
[browserName: string]: {
19-
[browserVersion: string]: Stats
20-
}
16+
export interface PerBrowserStats {
17+
[browserName: string]: {
18+
[browserVersion: string]: Stats
2119
}
2220
}
2321

22+
export type FinalStats = Stats & {perBrowser: PerBrowserStats}
23+
2424
export interface SkipItem {
2525
browser: string;
2626
suite: string;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import reducer from 'lib/static/modules/reducers/stats';
2+
import actionNames from 'lib/static/modules/action-names';
3+
import type {State} from 'lib/static/new-ui/types/store';
4+
import type {InitStaticReportAction} from 'lib/static/modules/actions/lifecycle';
5+
6+
describe('lib/static/modules/reducers/stats', () => {
7+
describe(`"${actionNames.INIT_STATIC_REPORT}" action`, () => {
8+
it('should not fail if stats is empty', () => {
9+
const action = {type: actionNames.INIT_STATIC_REPORT, payload: {stats: null} as InitStaticReportAction['payload']};
10+
11+
const newState = reducer({} as State, action);
12+
13+
assert.deepEqual(newState.stats, {all: {}, perBrowser: undefined} as State['stats']);
14+
});
15+
});
16+
});

0 commit comments

Comments
 (0)