JS: honor ignoreTestFailures flag and report failures to TC (KT-20735
fixed)
This commit is contained in:
@@ -31,43 +31,27 @@ node {
|
||||
download = true
|
||||
}
|
||||
|
||||
task testJest(type: NpmTask, dependsOn: [compileTestKotlin2Js, populateNodeModules, npmInstall]) {
|
||||
args = ['run', 'test-jest']
|
||||
execOverrides {
|
||||
it.standardOutput = new FileOutputStream("$buildDir/test-jest.log")
|
||||
it.errorOutput = new FileOutputStream("$buildDir/test-jest.err.log")
|
||||
def createFrameworkTest(def name) {
|
||||
return tasks.create("test$name", NpmTask) {
|
||||
dependsOn(compileKotlin2Js, populateNodeModules, npmInstall)
|
||||
def lowerName = name.toLowerCase()
|
||||
args = ['run', "test-$lowerName"]
|
||||
group = 'verification'
|
||||
execOverrides {
|
||||
it.ignoreExitValue = true
|
||||
it.standardOutput = new FileOutputStream("$buildDir/test-${lowerName}.log")
|
||||
it.errorOutput = new FileOutputStream("$buildDir/test-${lowerName}.err.log")
|
||||
}
|
||||
doLast {
|
||||
println file("$buildDir/tc-${lowerName}.log").text
|
||||
if (result.exitValue != 0 && !rootProject.ignoreTestFailures) {
|
||||
throw new GradleException("$name integration test failed")
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
task testJasmine(type: NpmTask, dependsOn: [compileTestKotlin2Js, populateNodeModules, npmInstall]) {
|
||||
args = ['run', 'test-jasmine']
|
||||
execOverrides {
|
||||
it.standardOutput = new FileOutputStream("$buildDir/test-jasmine.log")
|
||||
}
|
||||
}
|
||||
|
||||
task testMocha(type: NpmTask, dependsOn: [compileTestKotlin2Js, populateNodeModules, npmInstall]) {
|
||||
args = ['run', 'test-mocha']
|
||||
execOverrides {
|
||||
it.standardOutput = new FileOutputStream("$buildDir/test-mocha.log")
|
||||
}
|
||||
}
|
||||
|
||||
task testQunit(type: NpmTask, dependsOn: [compileTestKotlin2Js, populateNodeModules, npmInstall]) {
|
||||
args = ['run', 'test-qunit']
|
||||
execOverrides {
|
||||
it.standardOutput = new FileOutputStream("$buildDir/test-qunit.log")
|
||||
}
|
||||
}
|
||||
|
||||
task testTape(type: NpmTask, dependsOn: [compileTestKotlin2Js, populateNodeModules, npmInstall]) {
|
||||
args = ['run', 'test-tape']
|
||||
execOverrides {
|
||||
it.standardOutput = new FileOutputStream("$buildDir/test-tape.log")
|
||||
}
|
||||
}
|
||||
|
||||
[testJest, testJasmine, testMocha, testQunit, testTape].each {
|
||||
check.dependsOn it
|
||||
it.group = "verification"
|
||||
}
|
||||
['Jest', 'Jasmine', 'Mocha', 'Qunit', 'Tape'].each {
|
||||
check.dependsOn createFrameworkTest(it)
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
var Tester = require('./test-result-checker');
|
||||
var tester = new Tester(require('./expected-outcomes'));
|
||||
var tester = new Tester(require('./expected-outcomes'), 'jasmine');
|
||||
|
||||
process.on('exit', function() {
|
||||
tester.end();
|
||||
|
||||
@@ -2,7 +2,7 @@ var Tester = require('./test-result-checker');
|
||||
var expectedOutcomes = require('./expected-outcomes');
|
||||
|
||||
module.exports = function (results) {
|
||||
var tester = new Tester(expectedOutcomes);
|
||||
var tester = new Tester(expectedOutcomes, 'jest');
|
||||
var testResults = results.testResults[0].testResults;
|
||||
for (var i = 0; i < testResults.length; i++) {
|
||||
var tr = testResults[i];
|
||||
|
||||
@@ -5,7 +5,7 @@ var expectedOutcomes = require('./expected-outcomes');
|
||||
module.exports = function (runner) {
|
||||
mocha.reporters.Base.call(this, runner);
|
||||
|
||||
var tester = new Tester(expectedOutcomes);
|
||||
var tester = new Tester(expectedOutcomes, 'mocha');
|
||||
|
||||
runner.on('pass', function (test) {
|
||||
tester.passed(test.fullTitle().trim());
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
var Tester = require('./test-result-checker');
|
||||
var tester = new Tester(require('./expected-outcomes'));
|
||||
var tester = new Tester(require('./expected-outcomes'), 'qunit');
|
||||
|
||||
QUnit.testDone(function (details) {
|
||||
var testName = (details.module.replace('> ', '') + ' ' + details.name).trim();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
var tape = require('tape');
|
||||
var kotlin_test = require('kotlin-test');
|
||||
var kotlin_test = require('../build/node_modules/kotlin-test.js');
|
||||
|
||||
var suiteContext = {
|
||||
test: tape
|
||||
|
||||
@@ -14,7 +14,7 @@ for (var name in full) {
|
||||
}
|
||||
}
|
||||
|
||||
var tester = new Tester(noPending);
|
||||
var tester = new Tester(noPending, 'tape');
|
||||
|
||||
process.on('exit', function () {
|
||||
tester.end();
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
var Tester = function(testMap) {
|
||||
var fs = require('fs');
|
||||
|
||||
var Tester = function (testMap, frameworkName) {
|
||||
this._testMap = testMap;
|
||||
|
||||
this._isTeamCity = 'TEAMCITY_VERSION' in process.env;
|
||||
this._frameworkName = frameworkName;
|
||||
this._testStartDate = new Date();
|
||||
|
||||
this._testCount = {};
|
||||
|
||||
this._passed = 0;
|
||||
@@ -9,7 +15,7 @@ var Tester = function(testMap) {
|
||||
this._errors = []
|
||||
};
|
||||
|
||||
Tester.prototype._check = function(name, result) {
|
||||
Tester.prototype._check = function (name, result) {
|
||||
var count = this._testCount[name] | 0;
|
||||
this._testCount = count + 1;
|
||||
if (count === 1) {
|
||||
@@ -31,30 +37,46 @@ Tester.prototype._check = function(name, result) {
|
||||
this._passed++;
|
||||
};
|
||||
|
||||
Tester.prototype.passed = function(name) {
|
||||
Tester.prototype.passed = function (name) {
|
||||
this._check(name, 'pass');
|
||||
};
|
||||
|
||||
Tester.prototype.failed = function(name) {
|
||||
Tester.prototype.failed = function (name) {
|
||||
this._check(name, 'fail');
|
||||
};
|
||||
|
||||
Tester.prototype.pending = function(name) {
|
||||
Tester.prototype.pending = function (name) {
|
||||
this._check(name, 'pending');
|
||||
};
|
||||
|
||||
Tester.prototype.printResult = function() {
|
||||
console.log("Passed " + this._passed + " out of " + this._total);
|
||||
Tester.prototype.hasErrors = function() {
|
||||
return this._passed !== this._total || this._errors.length !== 0;
|
||||
};
|
||||
|
||||
Tester.prototype.printResult = function () {
|
||||
var message = 'Passed ' + this._passed + ' out of ' + this._total + '\n';
|
||||
for (var i = 0; i < this._errors.length; ++i) {
|
||||
console.log(this._errors[i]);
|
||||
message += this._errors[i] + '\n';
|
||||
}
|
||||
|
||||
if (this._isTeamCity) {
|
||||
var testName = 'kotlin-test + ' + this._frameworkName + ' integration test';
|
||||
var escapedMessage = message.replace(/\n/g, '|n').replace(/\r/g, '|r');
|
||||
message = "##teamcity[testStarted name='" + testName + "' captureStandardOutput='true']\n";
|
||||
if (this.hasErrors()) {
|
||||
message += "##teamcity[testFailed name='" + testName + "' message='has errors' details='" + escapedMessage + "']\n";
|
||||
}
|
||||
message +="##teamcity[testFinished name='" + testName + "' duration='" + (new Date() - this._testStartDate) + "']\n";
|
||||
}
|
||||
|
||||
fs.writeFileSync('build/tc-' + this._frameworkName + '.log', message);
|
||||
};
|
||||
|
||||
Tester.prototype.exitCode = function() {
|
||||
return this._errors.length;
|
||||
Tester.prototype.exitCode = function () {
|
||||
return this._isTeamCity || !this.hasErrors() ? 0 : 1;
|
||||
};
|
||||
|
||||
Tester.prototype.end = function() {
|
||||
Tester.prototype.end = function () {
|
||||
this.printResult();
|
||||
process.exitCode = this.exitCode();
|
||||
process.exit();
|
||||
|
||||
Reference in New Issue
Block a user