22
22
class NpmTestsWithoutNpmInstallationTest extends GradleIntegrationHarness {
23
23
24
24
@ Test
25
- void useNodeFromNodeGradlePlugin () throws Exception {
25
+ void useNodeAndNpmFromNodeGradlePlugin () throws Exception {
26
26
setFile ("build.gradle" ).toLines (
27
27
"plugins {" ,
28
28
" id 'com.diffplug.spotless'" ,
@@ -39,12 +39,48 @@ void useNodeFromNodeGradlePlugin() throws Exception {
39
39
"def prettierConfig = [:]" ,
40
40
"prettierConfig['printWidth'] = 50" ,
41
41
"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' : ''" ,
42
44
"spotless {" ,
43
45
" format 'mytypescript', {" ,
44
46
" target 'test.ts'" ,
45
47
" 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}\" )" ,
48
84
" .config(prettierConfig)" ,
49
85
" }" ,
50
86
"}" );
0 commit comments