Skip to content

Commit 36ffe6b

Browse files
committed
Issue #39: add a test to ensure that we can use the lazy configuration API with all tasks.
1 parent e5c6f10 commit 36ffe6b

File tree

10 files changed

+90
-24
lines changed

10 files changed

+90
-24
lines changed

src/test/groovy/com/github/gradle/node/KotlinDsl_integTest.groovy

+31-9
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import org.gradle.testkit.runner.TaskOutcome
55
import org.junit.Rule
66
import org.junit.contrib.java.lang.system.EnvironmentVariables
77

8+
import java.util.zip.ZipFile
9+
810
class KotlinDsl_integTest extends AbstractIntegTest {
911
@Rule
1012
EnvironmentVariables environmentVariables = new EnvironmentVariables()
@@ -15,16 +17,36 @@ class KotlinDsl_integTest extends AbstractIntegTest {
1517
copyResources('fixtures/javascript-project/', '')
1618

1719
when:
18-
def result = build("run")
20+
def result1 = build("run")
21+
22+
then:
23+
result1.task(":nodeSetup").outcome == TaskOutcome.SKIPPED
24+
result1.task(":npmSetup").outcome == TaskOutcome.SKIPPED
25+
result1.task(":yarnSetup").outcome == TaskOutcome.SUCCESS
26+
result1.task(":npmInstall").outcome == TaskOutcome.SUCCESS
27+
result1.task(":testNpx").outcome == TaskOutcome.SUCCESS
28+
result1.task(":testNpm").outcome == TaskOutcome.SUCCESS
29+
result1.task(":testYarn").outcome == TaskOutcome.SUCCESS
30+
result1.task(":run").outcome == TaskOutcome.SUCCESS
31+
result1.output.contains("Hello Bobby!")
32+
33+
when:
34+
def result2 = build("package")
1935

2036
then:
21-
result.task(":nodeSetup").outcome == TaskOutcome.SKIPPED
22-
result.task(":npmSetup").outcome == TaskOutcome.SKIPPED
23-
result.task(":npmInstall").outcome == TaskOutcome.SUCCESS
24-
result.task(":testNpx").outcome == TaskOutcome.SUCCESS
25-
result.task(":testNpm").outcome == TaskOutcome.SUCCESS
26-
result.task(":testYarn").outcome == TaskOutcome.SUCCESS
27-
result.task(":run").outcome == TaskOutcome.SUCCESS
28-
result.output.contains("Hello Bobby!")
37+
result2.task(":nodeSetup").outcome == TaskOutcome.SKIPPED
38+
result2.task(":npmSetup").outcome == TaskOutcome.SKIPPED
39+
result2.task(":npmInstall").outcome == TaskOutcome.SUCCESS
40+
result2.task(":buildNpx").outcome == TaskOutcome.SUCCESS
41+
result2.task(":buildNpm").outcome == TaskOutcome.SUCCESS
42+
result2.task(":buildYarn").outcome == TaskOutcome.SUCCESS
43+
result2.task(":package").outcome == TaskOutcome.SUCCESS
44+
def outputFile = createFile("build/app.zip")
45+
outputFile.exists()
46+
def zipFile = new ZipFile(outputFile)
47+
def zipFileEntries = Collections.list(zipFile.entries())
48+
zipFileEntries.findAll { it.name.equals("index.js") }.size() == 3
49+
zipFileEntries.findAll { it.name.equals("main.js") }.size() == 3
50+
zipFileEntries.size() == 6
2951
}
3052
}

src/test/groovy/com/github/gradle/node/npm/task/NpxTask_integTest.groovy

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class NpxTask_integTest extends AbstractIntegTest {
4646
result1.task(":npmInstall").outcome == TaskOutcome.SUCCESS
4747
result1.task(":lint").outcome == TaskOutcome.SUCCESS
4848
result1.task(":test").outcome == TaskOutcome.SUCCESS
49-
result1.output.contains("3 problems (0 errors, 3 warnings)")
49+
result1.output.contains("5 problems (0 errors, 5 warnings)")
5050
result1.output.contains("1 passing")
5151

5252
when:

src/test/resources/fixtures/javascript-project/package.json

+6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@
44
"mocha": "6.2.0",
55
"chai": "4.2.0"
66
},
7+
"devDependencies": {
8+
"@babel/cli": "^7.0.0",
9+
"@babel/core": "^7.0.0"
10+
},
711
"scripts": {
12+
"buildNpm": "babel src --out-dir build/npm-output",
13+
"build": "babel src",
814
"test": "mocha"
915
}
1016
}

src/test/resources/fixtures/javascript-project/test.js renamed to src/test/resources/fixtures/javascript-project/test/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const hello = require('./');
1+
const hello = require('../src');
22
const sayHello = hello.sayHello;
33
const chai = require('chai');
44
const expect = chai.expect;

src/test/resources/fixtures/kotlin/build.gradle.kts

