Skip to content

Commit

Permalink
add logging for reporting, remove dashboard leftovers (#7829)
Browse files Browse the repository at this point in the history
Changes:
* add logging for the `Reporting` subsystem
* remove the `dashboard` subsystem leftovers
  • Loading branch information
miherlosev authored Jun 26, 2023
1 parent abe4ed0 commit b7d8c8d
Show file tree
Hide file tree
Showing 11 changed files with 10 additions and 52 deletions.
8 changes: 0 additions & 8 deletions src/cli/argument-parser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
getMetaOptions,
getGrepOptions,
getCompilerOptions,
getDashboardOptions,
} from '../../utils/get-options';

import getFilterFn from '../../utils/get-filter-fn';
Expand Down Expand Up @@ -88,7 +87,6 @@ interface CommandLineOptions {
configFile?: string;
nativeAutomation?: boolean;
v8Flags?: string[];
dashboardOptions?: string | Dictionary<string | boolean | number>;
baseUrl?: string;
skipJsErrors?: boolean | Dictionary<RegExp | string>;
}
Expand Down Expand Up @@ -428,11 +426,6 @@ export default class CLIArgumentParser {
this.opts.compilerOptions = resultCompilerOptions;
}

private async _parseDashboardOptions (): Promise<void> {
if (this.opts.dashboardOptions)
this.opts.dashboardOptions = await getDashboardOptions(this.opts.dashboardOptions as string);
}

