Add error message & format selection capability to batched test runner
Change-Id: I6686bf951204672c3542148e85e59e14e83e73c4 Reviewed-by: David Skoland <david.skoland@qt.io>
This commit is contained in:
parent
334c27dad1
commit
9e05c9ad86
@ -36,6 +36,7 @@ class WebApi {
|
|||||||
#status = RunnerStatus.Running;
|
#status = RunnerStatus.Running;
|
||||||
#statusChangedEventPrivate;
|
#statusChangedEventPrivate;
|
||||||
#testStatusChangedEventPrivate;
|
#testStatusChangedEventPrivate;
|
||||||
|
#errorDetails;
|
||||||
|
|
||||||
onStatusChanged =
|
onStatusChanged =
|
||||||
new EventSource((privateInterface) => this.#statusChangedEventPrivate = privateInterface);
|
new EventSource((privateInterface) => this.#statusChangedEventPrivate = privateInterface);
|
||||||
@ -52,11 +53,13 @@ class WebApi {
|
|||||||
setTestResultData: (testName, testStatus, exitCode, textOutput) =>
|
setTestResultData: (testName, testStatus, exitCode, textOutput) =>
|
||||||
this.#setTestResultData(testName, testStatus, exitCode, textOutput),
|
this.#setTestResultData(testName, testStatus, exitCode, textOutput),
|
||||||
setTestRunnerStatus: status => this.#setTestRunnerStatus(status),
|
setTestRunnerStatus: status => this.#setTestRunnerStatus(status),
|
||||||
|
setTestRunnerError: details => this.#setTestRunnerError(details),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
get results() { return this.#results; }
|
get results() { return this.#results; }
|
||||||
get status() { return this.#status; }
|
get status() { return this.#status; }
|
||||||
|
get errorDetails() { return this.#errorDetails; }
|
||||||
|
|
||||||
#registerTest(testName) { this.#results.set(testName, { status: TestStatus.Pending }); }
|
#registerTest(testName) { this.#results.set(testName, { status: TestStatus.Pending }); }
|
||||||
|
|
||||||
@ -84,6 +87,12 @@ class WebApi {
|
|||||||
this.#status = status;
|
this.#status = status;
|
||||||
this.#statusChangedEventPrivate.fireEvent(status);
|
this.#statusChangedEventPrivate.fireEvent(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#setTestRunnerError(details) {
|
||||||
|
this.#status = RunnerStatus.Error;
|
||||||
|
this.#errorDetails = details;
|
||||||
|
this.#statusChangedEventPrivate.fireEvent(RunnerStatus.Error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class BatchedTestRunner {
|
class BatchedTestRunner {
|
||||||
@ -97,7 +106,7 @@ class BatchedTestRunner {
|
|||||||
this.#privateWebApi = privateWebApi;
|
this.#privateWebApi = privateWebApi;
|
||||||
}
|
}
|
||||||
|
|
||||||
async #doRun(testName) {
|
async #doRun(testName, testOutputFormat) {
|
||||||
const module = await this.#loader.loadEmscriptenModule(
|
const module = await this.#loader.loadEmscriptenModule(
|
||||||
BatchedTestRunner.#TestBatchModuleName,
|
BatchedTestRunner.#TestBatchModuleName,
|
||||||
() => { }
|
() => { }
|
||||||
@ -112,7 +121,7 @@ class BatchedTestRunner {
|
|||||||
try {
|
try {
|
||||||
const LogToStdoutSpecialFilename = '-';
|
const LogToStdoutSpecialFilename = '-';
|
||||||
result = await module.exec({
|
result = await module.exec({
|
||||||
args: [testClassName, '-o', `${LogToStdoutSpecialFilename},xml`],
|
args: [testClassName, '-o', `${LogToStdoutSpecialFilename},${testOutputFormat}`],
|
||||||
});
|
});
|
||||||
|
|
||||||
if (result.exitCode < 0)
|
if (result.exitCode < 0)
|
||||||
@ -127,13 +136,11 @@ class BatchedTestRunner {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async run(testName) {
|
async run(testName, testOutputFormat) {
|
||||||
try {
|
|
||||||
await this.#doRun(testName);
|
await this.#doRun(testName, testOutputFormat);
|
||||||
this.#privateWebApi.setTestRunnerStatus(RunnerStatus.Completed);
|
this.#privateWebApi.setTestRunnerStatus(RunnerStatus.Completed);
|
||||||
} catch (e) {
|
|
||||||
this.#privateWebApi.setTestRunnerStatus(RunnerStatus.Error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async #getTestClassNames(module) {
|
async #getTestClassNames(module) {
|
||||||
@ -146,17 +153,27 @@ class BatchedTestRunner {
|
|||||||
window.qtTestRunner = new WebApi(privateApi => privateWebApi = privateApi);
|
window.qtTestRunner = new WebApi(privateApi => privateWebApi = privateApi);
|
||||||
|
|
||||||
const parsed = parseQuery(location.search);
|
const parsed = parseQuery(location.search);
|
||||||
const testName = parsed['qtestname'];
|
const testName = parsed.get('qtestname');
|
||||||
if (typeof testName !== 'undefined' && (typeof testName !== 'string' || testName === '')) {
|
try {
|
||||||
console.error('The testName parameter is incorrect');
|
if (typeof testName !== 'undefined' && (typeof testName !== 'string' || testName === ''))
|
||||||
return;
|
throw new Error('The testName parameter is incorrect');
|
||||||
|
|
||||||
|
const testOutputFormat = (() => {
|
||||||
|
const format = parsed.get('qtestoutputformat') ?? 'txt';
|
||||||
|
console.log(format);
|
||||||
|
if (-1 === ['txt', 'xml', 'lightxml', 'junitxml', 'tap'].indexOf(format))
|
||||||
|
throw new Error(`Bad file format: ${format}`);
|
||||||
|
return format;
|
||||||
|
})();
|
||||||
|
|
||||||
|
const resourceLocator = new ResourceLocator('');
|
||||||
|
const testRunner = new BatchedTestRunner(
|
||||||
|
new ModuleLoader(new ResourceFetcher(resourceLocator), resourceLocator),
|
||||||
|
privateWebApi
|
||||||
|
);
|
||||||
|
|
||||||
|
testRunner.run(testName, testOutputFormat);
|
||||||
|
} catch (e) {
|
||||||
|
privateWebApi.setTestRunnerError(e.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
const resourceLocator = new ResourceLocator('');
|
|
||||||
const testRunner = new BatchedTestRunner(
|
|
||||||
new ModuleLoader(new ResourceFetcher(resourceLocator), resourceLocator),
|
|
||||||
privateWebApi
|
|
||||||
);
|
|
||||||
|
|
||||||
testRunner.run(testName);
|
|
||||||
})();
|
})();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user