Skip to content

Commit f4f8da7

Browse files
committed
add test for supplying only npm when binary
1 parent 4b3cb24 commit f4f8da7

File tree

1 file changed

+39
-3
lines changed

1 file changed

+39
-3
lines changed

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

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
class NpmTestsWithoutNpmInstallationTest extends GradleIntegrationHarness {
2323

2424
@Test
25-
void useNodeFromNodeGradlePlugin() throws Exception {
25+
void useNodeAndNpmFromNodeGradlePlugin() throws Exception {
2626
setFile("build.gradle").toLines(
2727
"plugins {",
2828
" id 'com.diffplug.spotless'",
@@ -39,12 +39,48 @@ void useNodeFromNodeGradlePlugin() throws Exception {
3939
"def prettierConfig = [:]",
4040
"prettierConfig['printWidth'] = 50",
4141
"prettierConfig['parser'] = 'typescript'",
42+
"def npmExecExtension = System.getProperty('os.name').toLowerCase().contains('windows') ? '.cmd' : ''",
43+
"def nodeExecExtension = System.getProperty('os.name').toLowerCase().contains('windows') ? '.exe' : ''",
4244
"spotless {",
4345
" format 'mytypescript', {",
4446
" target 'test.ts'",
4547
" prettier()",
46-
" .npmExecutable(\"${tasks.named('npmSetup').get().npmDir.get()}/bin/npm\")",
47-
" .nodeExecutable(\"${tasks.named('nodeSetup').get().nodeDir.get()}/bin/node\")",
48+
" .npmExecutable(\"${tasks.named('npmSetup').get().npmDir.get()}/bin/npm${npmExecExtension}\")",
49+
" .nodeExecutable(\"${tasks.named('nodeSetup').get().nodeDir.get()}/bin/node${nodeExecExtension}\")",
50+
" .config(prettierConfig)",
51+
" }",
52+
"}");
53+
setFile("test.ts").toResource("npm/prettier/config/typescript.dirty");
54+
// make sure node binary is there
55+
gradleRunner().withArguments("nodeSetup", "npmSetup").build();
56+
// then run spotless using that node installation
57+
final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build();
58+
Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL");
59+
assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile.clean");
60+
}
61+
62+
@Test
63+
void useNpmFromNodeGradlePlugin() throws Exception {
64+
setFile("build.gradle").toLines(
65+
"plugins {",
66+
" id 'com.diffplug.spotless'",
67+
" id 'com.github.node-gradle.node' version '3.5.1'",
68+
"}",
69+
"repositories { mavenCentral() }",
70+
"node {",
71+
" download = true",
72+
" version = '18.13.0'",
73+
" workDir = file(\"${buildDir}/nodejs\")",
74+
"}",
75+
"def prettierConfig = [:]",
76+
"prettierConfig['printWidth'] = 50",
77+
"prettierConfig['parser'] = 'typescript'",
78+
"def npmExecExtension = System.getProperty('os.name').toLowerCase().contains('windows') ? '.cmd' : ''",
79+
"spotless {",
80+
" format 'mytypescript', {",
81+
" target 'test.ts'",
82+
" prettier()",
83+
" .npmExecutable(\"${tasks.named('npmSetup').get().npmDir.get()}/bin/npm${npmExecExtension}\")",
4884
" .config(prettierConfig)",
4985
" }",
5086
"}");

0 commit comments

Comments
 (0)