Skip to content

Commit

Permalink
feat: add isRealtime option
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanDavlyatshin committed May 24, 2021
1 parent 30c5b49 commit 73b7bd8
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/background/backend-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ export default async (backendUrl: string, errorCb: any, completeCb: any) => {

getMethods(baseUrl: string) {
return {
async startTest(testName: string) { // TODO add isRealTime param
async startTest(testName: string, isRealtime: boolean) {
const sessionId = uuid();
await sendSessionAction(baseUrl, {
type: 'START',
payload: {
sessionId,
testName,
testType: 'MANUAL',
isRealtime: true,
isRealtime,
},
});
return sessionId;
Expand Down
12 changes: 6 additions & 6 deletions src/background/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,11 @@ async function init() {

const router = createMessageRouter();

router.add('START_TEST', async (sender: chrome.runtime.MessageSender, testName: string) => {
router.add('START_TEST', async (sender: chrome.runtime.MessageSender, { testName, isRealtime }) => {
const host = transformHost(sender.url);
const adapter = adapters[host];
if (!adapter) throw new Error('Backend connection unavailable');
const sessionId = await adapter.startTest(testName, sender);
const sessionId = await adapter.startTest(testName, isRealtime, sender);
sessionsData[host] = {
testName,
sessionId,
Expand Down Expand Up @@ -455,8 +455,8 @@ function createAdapter(adapterInfo: AdapterInfo, backend: BackendCreator): Agent

if (!adapterInfo.mustRecordJsCoverage) {
return {
startTest: async (testName) => {
const sessionId = await backendApi.startTest(testName);
startTest: async (testName, isRealtime) => {
const sessionId = await backendApi.startTest(testName, isRealtime);
return sessionId;
},
stopTest: async (sessionId: string) => {
Expand All @@ -468,10 +468,10 @@ function createAdapter(adapterInfo: AdapterInfo, backend: BackendCreator): Agent
};
}
return {
startTest: async (testName, sender) => {
startTest: async (testName, isRealtime, sender) => {
if (!sender) throw new Error('START_TEST_NO_SENDER');
await jsCoverageRecorder.start(sender);
const sessionId = await backendApi.startTest(testName);
const sessionId = await backendApi.startTest(testName, isRealtime);
return sessionId;
},
stopTest: async (sessionId, testName, sender) => {
Expand Down
4 changes: 2 additions & 2 deletions src/background/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export interface Routes {
}

export interface AgentAdapter {
startTest: (testName: string, sender?: chrome.runtime.MessageSender) => Promise<string>;
startTest: (testName: string, isRealtime: boolean, sender?: chrome.runtime.MessageSender) => Promise<string>;
stopTest: (sessionId: string, testName?: string, sender?: chrome.runtime.MessageSender) => Promise<void>;
cancelTest: (sessionId: string, sender?: chrome.runtime.MessageSender) => Promise<void>;
}
Expand Down Expand Up @@ -47,7 +47,7 @@ export interface AdapterInfo {
}

export interface BackendApi {
startTest: (testName: string) => Promise<string>;
startTest: (testName: string, isRealtime: boolean) => Promise<string>;
stopTest: (sessionId: string) => Promise<void>;
cancelTest: (sessionId: string) => Promise<void>;
addSessionData: (sessionId: string, data: unknown) => Promise<void>;
Expand Down
4 changes: 2 additions & 2 deletions src/common/background-interop/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ async function sendMessage<T>(message: unknown): Promise<T> {
});
}

export async function startTest(testName: string) {
return sendMessage<string>({ type: 'START_TEST', payload: testName });
export async function startTest(testName: string, isRealtime: boolean) {
return sendMessage<string>({ type: 'START_TEST', payload: { testName, isRealtime } });
}

export async function stopTest() {
Expand Down
13 changes: 11 additions & 2 deletions src/content-script/pages/start-new-manual-test/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { Button } from '@drill4j/ui-kit';
import { Button, Checkbox } from '@drill4j/ui-kit';

import { AgentContext } from '../../context';
import * as bgInterop from '../../../common/background-interop';
Expand All @@ -9,6 +9,7 @@ import { ManualTestError } from '../manual-test-error';
export const StartNewManualTest = () => {
const [submitError, setSubmitError] = React.useState('');
const [testName, setTestName] = React.useState('');
const [isRealtime, setIsRealTime] = React.useState(true);
const [isFormSubmitting, setIsFormSubmitting] = React.useState(false);
const agent = React.useContext(AgentContext);

Expand Down Expand Up @@ -42,6 +43,14 @@ export const StartNewManualTest = () => {
onChange={({ currentTarget: { value } }) => setTestName(value)}
disabled={isFormSubmitting}
/>
<span title="Whether a coverage must be updated in real-time or not" style={{ display: 'inherit' }}>
<span style={{ marginRight: '10px' }}>Realtime</span>
<Checkbox
disabled={isFormSubmitting}
checked={isRealtime}
onChange={(el) => setIsRealTime(el.target.checked)}
/>
</span>
<div title={!testName ? 'Enter a test name to start testing' : undefined}>
<Button
type="primary"
Expand All @@ -51,7 +60,7 @@ export const StartNewManualTest = () => {
setSubmitError('');
setIsFormSubmitting(true);
try {
await bgInterop.startTest(testName);
await bgInterop.startTest(testName, isRealtime);
if (agent.mustRecordJsCoverage) {
(window as any).reloadRequired = true;
}
Expand Down

0 comments on commit 73b7bd8

Please sign in to comment.