mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-17 04:41:36 +08:00
Remove generation of test-results.xml (#4537)
This commit is contained in:

committed by
GitHub

parent
09535627b9
commit
661e6cf582
@ -262,34 +262,22 @@ var running = false;
|
|||||||
var testsQueue = new Array<TestInfo>();
|
var testsQueue = new Array<TestInfo>();
|
||||||
|
|
||||||
function printRunTestStats() {
|
function printRunTestStats() {
|
||||||
let testFileContent = new Array<string>();
|
|
||||||
const testCases = new Array<string>();
|
const testCases = new Array<string>();
|
||||||
|
|
||||||
var failedTestCount = 0;
|
var failedTestCount = 0;
|
||||||
var failedTestInfo = [];
|
const failedTestInfo = [];
|
||||||
const slowTests = new Array<string>();
|
const slowTests = new Array<string>();
|
||||||
|
|
||||||
let allTests = testsQueue.filter(t => t.isTest);
|
let allTests = testsQueue.filter(t => t.isTest);
|
||||||
|
|
||||||
testFileContent.push("<testsuites>");
|
|
||||||
|
|
||||||
allTests.forEach((testCase, i, arr) => {
|
allTests.forEach((testCase, i, arr) => {
|
||||||
let testName = testCase.testName;
|
let testName = testCase.testName;
|
||||||
let duration = (testCase.duration / 1000).toFixed(2);
|
|
||||||
|
|
||||||
if (!testCase.isPassed) {
|
if (!testCase.isPassed) {
|
||||||
failedTestCount++;
|
failedTestCount++;
|
||||||
|
|
||||||
let errorMessage = testCase.errorMessage;
|
|
||||||
|
|
||||||
failedTestInfo.push(testCase.testName + " FAILED: " + testCase.errorMessage);
|
failedTestInfo.push(testCase.testName + " FAILED: " + testCase.errorMessage);
|
||||||
|
|
||||||
testCases.push(`<testcase classname="${platform.device.os}" name="${testName}" time="${duration}"><failure type="exceptions.AssertionError"><![CDATA[${errorMessage}]]></failure></testcase>`);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
testCases.push(`<testcase classname="${platform.device.os}" name="${testName}" time="${duration}"></testcase>`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let duration = (testCase.duration / 1000).toFixed(2);
|
||||||
if (testCase.duration > 500) {
|
if (testCase.duration > 500) {
|
||||||
slowTests.push(`${testCase.testName}: ${duration}s`);
|
slowTests.push(`${testCase.testName}: ${duration}s`);
|
||||||
}
|
}
|
||||||
@ -297,13 +285,11 @@ function printRunTestStats() {
|
|||||||
|
|
||||||
const totalTime = (TKUnit.time() - startTime).toFixed(2);
|
const totalTime = (TKUnit.time() - startTime).toFixed(2);
|
||||||
|
|
||||||
testFileContent.push(`<testsuite name="NativeScript Tests" timestamp="${new Date()}" hostname="hostname" time="${totalTime}" errors="0" tests="${allTests.length}" skipped="0" failures="${failedTestCount}">`);
|
let finalMessage = `\n`+
|
||||||
|
`=== ALL TESTS COMPLETE ===\n` +
|
||||||
testFileContent = testFileContent.concat(testCases);
|
|
||||||
|
|
||||||
let finalMessage = `\n=== ALL TESTS COMPLETE ===\n` +
|
|
||||||
`${(allTests.length - failedTestCount)} OK, ${failedTestCount} failed\n` +
|
`${(allTests.length - failedTestCount)} OK, ${failedTestCount} failed\n` +
|
||||||
`DURATION: ${totalTime} ms\n`;
|
`DURATION: ${totalTime} ms\n`;
|
||||||
|
|
||||||
TKUnit.write(finalMessage, messageType.info);
|
TKUnit.write(finalMessage, messageType.info);
|
||||||
|
|
||||||
failedTestInfo.forEach((message, i, arr) => {
|
failedTestInfo.forEach((message, i, arr) => {
|
||||||
@ -311,40 +297,56 @@ function printRunTestStats() {
|
|||||||
finalMessage += "\n" + message;
|
finalMessage += "\n" + message;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// console.log("test-result.xml:\n" + generateTestFile(allTests));
|
||||||
|
|
||||||
// DO NOT CHANGE THE FIRST ROW! Used as an indicator for test run pass detection.
|
// DO NOT CHANGE THE FIRST ROW! Used as an indicator for test run pass detection.
|
||||||
TKUnit.write(`Tests EOF!`, messageType.info);
|
TKUnit.write(`Tests EOF!`, messageType.info);
|
||||||
|
|
||||||
testFileContent.push("</testsuite>");
|
showReportPage(finalMessage);
|
||||||
testFileContent.push("</testsuites>");
|
}
|
||||||
|
|
||||||
let testFilePath: string;
|
function generateTestFile(allTests: TestInfo[]) {
|
||||||
let testResultsFileName = "test-results.xml";
|
let failedTestCount = 0;
|
||||||
if (platform.isIOS) {
|
|
||||||
testFilePath = fs.path.join(fs.knownFolders.documents().path, testResultsFileName);
|
|
||||||
} else {
|
|
||||||
testFilePath = fs.path.join(android.os.Environment.getExternalStorageDirectory().getAbsolutePath(), "Documents", testResultsFileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
let testFile = fs.File.fromPath(testFilePath);
|
const testCases = new Array<string>();
|
||||||
testFile.writeTextSync(testFileContent.join(""));
|
allTests.forEach((testCase, i, arr) => {
|
||||||
|
let testName = testCase.testName;
|
||||||
|
let duration = (testCase.duration / 1000).toFixed(2);
|
||||||
|
|
||||||
finalMessage += "\n" + "Test results: " + testFilePath;
|
testCases.push(`<testcase classname="${platform.device.os}" name="${testName}" time="${duration}">`)
|
||||||
// finalMessage += "\n" + "----------------- ";
|
if (!testCase.isPassed) {
|
||||||
// finalMessage += "\n" + "Slow tests: ";
|
failedTestCount++;
|
||||||
// slowTests.forEach((message, i, arr) => {
|
testCases.push(`<failure type="exceptions.AssertionError"><![CDATA[${testCase.errorMessage}]]></failure>`)
|
||||||
// TKUnit.write(message, messageType.error);
|
}
|
||||||
// finalMessage += "\n" + message;
|
testCases.push(`</testcase>`);
|
||||||
// });
|
});
|
||||||
|
|
||||||
|
const totalTime = (TKUnit.time() - startTime).toFixed(2);
|
||||||
|
|
||||||
|
const result = [
|
||||||
|
"<testsuites>",
|
||||||
|
`<testsuite name="NativeScript Tests" timestamp="${new Date()}" hostname="hostname" time="${totalTime}" errors="0" tests="${allTests.length}" skipped="0" failures="${failedTestCount}">`,
|
||||||
|
...testCases,
|
||||||
|
"</testsuite>",
|
||||||
|
"</testsuites>"
|
||||||
|
].join("");
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
function showReportPage(finalMessage: string) {
|
||||||
let stack = new StackLayout();
|
let stack = new StackLayout();
|
||||||
|
|
||||||
let btn = new Button();
|
let btn = new Button();
|
||||||
btn.text = "Rerun tests";
|
btn.text = "Rerun tests";
|
||||||
btn.on("tap", () => runAll(testsSelector));
|
btn.on("tap", () => runAll(testsSelector));
|
||||||
stack.addChild(btn);
|
stack.addChild(btn);
|
||||||
|
|
||||||
let messageContainer = new TextView();
|
let messageContainer = new TextView();
|
||||||
messageContainer.editable = messageContainer.autocorrect = false;
|
messageContainer.editable = messageContainer.autocorrect = false;
|
||||||
messageContainer.text = finalMessage;
|
messageContainer.text = finalMessage;
|
||||||
stack.addChild(messageContainer);
|
stack.addChild(messageContainer);
|
||||||
|
|
||||||
const page = topmost().currentPage;
|
const page = topmost().currentPage;
|
||||||
page.id = unsetValue;
|
page.id = unsetValue;
|
||||||
page.className = unsetValue;
|
page.className = unsetValue;
|
||||||
@ -362,6 +364,7 @@ function printRunTestStats() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function startLog(): void {
|
function startLog(): void {
|
||||||
let testsName: string = this.name;
|
let testsName: string = this.name;
|
||||||
TKUnit.write("START " + testsName + " TESTS.", messageType.info);
|
TKUnit.write("START " + testsName + " TESTS.", messageType.info);
|
||||||
|
Reference in New Issue
Block a user