+40-5
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ val testTaskUsingNpx = tasks.register<NpxTask>("testNpx") {
3535
}
3636
inputs.dir("node_modules")
3737
inputs.file("package.json")
38-
inputs.files("index.js", "test.js")
38+
inputs.dir("src")
39+
inputs.dir("test")
3940
outputs.upToDateWhen {
4041
true
4142
}
@@ -52,7 +53,8 @@ val testTaskUsingNpm = tasks.register<NpmTask>("testNpm") {
5253
}
5354
inputs.dir("node_modules")
5455
inputs.file("package.json")
55-
inputs.files("index.js", "test.js")
56+
inputs.dir("src")
57+
inputs.dir("test")
5658
outputs.upToDateWhen {
5759
true
5860
}
@@ -69,24 +71,57 @@ val testTaskUsingYarn = tasks.register<YarnTask>("testYarn") {
6971
}
7072
inputs.dir("node_modules")
7173
inputs.file("package.json")
72-
inputs.files("index.js", "test.js")
74+
inputs.dir("src")
75+
inputs.dir("test")
7376
outputs.upToDateWhen {
7477
true
7578
}
7679
}
7780

7881
tasks.register<NodeTask>("run") {
7982
dependsOn(testTaskUsingNpx, testTaskUsingNpm, testTaskUsingYarn)
80-
script = file("main.js")
83+
script = file("src/main.js")
8184
args = listOf("Bobby")
8285
ignoreExitValue = false
8386
environment = mapOf("MY_CUSTOM_VARIABLE" to "hello")
8487
workingDir = file("./")
8588
execOverrides = {
8689
standardOutput = System.out
8790
}
88-
inputs.files("index.js", "main.js")
91+
inputs.dir("src")
8992
outputs.upToDateWhen {
9093
false
9194
}
9295
}
96+
97+
val buildTaskUsingNpx = tasks.register<NpxTask>("buildNpx") {
98+
dependsOn(npmInstallTask)
99+
command = "babel"
100+
args = listOf("src", "--out-dir", "${buildDir}/npx-output")
101+
inputs.dir("src")
102+
outputs.dir("${buildDir}/npx-output")
103+
}
104+
105+
val buildTaskUsingNpm = tasks.register<NpmTask>("buildNpm") {
106+
dependsOn(npmInstallTask)
107+
// For some reason the --out-dir parameter is not passed to babel, so we use a dedicated command
108+
npmCommand = listOf("run", "buildNpm")
109+
args = listOf()
110+
inputs.dir("src")
111+
outputs.dir("${buildDir}/npm-output")
112+
}
113+
114+
val buildTaskUsingYarn = tasks.register<YarnTask>("buildYarn") {
115+
dependsOn(npmInstallTask)
116+
yarnCommand = listOf("run", "build")
117+
args = listOf("--out-dir", "${buildDir}/yarn-output")
118+
inputs.dir("src")
119+
outputs.dir("${buildDir}/yarn-output")
120+
}
121+
122+
tasks.register<Zip>("package") {
123+
// Using old deprecated properties to get it work with Gradle 5.0
124+
archiveName = "app.zip"
125+
destinationDir = buildDir
126+
from(buildTaskUsingNpx, buildTaskUsingNpm, buildTaskUsingYarn)
127+
}

src/test/resources/fixtures/npm/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ task test(type: NpmTask) {
1414
dependsOn npmInstall
1515
npmCommand = changeInputs ? ['run', 'test'] : ['run']
1616
args = changeInputs ? [] : ['test']
17-
inputs.dir('node_modules')
1817
inputs.file('package.json')
19-
inputs.files('index.js', 'test.js')
18+
inputs.dir('src')
19+
inputs.dir('test')
2020
outputs.upToDateWhen {
2121
true
2222
}

src/test/resources/fixtures/npx/build.gradle

+7-5
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ node {
1313
task lint(type: NpxTask) {
1414
dependsOn npmInstall
1515
command = "[email protected]"
16-
args = ["index.js", "test.js"]
17-
inputs.files(".eslintrc.yml", "index.js")
16+
args = ["src", "test"]
17+
inputs.file(".eslintrc.yml")
18+
inputs.dir("src")
19+
inputs.dir("test")
1820
outputs.upToDateWhen {
1921
true
2022
}
@@ -23,9 +25,9 @@ task lint(type: NpxTask) {
2325
task test(type: NpxTask) {
2426
dependsOn lint
2527
command = "mocha"
26-
inputs.dir("node_modules")
2728
inputs.file("package.json")
28-
inputs.files("index.js", "test.js")
29+
inputs.dir("src")
30+
inputs.dir("test")
2931
outputs.upToDateWhen {
3032
true
3133
}
@@ -51,7 +53,7 @@ task version(type: NpxTask) {
5153
}
5254

5355
if (isPropertyEnabled("changeInputs")) {
54-
lint.args = ["index.js"]
56+
lint.args = ["src"]
5557
test.command = "_mocha"
5658
}
5759

src/test/resources/fixtures/yarn/build.gradle

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ task test(type: YarnTask) {
1616
args = changeInputs ? [] : ["test"]
1717
inputs.dir("node_modules")
1818
inputs.file("package.json")
19-
inputs.files("index.js", "test.js")
19+
inputs.dir("src")
20+
inputs.dir("test")
2021
outputs.upToDateWhen {
2122
true
2223
}

0 commit comments

Comments
 (0)