Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
"test:ai:temp": "AITEST=true BRIDGE_MODE=true vitest tests/bridge.test.ts"
},
"dependencies": {
"@cucumber/gherkin": "41.0.0",
"@cucumber/messages": "33.0.3",
"@midscene/android": "workspace:*",
"@midscene/computer": "workspace:*",
"@midscene/core": "workspace:*",
Expand Down
1 change: 1 addition & 0 deletions packages/cli/rslib.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export default defineConfig({
entry: {
index: 'src/index.ts',
'framework/index': 'src/framework/index.ts',
'framework/feature-loader': 'src/framework/feature-loader.ts',
},
define: {
__VERSION__: JSON.stringify(version),
Expand Down
12 changes: 7 additions & 5 deletions packages/cli/src/cli-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,19 @@ Examples:
};
};

// match yml or yaml files
const RUNNABLE_FILE_EXTENSIONS = ['.yml', '.yaml', '.feature'];

const isRunnableFile = (file: string): boolean =>
RUNNABLE_FILE_EXTENSIONS.some((ext) => file.endsWith(ext));

export async function matchYamlFiles(
fileGlob: string,
options?: {
cwd?: string;
},
) {
if (existsSync(fileGlob) && statSync(fileGlob).isDirectory()) {
fileGlob = join(fileGlob, '**/*.{yml,yaml}');
fileGlob = join(fileGlob, '**/*.{yml,yaml,feature}');
}

const { cwd } = options || {};
Expand All @@ -160,7 +164,5 @@ export async function matchYamlFiles(
cwd,
});

return files
.filter((file) => file.endsWith('.yml') || file.endsWith('.yaml'))
.sort();
return files.filter(isRunnableFile).sort();
}
4 changes: 3 additions & 1 deletion packages/cli/src/config-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ export async function parseConfigYaml(

// Validate that at least one file was found
if (files.length === 0) {
throw new Error('No YAML files found matching the patterns in "files"');
throw new Error(
'No YAML or feature files found matching the patterns in "files"',
);
}

// Generate default summary filename
Expand Down
32 changes: 21 additions & 11 deletions packages/cli/src/execution-summary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,19 @@ const toTestStatus = (
const safeReportNamePart = (value: string): string =>
value.replace(/[:*?"<>|# ]/g, '-');

const createRetryReportName = (file: string): string => {
const fileName = basename(file, extname(file)) || 'yaml';
const resultDisplayName = (result: MidsceneYamlConfigResult): string =>
result.testName ?? result.file;

const retryAttemptDisplayName = (result: MidsceneYamlConfigResult): string =>
result.testName ?? basename(result.file);

const createRetryReportName = (result: MidsceneYamlConfigResult): string => {
const label = resultDisplayName(result);
const fileName = result.testName
? basename(label)
: basename(result.file, extname(result.file)) || 'yaml';
const fileHash = createHash('sha1')
.update(resolve(file))
.update(`${resolve(result.file)}\0${result.testName ?? ''}`)
.digest('hex')
.slice(0, 8);
return `${safeReportNamePart(fileName)}-${fileHash}-retry-attempts`;
Expand All @@ -179,13 +188,14 @@ const createRetryAttemptReport = (
const tool = new ReportMergingTool();
for (const attempt of attemptsWithReports) {
const status = toTestStatus(attempt);
const displayName = retryAttemptDisplayName(result);
tool.append({
reportFilePath: attempt.report!,
reportAttributes: {
testDuration: attempt.duration ?? 0,
testStatus: status,
testTitle: `Attempt ${attempt.attempt}: ${status} - ${basename(result.file)}`,
testId: `${safeReportNamePart(basename(result.file))}-attempt-${attempt.attempt}`,
testTitle: `Attempt ${attempt.attempt}: ${status} - ${displayName}`,
testId: `${safeReportNamePart(displayName)}-attempt-${attempt.attempt}`,
testDescription:
attempt.error ??
(attempt.success ? 'YAML attempt passed' : 'YAML attempt failed'),
Expand All @@ -194,7 +204,7 @@ const createRetryAttemptReport = (
}

return (
tool.mergeReports(createRetryReportName(result.file), {
tool.mergeReports(createRetryReportName(result), {
outputDir: getMidsceneRunSubDir('report'),
overwrite: true,
}) || undefined
Expand Down Expand Up @@ -249,7 +259,7 @@ export function writeExecutionSummaryFile(
const retryReport = createRetryAttemptReportSafely(result);

return {
script: relative(outputDir, result.file),
script: result.testName ?? relative(outputDir, result.file),
success: result.success,
resultType: result.resultType,
output: result.output
Expand Down Expand Up @@ -340,15 +350,15 @@ export function printExecutionSummary(
if (successfulFiles.length > 0) {
console.log('\n✅ Successful files:');
successfulFiles.forEach((result) => {
console.log(` ${result.file}`);
console.log(` ${resultDisplayName(result)}`);
printResultArtifacts(result);
});
}

if (failedFiles.length > 0) {
console.log('\n❌ Failed files');
failedFiles.forEach((result) => {
console.log(` ${result.file}`);
console.log(` ${resultDisplayName(result)}`);
if (result.error) {
console.log(` Error: ${result.error}`);
}
Expand All @@ -360,7 +370,7 @@ export function printExecutionSummary(
'\n⚠️ Partial failed files (some tasks failed with continueOnError)',
);
partialFailedFiles.forEach((result) => {
console.log(` ${result.file}`);
console.log(` ${resultDisplayName(result)}`);
if (result.error) {
console.log(` Error: ${result.error}`);
}
Expand All @@ -370,7 +380,7 @@ export function printExecutionSummary(
if (notExecutedFiles.length > 0) {
console.log('\n⏸️ Not executed files');
notExecutedFiles.forEach((result) => {
console.log(` ${result.file}`);
console.log(` ${resultDisplayName(result)}`);
});
}

Expand Down
9 changes: 8 additions & 1 deletion packages/cli/src/framework/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
printExecutionSummary,
writeExecutionSummaryFile,
} from '../execution-summary';
import { isFeatureFile } from './feature-file';
import {
type GeneratedRstestYamlProject,
type RstestYamlCaseOptions,
Expand Down Expand Up @@ -68,14 +69,20 @@ const readProjectResults = (
) as MidsceneYamlConfigResult;
}

return createNotExecutedYamlResult(item.yamlFile);
return {
...createNotExecutedYamlResult(item.yamlFile),
testName: item.testName,
};
});

export async function runFrameworkTestConfig(
config: BatchRunnerConfig,
commandOptions: FrameworkTestCommandOptions = {},
): Promise<number> {
printExecutionPlan(config);
if (config.shareBrowserContext && config.files.some(isFeatureFile)) {
throw new Error('shareBrowserContext is not supported for .feature files');
}

const projectDir = resolve(commandOptions.projectDir || process.cwd());
const project = createRstestYamlProject({
Expand Down
Loading
Loading