private _parseListBrowsers (): void {
const listBrowserOption = this.opts.listBrowsers;

Expand Down Expand Up @@ -494,7 +487,6 @@ export default class CLIArgumentParser {
await this._parseCompilerOptions();
await this._parseSslOptions();
await this._parseReporters();
await this._parseDashboardOptions();
}

public getRunOptions (): RunnerRunOptions {
Expand Down
1 change: 0 additions & 1 deletion src/configuration/option-names.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ enum OptionNames {
userVariables = 'userVariables',
v8Flags = 'v8Flags',
hooks = 'hooks',
dashboard = 'dashboard',
baseUrl = 'baseUrl',
disableCrossDomain = 'disableCrossDomain',
esm = 'esm',
Expand Down
9 changes: 0 additions & 9 deletions src/configuration/testcafe-configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ export default class TestCafeConfiguration extends Configuration {

const opts = await this._load();

this._checkUnsecureDataInJSONConfiguration(opts);

if (opts) {
this._options = Configuration._fromObj(opts);

Expand Down Expand Up @@ -180,13 +178,6 @@ export default class TestCafeConfiguration extends Configuration {
};
}

private _checkUnsecureDataInJSONConfiguration (opts: any): void {
if (!this._isJSONConfiguration())
return;

if (opts?.[OPTION_NAMES.dashboard]?.token)
throw new GeneralError(RUNTIME_ERRORS.dashboardTokenInJSON);
}
private _prepareFlag (name: string, source = OptionSource.Configuration): void {
const option = this._ensureOption(name, void 0, source);

Expand Down
1 change: 0 additions & 1 deletion src/errors/runtime/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ export default {
[BrowserConnectionErrorHint.UseBrowserInitOption]: 'Increase the Browser Initialization Timeout if its value is too low (currently: {browserInitTimeoutMsg}). The timeout determines how long TestCafe waits for browsers to be ready.',
[BrowserConnectionErrorHint.RestErrorCauses]: 'The error can also be caused by network issues or remote device failure. Make sure that your network connection is stable and you can reach the remote device.',
[RUNTIME_ERRORS.cannotFindTestcafeConfigurationFile]: 'Cannot locate a TestCafe configuration file at {filePath}. Either the file does not exist, or the path is invalid.',
[RUNTIME_ERRORS.dashboardTokenInJSON]: 'Insecure token declaration: cannot declare a Dashboard token in a JSON configuration file. Use a JavaScript configuration file, or declare a Dashboard token with one of the following: the CLI, the Test Runner API, the TESTCAFE_DASHBOARD_TOKEN environment variable.',
[RUNTIME_ERRORS.relativeBaseUrl]: 'The value of the baseUrl argument cannot be relative: "{baseUrl}"',
[RUNTIME_ERRORS.requestUrlInvalidValueError]: 'The request url is invalid ({actualValue}).',
[RUNTIME_ERRORS.requestRuntimeError]: 'The request was interrupted by an error:\n{message}',
Expand Down
1 change: 0 additions & 1 deletion src/errors/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ export const RUNTIME_ERRORS = {
invalidSuccessThresholdValue: 'E1068',
cannotSetConcurrencyWithCDPPort: 'E1069',
cannotFindTestcafeConfigurationFile: 'E1070',
dashboardTokenInJSON: 'E1071',
requestUrlInvalidValueError: 'E1072',
requestRuntimeError: 'E1073',
requestCannotResolveTestRun: 'E1074',
Expand Down
13 changes: 7 additions & 6 deletions src/reporter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import fs from 'fs';
import MessageBus from '../utils/message-bus';
import BrowserConnection from '../browser/connection';
import { Dictionary } from '../configuration/interfaces';
import debug from 'debug';
import { reporterLogger } from '../utils/debug-loggers';

interface PendingPromise {
resolve: Function | null;
Expand Down Expand Up @@ -152,8 +152,6 @@ export interface ReporterOptions {
reporterPluginHooks?: ReporterPluginHooks
}

const debugLog = debug('testcafe:reporter');

export default class Reporter {
public readonly plugin: ReporterPluginHost;
public readonly messageBus: MessageBus;
Expand Down Expand Up @@ -196,6 +194,8 @@ export default class Reporter {
}

public async dispatchToPlugin ({ method, initialObject, args = [] }: PluginMethodArguments): Promise<void> {
reporterLogger('begin dispatchToPlugin method: %s\n%O', method, args);

try {
// @ts-ignore
await this.plugin[method](...args);
Expand All @@ -207,14 +207,16 @@ export default class Reporter {
originalError,
});

debugLog('Plugin error: %O', uncaughtError);
debugLog('Plugin error: initialObject: %O', initialObject);
reporterLogger('Plugin error: %O', uncaughtError);
reporterLogger('Plugin error: initialObject: %O', initialObject);

if (initialObject)
await initialObject.emit('error', uncaughtError);
else
throw uncaughtError;
}

reporterLogger('end dispatchToPlugin method: %s', method);
}

private _assignMessageBusEventHandlers (): void {
Expand Down Expand Up @@ -503,7 +505,6 @@ export default class Reporter {

const taskProperties = {
configuration: task.opts,
dashboardUrl: task.opts.dashboardUrl,
};

await this.dispatchToPlugin({
Expand Down
8 changes: 0 additions & 8 deletions src/runner/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -520,12 +520,6 @@ export default class Runner extends EventEmitter {
this._messageBus.clearListeners();
}

_getDashboardUrl () {
const dashboardReporter = this._reporters.find(r => r.plugin.name === 'dashboard')?.plugin;

return dashboardReporter?.getReportUrl ? dashboardReporter.getReportUrl() : '';
}

_prepareAndRunTask (options) {
const messageBusErrorPromise = promisifyEvent(this._messageBus, 'error');
const taskOptionsPromise = this._getRunTaskOptions(options);
Expand Down Expand Up @@ -605,8 +599,6 @@ export default class Runner extends EventEmitter {

const resultOptions = {
...this.configuration.getOptions(),

dashboardUrl: this._getDashboardUrl(),
};

return {
Expand Down
3 changes: 3 additions & 0 deletions src/utils/debug-loggers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ const runnerLogger = testcafeLogger.extend('runner');

const testRunControllerLogger = runnerLogger.extend('test-run-controller');

const reporterLogger = testcafeLogger.extend('reporter');

export {
nativeAutomationLogger,
requestPipelineLogger,
Expand All @@ -33,4 +35,5 @@ export {
requestPipelineOtherRequestLogger,
requestPipelineContextLogger,
testRunControllerLogger,
reporterLogger,
};
2 changes: 0 additions & 2 deletions src/utils/get-options/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import getVideoOptions from './video';
import getMetaOptions from './meta';
import getGrepOptions from './grep';
import getCompilerOptions from './compiler';
import getDashboardOptions from './dashboard';
import { getSkipJsErrorsOptions } from './skip-js-errors';

export {
Expand All @@ -16,6 +15,5 @@ export {
getMetaOptions,
getGrepOptions,
getCompilerOptions,
getDashboardOptions,
getSkipJsErrorsOptions,
};
12 changes: 0 additions & 12 deletions test/server/configuration-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,18 +394,6 @@ describe('TestCafeConfiguration', function () {

expect(testCafeConfiguration.getOption('jsConfig')).to.be.true;
});

it('Should raise an error if dashboard.token is specified in JSON configuration file', () => {
createJSONTestCafeConfigurationFile({
'dashboard': {
'token': 'secret',
},
});

expect((async () => {
await testCafeConfiguration.init();
})()).be.rejectedWith(/Insecure token declaration: cannot declare a Dashboard token in a JSON configuration file/);
});
});

it("File doesn't exists", async () => {
Expand Down
4 changes: 0 additions & 4 deletions test/server/reporter-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,6 @@ describe('Reporter', () => {
src: ['test.js'],
stopOnFirstFail: false,
takeScreenshotsOnFails: false,
dashboardUrl: 'https://example.com/path',
};

class TaskMock extends Task {
Expand Down Expand Up @@ -670,7 +669,6 @@ describe('Reporter', () => {
assertionTimeout: 3000,
browsers: ['chrome', 'firefox'],
concurrency: 1,
dashboardUrl: 'https://example.com/path',
debugMode: false,
debugOnFail: false,
developmentMode: false,
Expand All @@ -693,8 +691,6 @@ describe('Reporter', () => {
stopOnFirstFail: false,
takeScreenshotsOnFails: false,
},

dashboardUrl: 'https://example.com/path',
},
],
},
Expand Down

0 comments on commit b7d8c8d

Please sign in to comment.