JS tests: changes to kotlin.test + the way compiler tests are generated.
This commit is contained in:
@@ -0,0 +1 @@
|
||||
node_modules
|
||||
@@ -0,0 +1,75 @@
|
||||
plugins {
|
||||
id "com.moowork.node" version "1.2.0"
|
||||
}
|
||||
|
||||
description = 'Kotlin-test integration tests for JS'
|
||||
|
||||
apply plugin: 'kotlin-platform-js'
|
||||
|
||||
dependencies {
|
||||
compile project(':kotlin-test:kotlin-test-js')
|
||||
}
|
||||
|
||||
|
||||
sourceSets {
|
||||
main.kotlin.srcDirs += 'src'
|
||||
test.kotlin.srcDirs += 'test'
|
||||
}
|
||||
|
||||
|
||||
compileKotlin2Js {
|
||||
kotlinOptions {
|
||||
moduleKind = "commonjs"
|
||||
}
|
||||
}
|
||||
|
||||
compileTestKotlin2Js {
|
||||
kotlinOptions {
|
||||
moduleKind = "commonjs"
|
||||
}
|
||||
}
|
||||
|
||||
compileKotlin2Js.doLast {
|
||||
configurations.compile.each { File file ->
|
||||
copy {
|
||||
includeEmptyDirs = false
|
||||
|
||||
from zipTree(file.absolutePath)
|
||||
into "${buildDir}/classes/"
|
||||
include { fileTreeElement ->
|
||||
def path = fileTreeElement.path
|
||||
path.endsWith(".js") && (path.startsWith("META-INF/resources/") || !path.startsWith("META-INF/"))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
node {
|
||||
version = '6.11.0'
|
||||
download = true
|
||||
}
|
||||
|
||||
task testJest(type: NpmTask, dependsOn: [compileTestKotlin2Js, compileTestKotlin2Js, npmInstall]) {
|
||||
args = ['run', 'test-jest']
|
||||
}
|
||||
|
||||
task testJasmine(type: NpmTask, dependsOn: [compileTestKotlin2Js, compileTestKotlin2Js, npmInstall]) {
|
||||
args = ['run', 'test-jasmine']
|
||||
}
|
||||
|
||||
task testMocha(type: NpmTask, dependsOn: [compileTestKotlin2Js, compileTestKotlin2Js, npmInstall]) {
|
||||
args = ['run', 'test-mocha']
|
||||
}
|
||||
|
||||
task testQunit(type: NpmTask, dependsOn: [compileTestKotlin2Js, compileTestKotlin2Js, npmInstall]) {
|
||||
args = ['run', 'test-qunit']
|
||||
}
|
||||
|
||||
task testTape(type: NpmTask, dependsOn: [compileTestKotlin2Js, compileTestKotlin2Js, npmInstall]) {
|
||||
args = ['run', 'test-tape']
|
||||
}
|
||||
|
||||
[testJest, testJasmine, testMocha, testQunit, testTape].each {
|
||||
check.dependsOn it
|
||||
it.group = "verification"
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
module.exports = {
|
||||
'SimpleTest testFoo': 'fail',
|
||||
'SimpleTest testBar': 'pass',
|
||||
'SimpleTest testFooWrong': 'pending',
|
||||
'TestTest emptyTest': 'pending',
|
||||
'org OrgTest test': 'pass',
|
||||
'org.some SomeTest someIsBetterThanNothing': 'pass',
|
||||
'org.some.name NameTest test': 'pass',
|
||||
'org.other.name NameTest nameIsOk': 'pass'
|
||||
};
|
||||
@@ -0,0 +1,22 @@
|
||||
var Tester = require('./test-result-checker');
|
||||
var tester = new Tester(require('./expected-outcomes'));
|
||||
|
||||
process.on('exit', function() {
|
||||
tester.end();
|
||||
});
|
||||
|
||||
jasmine.getEnv().addReporter({
|
||||
specDone: function(result) {
|
||||
var status = result.status;
|
||||
var name = result.fullName.trim();
|
||||
if (status === 'passed') {
|
||||
tester.passed(name);
|
||||
}
|
||||
else if (status === 'failed') {
|
||||
tester.failed(name);
|
||||
}
|
||||
else {
|
||||
tester.pending(name);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,22 @@
|
||||
var Tester = require('./test-result-checker');
|
||||
var expectedOutcomes = require('./expected-outcomes');
|
||||
|
||||
module.exports = function (results) {
|
||||
var tester = new Tester(expectedOutcomes);
|
||||
var testResults = results.testResults[0].testResults;
|
||||
for (var i = 0; i < testResults.length; i++) {
|
||||
var tr = testResults[i];
|
||||
|
||||
var name = tr.fullName.trim();
|
||||
if (tr.status === 'passed') {
|
||||
tester.passed(name);
|
||||
}
|
||||
else if (tr.status === 'failed') {
|
||||
tester.failed(name);
|
||||
}
|
||||
else {
|
||||
tester.pending(name);
|
||||
}
|
||||
}
|
||||
tester.end();
|
||||
};
|
||||
@@ -0,0 +1,25 @@
|
||||
var mocha = require('mocha');
|
||||
var Tester = require('./test-result-checker');
|
||||
var expectedOutcomes = require('./expected-outcomes');
|
||||
|
||||
module.exports = function (runner) {
|
||||
mocha.reporters.Base.call(this, runner);
|
||||
|
||||
var tester = new Tester(expectedOutcomes);
|
||||
|
||||
runner.on('pass', function (test) {
|
||||
tester.passed(test.fullTitle().trim());
|
||||
});
|
||||
|
||||
runner.on('fail', function (test, err) {
|
||||
tester.failed(test.fullTitle().trim());
|
||||
});
|
||||
|
||||
runner.on('pending', function (test) {
|
||||
tester.pending(test.fullTitle().trim());
|
||||
});
|
||||
|
||||
runner.on('end', function () {
|
||||
tester.end();
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,5 @@
|
||||
var paths = require('app-module-path');
|
||||
|
||||
paths.addPath('build/classes');
|
||||
paths.addPath('build/classes/main');
|
||||
paths.addPath('build/classes/test');
|
||||
@@ -0,0 +1,21 @@
|
||||
var Tester = require('./test-result-checker');
|
||||
var tester = new Tester(require('./expected-outcomes'));
|
||||
|
||||
QUnit.testDone(function (details) {
|
||||
var testName = (details.module.replace('> ', '') + ' ' + details.name).trim();
|
||||
if (details.skipped) {
|
||||
tester.pending(testName);
|
||||
}
|
||||
else if (!details.failed) {
|
||||
tester.passed(testName);
|
||||
}
|
||||
else {
|
||||
tester.failed(testName);
|
||||
}
|
||||
});
|
||||
|
||||
QUnit.done(function (details) {
|
||||
tester.printResult();
|
||||
details.failed = tester.exitCode();
|
||||
});
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
var tape = require('tape');
|
||||
var kotlin_test = require('kotlin-test');
|
||||
|
||||
var suiteContext = {
|
||||
test: tape
|
||||
};
|
||||
var hasTests = false;
|
||||
|
||||
kotlin_test.setAdapter({
|
||||
suite: function (name, ignored, fn) {
|
||||
suiteContext.test(name, { skip: ignored }, function(t) {
|
||||
var prevContext = suiteContext;
|
||||
suiteContext = t;
|
||||
hasTests = false;
|
||||
fn();
|
||||
suiteContext = prevContext;
|
||||
if (!hasTests) {
|
||||
t.pass('fake suite assert');
|
||||
}
|
||||
t.end();
|
||||
});
|
||||
},
|
||||
|
||||
test: function (name, ignored, fn) {
|
||||
hasTests = true;
|
||||
suiteContext.test(name, { skip: ignored }, function (t) {
|
||||
try {
|
||||
fn();
|
||||
} catch (e) {
|
||||
t.ok(false, e.message);
|
||||
}
|
||||
t.pass('fake assert');
|
||||
t.end();
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,61 @@
|
||||
var test = require('tape');
|
||||
var path = require('path');
|
||||
|
||||
var Tester = require('./test-result-checker');
|
||||
|
||||
// Tape doesn't report pending tests.
|
||||
// See https://github.com/substack/tape/pull/197 and https://github.com/substack/tape/issues/90
|
||||
var full = require('./expected-outcomes');
|
||||
var noPending = {};
|
||||
for (var name in full) {
|
||||
var result = full[name];
|
||||
if (result !== 'pending') {
|
||||
noPending[name] = result;
|
||||
}
|
||||
}
|
||||
|
||||
var tester = new Tester(noPending);
|
||||
|
||||
process.on('exit', function () {
|
||||
tester.end();
|
||||
});
|
||||
|
||||
var stream = test.createStream({objectMode: true});
|
||||
|
||||
var nameStack = [];
|
||||
var passed;
|
||||
var shouldSkip;
|
||||
|
||||
stream.on('data', function (row) {
|
||||
if (row.type === 'test') {
|
||||
var name = row.name === '(anonymous)' ? ' ' : row.name;
|
||||
nameStack.push(name);
|
||||
passed = true;
|
||||
shouldSkip = false;
|
||||
}
|
||||
else if (row.type === 'end') {
|
||||
if (!shouldSkip) {
|
||||
var name = nameStack.join(' ').trim();
|
||||
if (passed) {
|
||||
tester.passed(name);
|
||||
}
|
||||
else {
|
||||
tester.failed(name);
|
||||
}
|
||||
}
|
||||
shouldSkip = true;
|
||||
nameStack.pop();
|
||||
}
|
||||
else if (row.type === 'assert') {
|
||||
if (nameStack.length < 2 || row.name === 'fake suite assert') {
|
||||
shouldSkip = true;
|
||||
}
|
||||
if (!row.ok) {
|
||||
passed = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
process.argv.slice(2).forEach(function (file) {
|
||||
require(path.resolve(file));
|
||||
});
|
||||
@@ -0,0 +1,63 @@
|
||||
var Tester = function(testMap) {
|
||||
this._testMap = testMap;
|
||||
|
||||
this._testCount = {};
|
||||
|
||||
this._passed = 0;
|
||||
this._total = Object.keys(testMap).length;
|
||||
|
||||
this._errors = []
|
||||
};
|
||||
|
||||
Tester.prototype._check = function(name, result) {
|
||||
var count = this._testCount[name] | 0;
|
||||
this._testCount = count + 1;
|
||||
if (count === 1) {
|
||||
this._errors.push('Duplicate test: "' + name + '"');
|
||||
return;
|
||||
}
|
||||
|
||||
var expected = this._testMap[name];
|
||||
if (!expected) {
|
||||
this._errors.push('Unexpected test: "' + name + '"');
|
||||
return;
|
||||
}
|
||||
|
||||
if (result !== expected) {
|
||||
this._errors.push('Unexpected test: "' + name + '"');
|
||||
return;
|
||||
}
|
||||
|
||||
this._passed++;
|
||||
};
|
||||
|
||||
Tester.prototype.passed = function(name) {
|
||||
this._check(name, 'pass');
|
||||
};
|
||||
|
||||
Tester.prototype.failed = function(name) {
|
||||
this._check(name, 'fail');
|
||||
};
|
||||
|
||||
Tester.prototype.pending = function(name) {
|
||||
this._check(name, 'pending');
|
||||
};
|
||||
|
||||
Tester.prototype.printResult = function() {
|
||||
console.log("Passed " + this._passed + " out of " + this._total);
|
||||
for (var i = 0; i < this._errors.length; ++i) {
|
||||
console.log(this._errors[i]);
|
||||
}
|
||||
};
|
||||
|
||||
Tester.prototype.exitCode = function() {
|
||||
return this._errors.length;
|
||||
};
|
||||
|
||||
Tester.prototype.end = function() {
|
||||
this.printResult();
|
||||
process.exitCode = this.exitCode();
|
||||
process.exit();
|
||||
};
|
||||
|
||||
module.exports = Tester;
|
||||
@@ -0,0 +1,39 @@
|
||||
{
|
||||
"name": "it",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "js/index.js",
|
||||
"scripts": {
|
||||
"test-jasmine": "jasmine js/paths.js js/jasmine-reporter.js build/classes/test/kotlin-test-js-it_test.js",
|
||||
"test-jest": "jest",
|
||||
"test-mocha": "mocha -r js/paths.js --reporter js/mocha-reporter.js build/classes/test/kotlin-test-js-it_test.js",
|
||||
"test-qunit": "qunit -c js/paths.js -d js/qunit-reporter.js -t build/classes/test/kotlin-test-js-it_test.js",
|
||||
"test-tape": "tape js/paths.js js/tape-reporter.js js/tape-plugin.js build/classes/test/kotlin-test-js-it_test.js"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"app-module-path": "^2.2.0",
|
||||
"jasmine": "^2.6.0",
|
||||
"jest": "^20.0.4",
|
||||
"mocha": "^3.4.2",
|
||||
"qunit": "^1.0.0",
|
||||
"tape": "^4.6.3",
|
||||
"watchify": "^3.9.0"
|
||||
},
|
||||
"jest": {
|
||||
"verbose": true,
|
||||
"roots": [
|
||||
"<rootDir>/build/classes/",
|
||||
"<rootDir>/build/classes/main/",
|
||||
"<rootDir>/build/classes/test/"
|
||||
],
|
||||
"testResultsProcessor": "<rootDir>/js/jest-reporter.js",
|
||||
"testRegex": "_test\\.js$",
|
||||
"moduleNameMapper": {
|
||||
"^kotlin$": "<rootDir>/build/classes/kotlin.js",
|
||||
"^kotlin-test$": "<rootDir>/build/classes/kotlin-test.js",
|
||||
"^kotlin-test-js-it_main$": "<rootDir>/build/classes/main/kotlin-test-js-it_main.js"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
fun foo() = 10
|
||||
@@ -0,0 +1,23 @@
|
||||
import kotlin.test.*
|
||||
|
||||
class SimpleTest {
|
||||
|
||||
@Test fun testFoo() {
|
||||
assertEquals(20, foo())
|
||||
}
|
||||
|
||||
@Test fun testBar() {
|
||||
assertEquals(10, foo())
|
||||
}
|
||||
|
||||
@Ignore @Test fun testFooWrong() {
|
||||
assertEquals(20, foo())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Ignore
|
||||
class TestTest {
|
||||
@Test fun emptyTest() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package org
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
class OrgTest {
|
||||
@Test fun test() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package org.other.name
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
class NameTest {
|
||||
@Test fun nameIsOk() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package org.some
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
class SomeTest {
|
||||
@Test fun someIsBetterThanNothing() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package org.some.name
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
class NameTest {
|
||||
@Test fun test() {
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user