Skip to content
This repository was archived by the owner on Jan 22, 2024. It is now read-only.

Commit c19df29

Browse files
committed
Added JS tests sample projects: mocha, jasmine, jest, qunit, tape, karma, frontend-plugin
1 parent b0f0077 commit c19df29

File tree

23 files changed

+531
-0
lines changed

23 files changed

+531
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
buildscript {
2+
repositories {
3+
jcenter()
4+
maven { url 'https://dl.bintray.com/kotlin/kotlin-eap-1.1' }
5+
maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' }
6+
}
7+
dependencies {
8+
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.4-eap-33'
9+
classpath "org.jetbrains.kotlin:kotlin-frontend-plugin:0.0.19"
10+
}
11+
}
12+
13+
apply plugin: 'kotlin2js'
14+
apply plugin: 'org.jetbrains.kotlin.frontend'
15+
16+
repositories {
17+
jcenter()
18+
maven { url 'https://dl.bintray.com/kotlin/kotlin-eap-1.1' }
19+
}
20+
21+
dependencies {
22+
compile "org.jetbrains.kotlin:kotlin-stdlib-js"
23+
compile "org.jetbrains.kotlin:kotlin-test-js" // for now only compile configuration is supported
24+
}
25+
26+
kotlinFrontend {
27+
npm {
28+
// dependency "style-loader"
29+
30+
devDependency("karma")
31+
}
32+
33+
webpackBundle {
34+
bundleName = "main"
35+
contentPath = file('src/main/web')
36+
}
37+
}
38+
39+
[compileKotlin2Js, compileTestKotlin2Js]*.configure {
40+
kotlinOptions.moduleKind = "commonjs"
41+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fun foo() = 10
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import kotlin.test.*
2+
3+
class SimpleTest {
4+
5+
@Test fun testFoo() {
6+
assertEquals(10, foo())
7+
}
8+
9+
@Ignore @Test fun testFooWrong() {
10+
assertEquals(20, foo())
11+
}
12+
}
13+
14+
@Ignore
15+
class TestTest {
16+
@Test fun emptyTest() {
17+
// Will not run
18+
}
19+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
buildscript {
2+
repositories {
3+
maven { url 'https://dl.bintray.com/kotlin/kotlin-eap-1.1' }
4+
maven { url "https://plugins.gradle.org/m2/" }
5+
}
6+
dependencies {
7+
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.4-eap-33'
8+
classpath 'com.moowork.gradle:gradle-node-plugin:1.2.0'
9+
}
10+
}
11+
12+
apply plugin: 'kotlin2js'
13+
apply plugin: 'com.moowork.node'
14+
15+
repositories {
16+
maven { url 'https://dl.bintray.com/kotlin/kotlin-eap-1.1' }
17+
}
18+
19+
dependencies {
20+
compile "org.jetbrains.kotlin:kotlin-stdlib-js"
21+
testCompile "org.jetbrains.kotlin:kotlin-test-js"
22+
}
23+
24+
[compileKotlin2Js, compileTestKotlin2Js]*.configure {
25+
kotlinOptions.moduleKind = "commonjs"
26+
}
27+
28+
task populateNodeModules(type: Copy, dependsOn: compileKotlin2Js) {
29+
from compileKotlin2Js.destinationDir
30+
31+
configurations.testCompile.each {
32+
from zipTree(it.absolutePath).matching { include '*.js' }
33+
}
34+
35+
into "${buildDir}/node_modules"
36+
}
37+
38+
node {
39+
download = true
40+
}
41+
42+
task installJasmine(type: NpmTask) {
43+
args = ['install', 'jasmine']
44+
}
45+
46+
task runJasmine(type: NodeTask, dependsOn: [compileTestKotlin2Js, populateNodeModules, installJasmine]) {
47+
script = file('node_modules/.bin/jasmine')
48+
args = [compileTestKotlin2Js.outputFile]
49+
}
50+
51+
test.dependsOn runJasmine
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fun foo() = 10
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import kotlin.test.*
2+
3+
class SimpleTest {
4+
5+
@Test fun testFoo() {
6+
assertEquals(10, foo())
7+
}
8+
9+
@Ignore @Test fun testFooWrong() {
10+
assertEquals(20, foo())
11+
}
12+
}
13+
14+
@Ignore
15+
class TestTest {
16+
@Test fun emptyTest() {
17+
// Will not run
18+
}
19+
}

gradle/js-tests/jest/build.gradle

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
buildscript {
2+
repositories {
3+
maven { url 'https://dl.bintray.com/kotlin/kotlin-eap-1.1' }
4+
maven { url "https://plugins.gradle.org/m2/" }
5+
}
6+
dependencies {
7+
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.4-eap-33'
8+
classpath 'com.moowork.gradle:gradle-node-plugin:1.2.0'
9+
}
10+
}
11+
12+
apply plugin: 'kotlin2js'
13+
apply plugin: 'com.moowork.node'
14+
15+
repositories {
16+
maven { url 'https://dl.bintray.com/kotlin/kotlin-eap-1.1' }
17+
}
18+
19+
dependencies {
20+
compile "org.jetbrains.kotlin:kotlin-stdlib-js"
21+
testCompile "org.jetbrains.kotlin:kotlin-test-js"
22+
}
23+
24+
[compileKotlin2Js, compileTestKotlin2Js]*.configure {
25+
kotlinOptions.moduleKind = "commonjs"
26+
}
27+
28+
task populateNodeModules(type: Copy, dependsOn: compileKotlin2Js) {
29+
from compileKotlin2Js.destinationDir
30+
31+
configurations.testCompile.each {
32+
from zipTree(it.absolutePath).matching { include '*.js' }
33+
}
34+
35+
into "${buildDir}/node_modules"
36+
}
37+
38+
node {
39+
download = true
40+
}
41+
42+
task installJest(type: NpmTask) {
43+
args = ['install', 'jest']
44+
}
45+
46+
task runJest(type: NodeTask, dependsOn: [compileTestKotlin2Js, populateNodeModules, installJest]) {
47+
script = file('node_modules/.bin/jest')
48+
args = ['--testRegex=_test\\.js\$', compileTestKotlin2Js.outputFile]
49+
}
50+
51+
test.dependsOn runJest
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fun foo() = 10
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import kotlin.test.*
2+
3+
class SimpleTest {
4+
5+
@Test fun testFoo() {
6+
assertEquals(10, foo())
7+
}
8+
9+
@Ignore @Test fun testFooWrong() {
10+
assertEquals(20, foo())
11+
}
12+
}
13+
14+
@Ignore
15+
class TestTest {
16+
@Test fun emptyTest() {
17+
// Will not run
18+
}
19+
}

gradle/js-tests/karma/build.gradle

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
buildscript {
2+
repositories {
3+
maven { url 'https://dl.bintray.com/kotlin/kotlin-eap-1.1' }
4+
maven { url "https://plugins.gradle.org/m2/" }
5+
}
6+
dependencies {
7+
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.4-eap-33'
8+
classpath "gradle.plugin.com.craigburke.gradle:karma-gradle:1.4.4"
9+
}
10+
}
11+
12+
apply plugin: 'kotlin2js'
13+
apply plugin: 'com.craigburke.karma'
14+
15+
repositories {
16+
maven { url 'https://dl.bintray.com/kotlin/kotlin-eap-1.1' }
17+
}
18+
19+
dependencies {
20+
compile "org.jetbrains.kotlin:kotlin-stdlib-js"
21+
testCompile "org.jetbrains.kotlin:kotlin-test-js"
22+
}
23+
24+
def libDir = "$buildDir/lib"
25+
def compileOutput = compileKotlin2Js.outputFile
26+
def testOutput = compileTestKotlin2Js.outputFile
27+
28+
task populateNodeModules(type: Copy, dependsOn: compileKotlin2Js) {
29+
configurations.testCompile.each {
30+
from zipTree(it.absolutePath).matching { include '*.js' }
31+
}
32+
33+
into libDir
34+
}
35+
36+
karma {
37+
dependencies(['mocha'])
38+
39+
frameworks = ['mocha']
40+
browsers = ['PhantomJS']
41+
42+
files = [
43+
"$libDir/kotlin.js",
44+
"$libDir/*.js",
45+
compileOutput,
46+
testOutput
47+
]
48+
}
49+
50+
karmaRun {
51+
dependsOn compileTestKotlin2Js
52+
dependsOn populateNodeModules
53+
}
54+
55+
test.dependsOn karmaRun
56+
clean.dependsOn karmaClean
57+

0 commit comments

Comments
 (0)