Skip to content

Commit a96d92c

Browse files
committed
add tests that verifies issue diffplug#1499
1 parent 27f9919 commit a96d92c

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java

+41
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import org.assertj.core.api.Assertions;
1919
import org.gradle.testkit.runner.BuildResult;
20+
import org.junit.jupiter.api.Disabled;
2021
import org.junit.jupiter.api.Test;
2122

2223
class NpmTestsWithoutNpmInstallationTest extends GradleIntegrationHarness {
@@ -59,6 +60,46 @@ void useNodeAndNpmFromNodeGradlePlugin() throws Exception {
5960
assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile.clean");
6061
}
6162

63+
@Test
64+
@Disabled("This test is disabled because we currently don't support using npm/node installed by the" +
65+
"node-gradle-plugin as the installation takes place in the *execution* phase, but spotless needs it in the *configuration* phase.")
66+
void useNodeAndNpmFromNodeGradlePluginInOneSweep() throws Exception {
67+
setFile("build.gradle").toLines(
68+
"plugins {",
69+
" id 'com.diffplug.spotless'",
70+
" id 'com.github.node-gradle.node' version '3.5.1'",
71+
"}",
72+
"repositories { mavenCentral() }",
73+
"node {",
74+
" download = true",
75+
" version = '18.13.0'",
76+
" npmVersion = '8.19.2'",
77+
" workDir = file(\"${buildDir}/nodejs\")",
78+
" npmWorkDir = file(\"${buildDir}/npm\")",
79+
"}",
80+
"def prettierConfig = [:]",
81+
"prettierConfig['printWidth'] = 50",
82+
"prettierConfig['parser'] = 'typescript'",
83+
"def npmExecExtension = System.getProperty('os.name').toLowerCase().contains('windows') ? '.cmd' : ''",
84+
"def nodeExecExtension = System.getProperty('os.name').toLowerCase().contains('windows') ? '.exe' : ''",
85+
"spotless {",
86+
" format 'mytypescript', {",
87+
" target 'test.ts'",
88+
" prettier()",
89+
" .npmExecutable(\"${tasks.named('npmSetup').get().npmDir.get()}/bin/npm${npmExecExtension}\")",
90+
" .nodeExecutable(\"${tasks.named('nodeSetup').get().nodeDir.get()}/bin/node${nodeExecExtension}\")",
91+
" .config(prettierConfig)",
92+
" }",
93+
"}",
94+
"tasks.named('spotlessMytypescript').configure {",
95+
" it.dependsOn('nodeSetup', 'npmSetup')",
96+
"}");
97+
setFile("test.ts").toResource("npm/prettier/config/typescript.dirty");
98+
final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build();
99+
Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL");
100+
assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile.clean");
101+
}
102+
62103
@Test
63104
void useNpmFromNodeGradlePlugin() throws Exception {
64105
setFile("build.gradle").toLines(

0 commit comments

Comments
 (0)