Skip to content

Commit

Permalink
Issue #39: add a test to ensure that we can use the lazy configuratio…
Browse files Browse the repository at this point in the history
…n API with all tasks.
  • Loading branch information
bsautel committed Apr 6, 2020
1 parent e5c6f10 commit 36ffe6b
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 24 deletions.
40 changes: 31 additions & 9 deletions src/test/groovy/com/github/gradle/node/KotlinDsl_integTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import org.gradle.testkit.runner.TaskOutcome
import org.junit.Rule
import org.junit.contrib.java.lang.system.EnvironmentVariables

import java.util.zip.ZipFile

class KotlinDsl_integTest extends AbstractIntegTest {
@Rule
EnvironmentVariables environmentVariables = new EnvironmentVariables()
Expand All @@ -15,16 +17,36 @@ class KotlinDsl_integTest extends AbstractIntegTest {
copyResources('fixtures/javascript-project/', '')

when:
def result = build("run")
def result1 = build("run")

then:
result1.task(":nodeSetup").outcome == TaskOutcome.SKIPPED
result1.task(":npmSetup").outcome == TaskOutcome.SKIPPED
result1.task(":yarnSetup").outcome == TaskOutcome.SUCCESS
result1.task(":npmInstall").outcome == TaskOutcome.SUCCESS
result1.task(":testNpx").outcome == TaskOutcome.SUCCESS
result1.task(":testNpm").outcome == TaskOutcome.SUCCESS
result1.task(":testYarn").outcome == TaskOutcome.SUCCESS
result1.task(":run").outcome == TaskOutcome.SUCCESS
result1.output.contains("Hello Bobby!")

when:
def result2 = build("package")

then:
result.task(":nodeSetup").outcome == TaskOutcome.SKIPPED
result.task(":npmSetup").outcome == TaskOutcome.SKIPPED
result.task(":npmInstall").outcome == TaskOutcome.SUCCESS
result.task(":testNpx").outcome == TaskOutcome.SUCCESS
result.task(":testNpm").outcome == TaskOutcome.SUCCESS
result.task(":testYarn").outcome == TaskOutcome.SUCCESS
result.task(":run").outcome == TaskOutcome.SUCCESS
result.output.contains("Hello Bobby!")
result2.task(":nodeSetup").outcome == TaskOutcome.SKIPPED
result2.task(":npmSetup").outcome == TaskOutcome.SKIPPED
result2.task(":npmInstall").outcome == TaskOutcome.SUCCESS
result2.task(":buildNpx").outcome == TaskOutcome.SUCCESS
result2.task(":buildNpm").outcome == TaskOutcome.SUCCESS
result2.task(":buildYarn").outcome == TaskOutcome.SUCCESS
result2.task(":package").outcome == TaskOutcome.SUCCESS
def outputFile = createFile("build/app.zip")
outputFile.exists()
def zipFile = new ZipFile(outputFile)
def zipFileEntries = Collections.list(zipFile.entries())
zipFileEntries.findAll { it.name.equals("index.js") }.size() == 3
zipFileEntries.findAll { it.name.equals("main.js") }.size() == 3
zipFileEntries.size() == 6
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class NpxTask_integTest extends AbstractIntegTest {
result1.task(":npmInstall").outcome == TaskOutcome.SUCCESS
result1.task(":lint").outcome == TaskOutcome.SUCCESS
result1.task(":test").outcome == TaskOutcome.SUCCESS
result1.output.contains("3 problems (0 errors, 3 warnings)")
result1.output.contains("5 problems (0 errors, 5 warnings)")
result1.output.contains("1 passing")

when:
Expand Down
6 changes: 6 additions & 0 deletions src/test/resources/fixtures/javascript-project/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
"mocha": "6.2.0",
"chai": "4.2.0"
},
"devDependencies": {
"@babel/cli": "^7.0.0",
"@babel/core": "^7.0.0"
},
"scripts": {
"buildNpm": "babel src --out-dir build/npm-output",
"build": "babel src",
"test": "mocha"
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const hello = require('./');
const hello = require('../src');
const sayHello = hello.sayHello;
const chai = require('chai');
const expect = chai.expect;
Expand Down
45 changes: 40 additions & 5 deletions src/test/resources/fixtures/kotlin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ val testTaskUsingNpx = tasks.register<NpxTask>("testNpx") {
}
inputs.dir("node_modules")
inputs.file("package.json")
inputs.files("index.js", "test.js")
inputs.dir("src")
inputs.dir("test")
outputs.upToDateWhen {
true
}
Expand All @@ -52,7 +53,8 @@ val testTaskUsingNpm = tasks.register<NpmTask>("testNpm") {
}
inputs.dir("node_modules")
inputs.file("package.json")
inputs.files("index.js", "test.js")
inputs.dir("src")
inputs.dir("test")
outputs.upToDateWhen {
true
}
Expand All @@ -69,24 +71,57 @@ val testTaskUsingYarn = tasks.register<YarnTask>("testYarn") {
}
inputs.dir("node_modules")
inputs.file("package.json")
inputs.files("index.js", "test.js")
inputs.dir("src")
inputs.dir("test")
outputs.upToDateWhen {
true
}
}

tasks.register<NodeTask>("run") {
dependsOn(testTaskUsingNpx, testTaskUsingNpm, testTaskUsingYarn)
script = file("main.js")
script = file("src/main.js")
args = listOf("Bobby")
ignoreExitValue = false
environment = mapOf("MY_CUSTOM_VARIABLE" to "hello")
workingDir = file("./")
execOverrides = {
standardOutput = System.out
}
inputs.files("index.js", "main.js")
inputs.dir("src")
outputs.upToDateWhen {
false
}
}

val buildTaskUsingNpx = tasks.register<NpxTask>("buildNpx") {
dependsOn(npmInstallTask)
command = "babel"
args = listOf("src", "--out-dir", "${buildDir}/npx-output")
inputs.dir("src")
outputs.dir("${buildDir}/npx-output")
}

val buildTaskUsingNpm = tasks.register<NpmTask>("buildNpm") {
dependsOn(npmInstallTask)
// For some reason the --out-dir parameter is not passed to babel, so we use a dedicated command
npmCommand = listOf("run", "buildNpm")
args = listOf()
inputs.dir("src")
outputs.dir("${buildDir}/npm-output")
}

val buildTaskUsingYarn = tasks.register<YarnTask>("buildYarn") {
dependsOn(npmInstallTask)
yarnCommand = listOf("run", "build")
args = listOf("--out-dir", "${buildDir}/yarn-output")
inputs.dir("src")
outputs.dir("${buildDir}/yarn-output")
}

tasks.register<Zip>("package") {
// Using old deprecated properties to get it work with Gradle 5.0
archiveName = "app.zip"
destinationDir = buildDir
from(buildTaskUsingNpx, buildTaskUsingNpm, buildTaskUsingYarn)
}
4 changes: 2 additions & 2 deletions src/test/resources/fixtures/npm/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ task test(type: NpmTask) {
dependsOn npmInstall
npmCommand = changeInputs ? ['run', 'test'] : ['run']
args = changeInputs ? [] : ['test']
inputs.dir('node_modules')
inputs.file('package.json')
inputs.files('index.js', 'test.js')
inputs.dir('src')
inputs.dir('test')
outputs.upToDateWhen {
true
}
Expand Down
12 changes: 7 additions & 5 deletions src/test/resources/fixtures/npx/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ node {
task lint(type: NpxTask) {
dependsOn npmInstall
command = "[email protected]"
args = ["index.js", "test.js"]
inputs.files(".eslintrc.yml", "index.js")
args = ["src", "test"]
inputs.file(".eslintrc.yml")
inputs.dir("src")
inputs.dir("test")
outputs.upToDateWhen {
true
}
Expand All @@ -23,9 +25,9 @@ task lint(type: NpxTask) {
task test(type: NpxTask) {
dependsOn lint
command = "mocha"
inputs.dir("node_modules")
inputs.file("package.json")
inputs.files("index.js", "test.js")
inputs.dir("src")
inputs.dir("test")
outputs.upToDateWhen {
true
}
Expand All @@ -51,7 +53,7 @@ task version(type: NpxTask) {
}

if (isPropertyEnabled("changeInputs")) {
lint.args = ["index.js"]
lint.args = ["src"]
test.command = "_mocha"
}

Expand Down
3 changes: 2 additions & 1 deletion src/test/resources/fixtures/yarn/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ task test(type: YarnTask) {
args = changeInputs ? [] : ["test"]
inputs.dir("node_modules")
inputs.file("package.json")
inputs.files("index.js", "test.js")
inputs.dir("src")
inputs.dir("test")
outputs.upToDateWhen {
true
}
Expand Down

0 comments on commit 36ffe6b

Please sign in to comment.