Skip to content

Commit f0fc770

Browse files
committed
JS: Moved node_modules into build directory
1 parent 9df50e6 commit f0fc770

File tree

6 files changed

+71
-5936
lines changed

6 files changed

+71
-5936
lines changed

.gitignore

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,4 @@
44
.gradletasknamecache
55
build
66
out
7-
target
8-
node_modules
9-
package-lock.json
7+
target

gradle/node-js.gradle

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,38 @@ node {
55
version = "$node_version"
66
npmVersion = "$npm_version"
77
download = true
8+
nodeModulesDir = file(buildDir)
89
}
10+
11+
// Configures testing for JS modules
12+
13+
task prepareNodePackage(type: Copy) {
14+
from("npm") {
15+
include 'package.json'
16+
expand project.properties
17+
}
18+
from("npm") {
19+
exclude 'package.json'
20+
}
21+
into "$node.nodeModulesDir"
22+
}
23+
24+
npmInstall.dependsOn prepareNodePackage
25+
26+
task populateNodeModules(type: Copy, dependsOn: [compileKotlin2Js]) {
27+
from compileKotlin2Js.destinationDir
28+
into "$node.nodeModulesDir/node_modules"
29+
30+
afterEvaluate {
31+
configurations.testCompile.each {
32+
if (it.absolutePath.endsWith(".jar")) {
33+
from zipTree(it.absolutePath).matching {
34+
include '*.js'
35+
include '*.js.map'
36+
}
37+
}
38+
}
39+
}
40+
}
41+
42+
npmInstall.dependsOn populateNodeModules

gradle/test-mocha-js.gradle

Lines changed: 30 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,6 @@
1-
// Configures testing for JS modules
2-
3-
task populateNodeModules(type: Copy, dependsOn: compileKotlin2Js) {
4-
from compileKotlin2Js.destinationDir
5-
into "${buildDir}/node_modules"
6-
7-
afterEvaluate {
8-
configurations.testCompile.each {
9-
from zipTree(it.absolutePath).matching {
10-
include '*.js'
11-
include '*.js.map'
12-
}
13-
}
14-
}
15-
}
16-
171
// -- Testing with Mocha under Node
182

19-
task installDependenciesMochaNode(type: NpmTask) {
3+
task installDependenciesMochaNode(type: NpmTask, dependsOn: [npmInstall]) {
204
args = ['install',
215
"mocha@$mocha_version",
226
"source-map-support@$source_map_suport_version",
@@ -25,20 +9,17 @@ task installDependenciesMochaNode(type: NpmTask) {
259
"mocha-teamcity-reporter@$mocha_teamcity_reporter_version"]
2610
}
2711

28-
task prepareMochaNode(dependsOn: [compileTestKotlin2Js, populateNodeModules, installDependenciesMochaNode])
29-
30-
task testMochaNode(type: NodeTask, dependsOn: prepareMochaNode) {
31-
script = file('node_modules/mocha/bin/mocha')
12+
task testMochaNode(type: NodeTask, dependsOn: [compileTestKotlin2Js, installDependenciesMochaNode]) {
13+
script = file("$node.nodeModulesDir/node_modules/mocha/bin/mocha")
3214
args = [compileTestKotlin2Js.outputFile, '--require', 'source-map-support/register']
3315
if (project.hasProperty("teamcity")) args += ['--reporter', 'mocha-teamcity-reporter']
3416
}
3517

3618
test.dependsOn testMochaNode
3719

38-
3920
// -- Testing with Mocha under headless Chrome
4021

41-
task installDependenciesMochaChrome(type: NpmTask) {
22+
task installDependenciesMochaChrome(type: NpmTask, dependsOn: [npmInstall]) {
4223
args = ['install',
4324
"mocha@$mocha_version",
4425
"mocha-headless-chrome@$mocha_headless_chrome_version",
@@ -49,44 +30,40 @@ task installDependenciesMochaChrome(type: NpmTask) {
4930
"mocha-teamcity-reporter@$mocha_teamcity_reporter_version"]
5031
}
5132

52-
task prepareMochaChrome(dependsOn: [compileTestKotlin2Js, populateNodeModules, installDependenciesMochaChrome])
33+
def mochaChromeTestPage = file("$buildDir/test-page.html")
34+
35+
task prepareMochaChrome(dependsOn: [compileTestKotlin2Js, installDependenciesMochaChrome]) {
36+
outputs.file(mochaChromeTestPage)
37+
}
5338

5439
prepareMochaChrome.doLast {
55-
file("$buildDir/test-page.html").text = """
56-
<!DOCTYPE html>
57-
<html>
58-
<head>
59-
<title>Mocha Tests</title>
60-
<meta charset="utf-8">
61-
<link rel="stylesheet" href="$projectDir/node_modules/mocha/mocha.css">
62-
</head>
63-
<body>
64-
<div id="mocha"></div>
65-
<script src="$projectDir/node_modules/mocha/mocha.js"></script>
66-
<script>mocha.setup('bdd');</script>
67-
<script src="$projectDir/node_modules/kotlin/kotlin.js"></script>
68-
<script src="$projectDir/node_modules/kotlin-test/kotlin-test.js"></script>
69-
<script src="$compileKotlin2Js.outputFile"></script>
70-
<script src="$compileTestKotlin2Js.outputFile"></script>
71-
<script>mocha.run();</script>
72-
</body>
73-
</html>
74-
"""
40+
mochaChromeTestPage.text = """<!DOCTYPE html>
41+
<html>
42+
<head>
43+
<title>Mocha Tests</title>
44+
<meta charset="utf-8">
45+
<link rel="stylesheet" href="$node.nodeModulesDir/node_modules/mocha/mocha.css">
46+
</head>
47+
<body>
48+
<div id="mocha"></div>
49+
<script src="$node.nodeModulesDir/node_modules/mocha/mocha.js"></script>
50+
<script>mocha.setup('bdd');</script>
51+
<script src="$node.nodeModulesDir/node_modules/kotlin/kotlin.js"></script>
52+
<script src="$node.nodeModulesDir/node_modules/kotlin-test/kotlin-test.js"></script>
53+
<script src="$compileKotlin2Js.outputFile"></script>
54+
<script src="$compileTestKotlin2Js.outputFile"></script>
55+
<script>mocha.run();</script>
56+
</body>
57+
</html>
58+
"""
7559
}
7660

7761
task testMochaChrome(type: NodeTask, dependsOn: prepareMochaChrome) {
78-
script = file('node_modules/mocha-headless-chrome/bin/start')
79-
args = [compileTestKotlin2Js.outputFile, '--file', "$buildDir/test-page.html"]
62+
script = file("$node.nodeModulesDir/node_modules/mocha-headless-chrome/bin/start")
63+
args = [compileTestKotlin2Js.outputFile, '--file', mochaChromeTestPage]
8064
if (project.hasProperty("teamcity")) args += ['--reporter', 'mocha-teamcity-reporter']
8165
}
8266

8367
// todo: Commented out because mocha-headless-chrome does not work on TeamCity
8468
//test.dependsOn testMochaChrome
8569

86-
// -- Remove node_modules on clean
87-
88-
task deleteNodeModules(type: Delete) {
89-
delete 'node_modules'
90-
}
91-
92-
clean.dependsOn deleteNodeModules

0 commit comments

Comments
 (0)