+
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
764 changes: 54 additions & 710 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions src/adapter/codecept.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,20 @@ function CodeceptReporter(config) {

output.debug = function(msg) {
originalOutput.debug(msg);
dataStorage.putData('log', repeat(this.stepShift) + pc.cyan(msg.toString()));
dataStorage.putData('log', repeat(this?.stepShift || 0) + pc.cyan(msg.toString()));
};

output.say = function(message, color = 'cyan') {
originalOutput.say(message, color);
const sayMsg = repeat(this.stepShift) + ` ${pc.bold(pc[color](message))}`;
const sayMsg = repeat(this?.stepShift || 0) + ` ${pc.bold(pc[color](message))}`;
dataStorage.putData('log', sayMsg);
};

output.log = function(msg) {
originalOutput.log(msg);
dataStorage.putData('log', repeat(this.stepShift) + pc.gray(msg));
dataStorage.putData('log', repeat(this?.stepShift || 0) + pc.gray(msg));
};
output.stepShift = 0;

recorder.startUnlessRunning();

Expand Down
6 changes: 6 additions & 0 deletions src/bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,18 @@ import pc from 'picocolors';
import { filesize as prettyBytes } from 'filesize';
import dotenv from 'dotenv';
import Replay from '../replay.js';
import { checkForEnvPassedAsArguments } from '../utils/cli_utils.js';
import fs from 'fs';
import path from 'path';
import os from 'os';

const debug = createDebugMessages('@testomatio/reporter:xml-cli');
const version = getPackageVersion();
console.log(pc.cyan(pc.bold(` 🤩 Testomat.io Reporter v${version}`)));
const program = new Command();

checkForEnvPassedAsArguments();

program
.version(version)
.option('--env-file <envfile>', 'Load environment variables from env file')
Expand Down
4 changes: 4 additions & 0 deletions src/bin/reportXml.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import createDebugMessages from 'debug';
import { APP_PREFIX } from '../constants.js';
import XmlReader from '../xmlReader.js';
import { getPackageVersion } from '../utils/utils.js';
import { checkForEnvPassedAsArguments } from '../utils/cli_utils.js';
import dotenv from 'dotenv';
import path from 'path';

Expand All @@ -15,6 +16,9 @@ const debug = createDebugMessages('@testomatio/reporter:xml-cli');
console.log(pc.cyan(pc.bold(` 🤩 Testomat.io XML Reporter v${version}`)));
const program = new Command();

checkForEnvPassedAsArguments();


program
.arguments('<pattern>')
.option('-d, --dir <dir>', 'Project directory')
Expand Down
3 changes: 3 additions & 0 deletions src/bin/startTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ import { APP_PREFIX, STATUS } from '../constants.js';
import { getPackageVersion } from '../utils/utils.js';
import { config } from '../config.js';
import dotenv from 'dotenv';
import { checkForEnvPassedAsArguments } from '../utils/cli_utils.js';

const version = getPackageVersion();
console.log(pc.cyan(pc.bold(` 🤩 Testomat.io Reporter v${version}`)));
const program = new Command();

checkForEnvPassedAsArguments();

program
.option('-c, --command <cmd>', 'Test runner command')
.option('--launch', 'Start a new run and return its ID')
Expand Down
3 changes: 3 additions & 0 deletions src/bin/uploadArtifacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ import { getPackageVersion } from '../utils/utils.js';
import { config } from '../config.js';
import { readLatestRunId } from '../utils/utils.js';
import dotenv from 'dotenv';
import { checkForEnvPassedAsArguments } from '../utils/cli_utils.js';

const debug = createDebugMessages('@testomatio/reporter:upload-cli');
const version = getPackageVersion();
console.log(pc.cyan(pc.bold(` 🤩 Testomat.io Reporter v${version}`)));
const program = new Command();

checkForEnvPassedAsArguments();

program
.option('--env-file <envfile>', 'Load environment variables from env file')
.option('--force', 'Re-upload artifacts even if they were uploaded before')
Expand Down
3 changes: 1 addition & 2 deletions src/pipe/testomatio.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ class TestomatioPipe {
const resp = await this.client.request({
method: 'GET',
url: '/api/test_grep',
params: q.params,
responseType: q.responseType
...q,
});

if (Array.isArray(resp.data?.tests) && resp.data?.tests?.length > 0) {
Expand Down
16 changes: 11 additions & 5 deletions src/reporter-functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { services } from './services/index.js';
/**
* Stores path to file as artifact and uploads it to the S3 storage
* @param {string | {path: string, type: string, name: string}} data - path to file or object with path, type and name
* @param {any} [context=null] - optional context parameter
* @returns {void}
*/
function saveArtifact(data, context = null) {
if (process.env.IS_PLAYWRIGHT)
Expand All @@ -14,7 +16,8 @@ function saveArtifact(data, context = null) {

/**
* Attach log message(s) to the test report
* @param string
* @param {...any} args - log messages to attach
* @returns {void}
*/
function logMessage(...args) {
if (process.env.IS_PLAYWRIGHT) throw new Error('This function is not available in Playwright framework');
Expand All @@ -23,7 +26,8 @@ function logMessage(...args) {

/**
* Similar to "log" function but marks message in report as a step
* @param {string} message
* @param {string} message - step message
* @returns {void}
*/
function addStep(message) {
if (process.env.IS_PLAYWRIGHT)
Expand All @@ -34,8 +38,9 @@ function addStep(message) {

/**
* Add key-value pair(s) to the test report
* @param {{[key: string]: string} | string} keyValue object { key: value } (multiple props allowed) or key (string)
* @param {string?} value
* @param {{[key: string]: string} | string} keyValue - object { key: value } (multiple props allowed) or key (string)
* @param {string|null} [value=null] - optional value when keyValue is a string
* @returns {void}
*/
function setKeyValue(keyValue, value = null) {
if (process.env.IS_PLAYWRIGHT)
Expand All @@ -50,7 +55,8 @@ function setKeyValue(keyValue, value = null) {
/**
* Add a single label to the test report
* @param {string} key - label key (e.g. 'severity', 'feature', or just 'smoke' for labels without values)
* @param {string} [value] - optional label value (e.g. 'high', 'login')
* @param {string|null} [value=null] - optional label value (e.g. 'high', 'login')
* @returns {void}
*/
function setLabel(key, value = null) {
if (!key || typeof key !== 'string') {
Expand Down
12 changes: 6 additions & 6 deletions src/reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ export const step = reporterFunctions.step;
export const label = reporterFunctions.label;

/**
* @typedef {import('./reporter-functions.js')} artifact
* @typedef {import('./reporter-functions.js')} log
* @typedef {import('./services/index.js')} logger
* @typedef {import('./reporter-functions.js')} meta
* @typedef {import('./reporter-functions.js')} step
* @typedef {import('./reporter-functions.js')} label
* @typedef {typeof import('./reporter-functions.js').default.artifact} ArtifactFunction
* @typedef {typeof import('./reporter-functions.js').default.log} LogFunction
* @typedef {typeof import('./services/index.js').services.logger} LoggerService
* @typedef {typeof import('./reporter-functions.js').default.keyValue} MetaFunction
* @typedef {typeof import('./reporter-functions.js').default.step} StepFunction
* @typedef {typeof import('./reporter-functions.js').default.label} LabelFunction
*/
export default {
/**
Expand Down
13 changes: 13 additions & 0 deletions src/utils/cli_utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import pc from 'picocolors';
import { APP_PREFIX } from '../constants.js';

export function checkForEnvPassedAsArguments() {
const testomatioArgs = process.argv.filter(arg => arg.startsWith('TESTOMATIO'));
if (testomatioArgs.length === 0) return;

console.log(pc.yellow(`${APP_PREFIX} Found TESTOMATIO env passed as CLI arguments: ${testomatioArgs.join(', ')}`));
console.log(pc.yellow(`${APP_PREFIX} These variables can't be processed and will be ignored`));
console.log(pc.yellow(`${APP_PREFIX} Please use the following format instead:`));
console.log(pc.yellow(`${APP_PREFIX} ${testomatioArgs.join(' ')} ${process.argv[1].split('/').pop()}`));
console.log();
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const warningText = `${APP_PREFIX} Found TESTOMATIO env passed as CLI arguments: ${testomatioArgs.join(', ')}
These variables can't be processed and will be ignored. Please use the following format instead:
${testomatioArgs.join(' ')} ${process.argv[1].split('/').pop()}`;
console.log(pc.yellow(warningText));

126 changes: 112 additions & 14 deletions types/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,118 @@
declare module '@testomatio/reporter' {
import { services } from '@testomatio/reporter/src/services/index.js';
import reporterFunctions from '@testomatio/reporter/src/reporter-functions.js';

export default {
artifact: typeof reporterFunctions.artifact,
log: typeof reporterFunctions.log,
logger: typeof services.logger,
meta: typeof reporterFunctions.keyValue,
step: typeof reporterFunctions.step,
label: typeof reporterFunctions.label,
/**
* Stores path to file as artifact and uploads it to the S3 storage
* @param data - path to file or object with path, type and name
* @param context - optional context parameter
*/
export function artifact(data: string | ArtifactData, context?: any): void;

/**
* Attach log message(s) to the test report
* @param args - log messages
*/
export function log(...args: any[]): void;

/**
* Similar to "log" function but marks message in report as a step
* @param message - step message
*/
export function step(message: string): void;

/**
* Add key-value pair(s) to the test report
* @param keyValue - object { key: value } (multiple props allowed) or key (string)
* @param value - optional value when keyValue is a string
*/
export function meta(keyValue: Record<string, string> | string, value?: string | null): void;

/**
* Add a single label to the test report
* @param key - label key (e.g. 'severity', 'feature', or just 'smoke' for labels without values)
* @param value - optional label value (e.g. 'high', 'login')
*/
export function label(key: string, value?: string | null): void;

/**
* Logger service for intercepting and managing logs
*/
export const logger: Logger;

interface ArtifactData {
path: string;
type: string;
name: string;
}

interface Logger {
logLevel: string;
prettyObjects: boolean;

/**
* Define a step inside a test. Step name is attached to the report
* @param strings - template literal strings
* @param values - template literal values
*/
step(strings: any, ...values: any[]): void;

/**
* Get logs for a specific context
* @param context - testId or test context from test runner
*/
getLogs(context: string): string[];

/**
* Template literal log function
* @param strings - template literal strings or message
* @param args - arguments
*/
_templateLiteralLog(strings: any, ...args: any[]): void;

// Console methods
assert(...args: any[]): void;
debug(...args: any[]): void;
error(...args: any[]): void;
info(...args: any[]): void;
log(...args: any[]): void;
trace(...args: any[]): void;
warn(...args: any[]): void;

/**
* Intercept user logger messages
* @param userLogger - user's logger instance
*/
intercept(userLogger: any): void;

/**
* Stop logger interception
*/
stopInterception(): void;

/**
* Configure logger settings
* @param config - configuration options
*/
configure(config?: LoggerConfig): void;
}

interface LoggerConfig {
logLevel?: string;
prettyObjects?: boolean;
}

const _default: {
/**
* @deprecated Use `log` or `testomat.log`
*/
testomatioLogger: Logger;
artifact: typeof artifact;
log: typeof log;
logger: Logger;
meta: typeof meta;
step: typeof step;
label: typeof label;
};

export const artifact: typeof reporterFunctions.artifact;
export const log: typeof reporterFunctions.log;
export const meta: typeof reporterFunctions.keyValue;
export const label: typeof reporterFunctions.label;
export default _default;
}

export interface FileType {
Expand Down
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载