|
17 | 17 |
|
18 | 18 | import org.assertj.core.api.Assertions;
|
19 | 19 | import org.gradle.testkit.runner.BuildResult;
|
| 20 | +import org.junit.jupiter.api.Disabled; |
20 | 21 | import org.junit.jupiter.api.Test;
|
21 | 22 |
|
22 | 23 | class NpmTestsWithoutNpmInstallationTest extends GradleIntegrationHarness {
|
@@ -59,6 +60,46 @@ void useNodeAndNpmFromNodeGradlePlugin() throws Exception {
|
59 | 60 | assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile.clean");
|
60 | 61 | }
|
61 | 62 |
|
| 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 | + |
62 | 103 | @Test
|
63 | 104 | void useNpmFromNodeGradlePlugin() throws Exception {
|
64 | 105 | setFile("build.gradle").toLines(
|
|
0 commit comments