Skip to content

Commit 64b201b

Browse files
committed
1480: adding tests without cache and for eslint
1 parent 3c4b5bc commit 64b201b

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

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

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ void prettierWithSpecificInstallCacheTest() throws IOException {
6969
Assertions.assertThat(result2.getOutput()).containsPattern("Using cached node_modules for .*\\Q" + cacheDir.getAbsolutePath() + "\\E");
7070
}
7171

72+
@Test
73+
void prettierWithNoCacheTest() throws IOException {
74+
File dir2 = newFolder("npm-prettier-1");
75+
File cacheDir = null;
76+
BuildResult result = runPhpPrettierOnDir(dir2, cacheDir);
77+
Assertions.assertThat(result.getOutput())
78+
.doesNotContainPattern("Using cached node_modules for .*")
79+
.doesNotContainPattern("Caching node_modules for .*");
80+
}
81+
7282
@Test
7383
@Order(1)
7484
void prettierWithSpecificGlobalInstallCacheTest() throws IOException {
@@ -140,6 +150,16 @@ void tsfmtWithSpecificGlobalInstallCacheTest2() throws IOException {
140150
.doesNotContainPattern("Caching node_modules for .*\\Q" + cacheDir.getAbsolutePath() + "\\E");
141151
}
142152

153+
@Test
154+
void tsfmtWithNoCacheTest() throws IOException {
155+
File dir2 = newFolder("npm-tsfmt-1");
156+
File cacheDir = null;
157+
BuildResult result = runTsfmtOnDir(dir2, cacheDir);
158+
Assertions.assertThat(result.getOutput())
159+
.doesNotContainPattern("Using cached node_modules for .*")
160+
.doesNotContainPattern("Caching node_modules for .*");
161+
}
162+
143163
private BuildResult runTsfmtOnDir(File projDir, File cacheDir) throws IOException {
144164
String baseDir = projDir.getName();
145165
String cacheDirEnabled = cacheDirEnabledStringForCacheDir(cacheDir);
@@ -163,6 +183,60 @@ private BuildResult runTsfmtOnDir(File projDir, File cacheDir) throws IOExceptio
163183
return spotlessApply;
164184
}
165185

186+
@Test
187+
@Order(5)
188+
void eslintWithSpecificGlobalInstallCacheTest() throws IOException {
189+
File dir1 = newFolder("npm-eslint-global-1");
190+
File cacheDir = pertainingCacheDir;
191+
BuildResult result = runEslintOnDir(dir1, cacheDir);
192+
Assertions.assertThat(result.getOutput())
193+
.doesNotContainPattern("Using cached node_modules for .*\\Q" + cacheDir.getAbsolutePath() + "\\E")
194+
.containsPattern("Caching node_modules for .*\\Q" + cacheDir.getAbsolutePath() + "\\E");
195+
}
196+
197+
@Test
198+
@Order(6)
199+
void eslintWithSpecificGlobalInstallCacheTest2() throws IOException {
200+
File dir2 = newFolder("npm-eslint-global-2");
201+
File cacheDir = pertainingCacheDir;
202+
BuildResult result = runEslintOnDir(dir2, cacheDir);
203+
Assertions.assertThat(result.getOutput())
204+
.containsPattern("Using cached node_modules for .*\\Q" + cacheDir.getAbsolutePath() + "\\E")
205+
.doesNotContainPattern("Caching node_modules for .*\\Q" + cacheDir.getAbsolutePath() + "\\E");
206+
}
207+
208+
@Test
209+
void eslintWithNoCacheTest() throws IOException {
210+
File dir2 = newFolder("npm-eslint-1");
211+
File cacheDir = null;
212+
BuildResult result = runEslintOnDir(dir2, cacheDir);
213+
Assertions.assertThat(result.getOutput())
214+
.doesNotContainPattern("Using cached node_modules for .*")
215+
.doesNotContainPattern("Caching node_modules for .*");
216+
}
217+
218+
private BuildResult runEslintOnDir(File projDir, File cacheDir) throws IOException {
219+
String baseDir = projDir.getName();
220+
String cacheDirEnabled = cacheDirEnabledStringForCacheDir(cacheDir);
221+
222+
setFile(baseDir + "/.eslintrc.js").toResource("npm/eslint/typescript/custom_rules/.eslintrc.js");
223+
setFile(baseDir + "/build.gradle").toLines(
224+
"plugins {",
225+
" id 'com.diffplug.spotless'",
226+
"}",
227+
"repositories { mavenCentral() }",
228+
"spotless {",
229+
" typescript {",
230+
" target 'test.ts'",
231+
" eslint().configFile('.eslintrc.js')" + cacheDirEnabled,
232+
" }",
233+
"}");
234+
setFile(baseDir + "/test.ts").toResource("npm/eslint/typescript/custom_rules/typescript.dirty");
235+
BuildResult spotlessApply = gradleRunner().withProjectDir(projDir).withArguments("--stacktrace", "--info", "spotlessApply").build();
236+
assertFile(baseDir + "/test.ts").sameAsResource("npm/eslint/typescript/custom_rules/typescript.clean");
237+
return spotlessApply;
238+
}
239+
166240
private static String cacheDirEnabledStringForCacheDir(File cacheDir) {
167241
String cacheDirEnabled;
168242
if (cacheDir == null) {

0 commit comments

Comments
 (0)