|
24 | 24 | import org.assertj.core.api.Assertions;
|
25 | 25 | import org.gradle.testkit.runner.BuildResult;
|
26 | 26 | import org.junit.jupiter.api.BeforeAll;
|
| 27 | +import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; |
27 | 28 | import org.junit.jupiter.api.Order;
|
28 | 29 | import org.junit.jupiter.api.Test;
|
| 30 | +import org.junit.jupiter.api.TestMethodOrder; |
29 | 31 | import org.junit.jupiter.api.io.TempDir;
|
30 | 32 |
|
31 | 33 | import com.diffplug.common.base.Errors;
|
32 | 34 | import com.diffplug.spotless.tag.NpmTest;
|
33 | 35 |
|
| 36 | +@TestMethodOrder(OrderAnnotation.class) |
34 | 37 | @NpmTest
|
35 | 38 | class NpmInstallCacheIntegrationTests extends GradleIntegrationHarness {
|
36 | 39 |
|
@@ -115,6 +118,51 @@ private BuildResult runPhpPrettierOnDir(File projDir, File cacheDir) throws IOEx
|
115 | 118 | return spotlessApply;
|
116 | 119 | }
|
117 | 120 |
|
| 121 | + @Test |
| 122 | + @Order(3) |
| 123 | + void tsfmtWithSpecificGlobalInstallCacheTest() throws IOException { |
| 124 | + File dir1 = newFolder("npm-tsfmt-global-1"); |
| 125 | + File cacheDir = pertainingCacheDir; |
| 126 | + BuildResult result = runTsfmtOnDir(dir1, cacheDir); |
| 127 | + Assertions.assertThat(result.getOutput()) |
| 128 | + .doesNotContainPattern("Using cached node_modules for .*\\Q" + cacheDir.getAbsolutePath() + "\\E") |
| 129 | + .containsPattern("Caching node_modules for .*\\Q" + cacheDir.getAbsolutePath() + "\\E"); |
| 130 | + } |
| 131 | + |
| 132 | + @Test |
| 133 | + @Order(4) |
| 134 | + void tsfmtWithSpecificGlobalInstallCacheTest2() throws IOException { |
| 135 | + File dir2 = newFolder("npm-tsfmt-global-2"); |
| 136 | + File cacheDir = pertainingCacheDir; |
| 137 | + BuildResult result = runTsfmtOnDir(dir2, cacheDir); |
| 138 | + Assertions.assertThat(result.getOutput()) |
| 139 | + .containsPattern("Using cached node_modules for .*\\Q" + cacheDir.getAbsolutePath() + "\\E") |
| 140 | + .doesNotContainPattern("Caching node_modules for .*\\Q" + cacheDir.getAbsolutePath() + "\\E"); |
| 141 | + } |
| 142 | + |
| 143 | + private BuildResult runTsfmtOnDir(File projDir, File cacheDir) throws IOException { |
| 144 | + String baseDir = projDir.getName(); |
| 145 | + String cacheDirEnabled = cacheDirEnabledStringForCacheDir(cacheDir); |
| 146 | + setFile(baseDir + "/build.gradle").toLines( |
| 147 | + "plugins {", |
| 148 | + " id 'com.diffplug.spotless'", |
| 149 | + "}", |
| 150 | + "repositories { mavenCentral() }", |
| 151 | + "def tsfmtconfig = [:]", |
| 152 | + "tsfmtconfig['indentSize'] = 1", |
| 153 | + "tsfmtconfig['convertTabsToSpaces'] = true", |
| 154 | + "spotless {", |
| 155 | + " typescript {", |
| 156 | + " target 'test.ts'", |
| 157 | + " tsfmt().config(tsfmtconfig)" + cacheDirEnabled, |
| 158 | + " }", |
| 159 | + "}"); |
| 160 | + setFile(baseDir + "/test.ts").toResource("npm/tsfmt/tsfmt/tsfmt.dirty"); |
| 161 | + final BuildResult spotlessApply = gradleRunner().withProjectDir(projDir).withArguments("--stacktrace", "--info", "spotlessApply").build(); |
| 162 | + assertFile(baseDir + "/test.ts").sameAsResource("npm/tsfmt/tsfmt/tsfmt.clean"); |
| 163 | + return spotlessApply; |
| 164 | + } |
| 165 | + |
118 | 166 | private static String cacheDirEnabledStringForCacheDir(File cacheDir) {
|
119 | 167 | String cacheDirEnabled;
|
120 | 168 | if (cacheDir == null) {
|
|
0 commit comments