Skip to content

Commit 57fffb6

Browse files
author
rocketraccoon
committed
feat: add refresh tests
1 parent b80818c commit 57fffb6

17 files changed

Lines changed: 116 additions & 9 deletions

File tree

lib/gui/app.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ export class App {
5353
return this._toolRunner.findEqualDiffs(data);
5454
}
5555

56+
async refreshTests(): Promise<ToolRunnerTree | null> {
57+
await this._toolRunner.refreshTests();
58+
return this._toolRunner.tree;
59+
}
60+
5661
addClient(connection: Response): void {
5762
this._toolRunner.addClient(connection);
5863
}

lib/gui/server.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,15 @@ export const start = async (args: ServerArgs): Promise<ServerReadyData> => {
274274
logger.log('server shutting down');
275275
});
276276

277+
server.get('/refresh-tests', async (_req, res) => {
278+
try {
279+
const tree = await app.refreshTests();
280+
res.json(tree satisfies GetInitResponse);
281+
} catch (e: unknown) {
282+
res.status(INTERNAL_SERVER_ERROR).send(`Error while refreshing tests: ${(e as Error).message}`);
283+
}
284+
});
285+
277286
server.post('/stop', (_req, res) => {
278287
try {
279288
// pass 0 to prevent terminating testplane process

lib/gui/tool-runner/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,13 @@ export class ToolRunner {
154154
return this._toolAdapter.readTests(this._testFiles, this._globalOpts);
155155
}
156156

157+
async refreshTests(): Promise<void> {
158+
this._collection = await this._readTests();
159+
this._testAdapters = {};
160+
this._ensureReportBuilder().resetTree();
161+
await this._handleRunnableCollection();
162+
}
163+
157164
protected _ensureReportBuilder(): GuiReportBuilder {
158165
if (!this._reportBuilder) {
159166
throw new Error('ToolRunner has to be initialized before usage');
@@ -424,6 +431,8 @@ export class ToolRunner {
424431
protected async _loadDataFromDatabase(): Promise<Tree | null> {
425432
const dbPath = path.resolve(this._reportPath, LOCAL_DATABASE_NAME);
426433

434+
this._ensureReportBuilder().flushDb();
435+
427436
if (await fs.pathExists(dbPath)) {
428437
return getTestsTreeFromDatabase(dbPath, this._reporterConfig.baseHost);
429438
}

lib/report-builder/gui.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import _ from 'lodash';
22
import {StaticReportBuilder, StaticReportBuilderOptions} from './static';
3+
import {TestAttemptManager} from '../test-attempt-manager';
34
import {GuiTestsTreeBuilder, TestBranch, TestEqualDiffsData, TestRefUpdateData} from '../tests-tree-builder/gui';
45
import {UPDATED, DB_COLUMNS, TestStatus, DEFAULT_TITLE_DELIMITER, SKIPPED, SUCCESS} from '../constants';
56
import {ConfigForStaticFile, getConfigForStaticFile} from '../server-utils';
@@ -76,6 +77,12 @@ export class GuiReportBuilder extends StaticReportBuilder {
7677
};
7778
}
7879

80+
resetTree(): void {
81+
this._testsTree = GuiTestsTreeBuilder.create({baseHost: this._reporterConfig.baseHost});
82+
this._testAttemptManager = new TestAttemptManager();
83+
this._skips = [];
84+
}
85+
7986
getTestBranch(id: string): TestBranch {
8087
return this._testsTree.getTestBranch(id);
8188
}

lib/report-builder/static.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ export class StaticReportBuilder {
7676
this._workers = workers;
7777
}
7878

79+
flushDb(): void {
80+
this._dbClient.flush();
81+
}
82+
7983
registerAttempt(testInfo: {fullName: string, browserId: string}, status: TestStatus): number {
8084
return this._testAttemptManager.registerAttempt(testInfo, status);
8185
}

lib/sqlite-client.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ export class SqliteClient {
120120
return this._db;
121121
}
122122

123+
flush(): void {
124+
fs.writeFileSync(this._dbPath, this._db.export());
125+
}
126+
123127
close(): void {
124128
fs.writeFileSync(this._dbPath, this._db.run('VACUUM').export());
125129

lib/static/modules/action-names.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,6 @@ export default {
8282
SNAPSHOTS_PLAYER_GO_TO_TIME: 'SNAPSHOTS_PLAYER_GO_TO_TIME',
8383
SNAPSHOTS_PLAYER_TOGGLE_VISIBILITY: 'SNAPSHOTS_PLAYER_TOGGLE_VISIBILITY',
8484
SET_BROWSER_FEATURES: 'SET_BROWSER_FEATURES',
85+
SET_REFRESH_LOADING: 'SET_REFRESH_LOADING',
8586
SET_SEARCH_LOADING: 'SET_SEARCH_LOADING'
8687
} as const;

lib/static/modules/actions/filters.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,16 @@ export const setSearchLoading = (payload: boolean): SetSearchLoading => {
3838
export type ChangeViewModeAction = Action<typeof actionNames.CHANGE_VIEW_MODE, FilterPayload<ViewMode>>;
3939
export const changeViewMode = (payload: ChangeViewModeAction['payload']): ChangeViewModeAction => ({type: actionNames.CHANGE_VIEW_MODE, payload});
4040

41+
export type SetRefreshLoading = Action<typeof actionNames.SET_REFRESH_LOADING, boolean>;
42+
export const setRefreshLoading = (payload: boolean): SetRefreshLoading => {
43+
return {type: actionNames.SET_REFRESH_LOADING, payload};
44+
};
45+
4146
export type FiltersAction =
4247
| UpdateNameFilterAction
4348
| SetMatchCaseFilterAction
4449
| SetUseRegexFilterAction
4550
| SelectBrowsersAction
4651
| ChangeViewModeAction
52+
| SetRefreshLoading
4753
| SetSearchLoading;

lib/static/modules/actions/lifecycle.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {GetInitResponse} from '@/gui/server';
1818
import {Tree} from '@/tests-tree-builder/base';
1919
import {BrowserItem} from '@/types';
2020
import {createNotificationError} from '@/static/modules/actions/notifications';
21+
import {setRefreshLoading} from '@/static/modules/actions/filters';
2122
import {LocalStorageKey} from '@/constants/local-storage';
2223
import * as localStorageWrapper from '@/static/modules/local-storage-wrapper';
2324
import {updateTimeTravelSettings} from '../../new-ui/utils/api';
@@ -139,6 +140,25 @@ export const thunkInitStaticReport = ({isNewUi}: InitStaticReportData = {}): App
139140
};
140141
};
141142

143+
export const thunkRefreshGuiReport = (): AppThunk => {
144+
return async (dispatch, getState) => {
145+
dispatch(setRefreshLoading(true));
146+
try {
147+
const response = await axios.get<GetInitResponse>('/refresh-tests');
148+
149+
if (!response.data) {
150+
throw new Error('Could not refresh tests data.');
151+
}
152+
153+
const {db} = getState();
154+
dispatch(initGuiReport({...response.data, db: db!}));
155+
} catch (e: unknown) {
156+
dispatch(createNotificationError('thunkRefreshGuiReport', e as Error));
157+
dispatch(setRefreshLoading(false));
158+
}
159+
};
160+
};
161+
142162
export type FinGuiReportAction = Action<typeof actionNames.FIN_GUI_REPORT>;
143163
export const finGuiReport = (): FinGuiReportAction => ({type: actionNames.FIN_GUI_REPORT});
144164

lib/static/modules/reducers/filters.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export default (state: State, action: FiltersAction | InitGuiReportAction | Init
4141
state,
4242
{
4343
app: {
44+
isRefreshLoading: false,
4445
viewMode,
4546
[Page.visualChecksPage]: {
4647
diffMode: visualChecksPageDiffMode
@@ -99,6 +100,9 @@ export default (state: State, action: FiltersAction | InitGuiReportAction | Init
99100
case actionNames.SET_SEARCH_LOADING:
100101
return applyStateUpdate(state, {app: {isSearchLoading: action.payload}});
101102

103+
case actionNames.SET_REFRESH_LOADING:
104+
return applyStateUpdate(state, {app: {isRefreshLoading: action.payload}});
105+
102106
default:
103107
return state;
104108
}

0 commit comments

Comments
 (0)