Skip to content

Commit e6b2268

Browse files
committed
chore: make sure to test prettier 3 also on configuration parts
1 parent bd09183 commit e6b2268

File tree

9 files changed

+83
-20
lines changed

9 files changed

+83
-20
lines changed

lib/src/main/java/com/diffplug/spotless/npm/PrettierFormatterStep.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@ public class PrettierFormatterStep {
4141

4242
public static final String NAME = "prettier-format";
4343

44+
public static final String DEFAULT_VERSION = "2.8.8";
45+
4446
public static final Map<String, String> defaultDevDependencies() {
45-
return defaultDevDependenciesWithPrettier("2.8.8");
47+
return defaultDevDependenciesWithPrettier(DEFAULT_VERSION);
4648
}
4749

4850
public static final Map<String, String> defaultDevDependenciesWithPrettier(String version) {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
parser: typescript
2-
printWidth: 50
2+
printWidth: 20
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
export class MyVeryOwnControllerWithARatherLongNameThatIsNotReallyNecessary
2+
extends AbstractController
3+
implements
4+
DisposeAware,
5+
CallbackAware
6+
{
7+
public myValue: string[];
8+
9+
constructor(
10+
private myService: Service,
11+
name: string,
12+
private field: any
13+
) {
14+
super(name);
15+
}
16+
17+
//...
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
export class MyVeryOwnControllerWithARatherLongNameThatIsNotReallyNecessary
2+
extends AbstractController
3+
implements
4+
DisposeAware,
5+
CallbackAware
6+
{
7+
public myValue: string[];
8+
9+
constructor(
10+
private myService: Service,
11+
name: string,
12+
private field: any,
13+
) {
14+
super(name);
15+
}
16+
17+
//...
18+
}

testlib/src/main/resources/npm/prettier/config/typescript.configfile.clean renamed to testlib/src/main/resources/npm/prettier/config/typescript.defaults_prettier_3.clean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export class MyVeryOwnControllerWithARatherLongNameThatIsNotReallyNecessary
77
constructor(
88
private myService: Service,
99
name: string,
10-
private field: any
10+
private field: any,
1111
) {
1212
super(name);
1313
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export class MyVeryOwnControllerWithARatherLongNameThatIsNotReallyNecessary extends AbstractController implements DisposeAware, CallbackAware {
2+
public myValue: string[];
3+
4+
constructor(
5+
private myService: Service,
6+
name: string,
7+
private field: any,
8+
) {
9+
super(name);
10+
}
11+
12+
//...
13+
}

testlib/src/test/java/com/diffplug/spotless/npm/PrettierFormatterStepTest.java

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535
@NpmTest
3636
class PrettierFormatterStepTest extends ResourceHarness {
3737

38+
private static final String PRETTIER_VERSION_2 = PrettierFormatterStep.DEFAULT_VERSION;
39+
40+
private static final String PRETTIER_VERSION_3 = "3.0.0";
41+
3842
@NpmTest
3943
@Nested
4044
class PrettierFormattingOfFileTypesIsWorking extends NpmFormatterStepCommonTests {
@@ -77,15 +81,16 @@ private void runTestUsingPrettier(String fileType, Map<String, String> dependenc
7781
@Nested
7882
class SpecificPrettierFormatterStepTests extends NpmFormatterStepCommonTests {
7983

80-
@Test
81-
void parserInferenceBasedOnExplicitFilepathIsWorking() throws Exception {
84+
@ParameterizedTest(name = "{index}: parser inference based on explicit filepath is working with prettier {0}")
85+
@ValueSource(strings = {PRETTIER_VERSION_2, PRETTIER_VERSION_3})
86+
void parserInferenceBasedOnExplicitFilepathIsWorking(String prettierVersion) throws Exception {
8287
String filedir = "npm/prettier/filetypes/json/";
8388

8489
final String dirtyFile = filedir + "json.dirty";
8590
final String cleanFile = filedir + "json.clean";
8691

8792
final FormatterStep formatterStep = PrettierFormatterStep.create(
88-
PrettierFormatterStep.defaultDevDependencies(),
93+
ImmutableMap.of("prettier", prettierVersion),
8994
TestProvisioner.mavenCentral(),
9095
projectDir(),
9196
buildDir(),
@@ -98,15 +103,16 @@ void parserInferenceBasedOnExplicitFilepathIsWorking() throws Exception {
98103
}
99104
}
100105

101-
@Test
102-
void parserInferenceBasedOnFilenameIsWorking() throws Exception {
106+
@ParameterizedTest(name = "{index}: parser inference based on filename is working with prettier {0}")
107+
@ValueSource(strings = {PRETTIER_VERSION_2, PRETTIER_VERSION_3})
108+
void parserInferenceBasedOnFilenameIsWorking(String prettierVersion) throws Exception {
103109
String filedir = "npm/prettier/filename/";
104110

105111
final String dirtyFile = filedir + "dirty.json";
106112
final String cleanFile = filedir + "clean.json";
107113

108114
final FormatterStep formatterStep = PrettierFormatterStep.create(
109-
PrettierFormatterStep.defaultDevDependencies(),
115+
ImmutableMap.of("prettier", prettierVersion),
110116
TestProvisioner.mavenCentral(),
111117
projectDir(),
112118
buildDir(),
@@ -142,13 +148,13 @@ class PrettierFormattingOptionsAreWorking extends NpmFormatterStepCommonTests {
142148

143149
private static final String FILEDIR = "npm/prettier/config/";
144150

145-
void runFormatTest(PrettierConfig config, String cleanFileNameSuffix) throws Exception {
151+
void runFormatTest(String prettierVersion, PrettierConfig config, String cleanFileNameSuffix) throws Exception {
146152

147153
final String dirtyFile = FILEDIR + "typescript.dirty";
148154
final String cleanFile = FILEDIR + "typescript." + cleanFileNameSuffix + ".clean";
149155

150156
final FormatterStep formatterStep = PrettierFormatterStep.create(
151-
PrettierFormatterStep.defaultDevDependencies(),
157+
ImmutableMap.of("prettier", prettierVersion),
152158
TestProvisioner.mavenCentral(),
153159
projectDir(),
154160
buildDir(),
@@ -161,20 +167,26 @@ void runFormatTest(PrettierConfig config, String cleanFileNameSuffix) throws Exc
161167
}
162168
}
163169

164-
@Test
165-
void defaultsAreApplied() throws Exception {
166-
runFormatTest(new PrettierConfig(null, ImmutableMap.of("parser", "typescript")), "defaults");
170+
@ParameterizedTest(name = "{index}: defaults are applied with prettier {0}")
171+
@ValueSource(strings = {PRETTIER_VERSION_2, PRETTIER_VERSION_3})
172+
void defaultsAreApplied(String prettierVersion) throws Exception {
173+
runFormatTest(prettierVersion, new PrettierConfig(null, ImmutableMap.of("parser", "typescript")), "defaults_prettier_" + major(prettierVersion));
167174
}
168175

169-
@Test
170-
void configFileOptionsAreApplied() throws Exception {
171-
runFormatTest(new PrettierConfig(createTestFile(FILEDIR + ".prettierrc.yml"), null), "configfile");
176+
@ParameterizedTest(name = "{index}: config file options are applied with prettier {0}")
177+
@ValueSource(strings = {PRETTIER_VERSION_2, PRETTIER_VERSION_3})
178+
void configFileOptionsAreApplied(String prettierVersion) throws Exception {
179+
runFormatTest(prettierVersion, new PrettierConfig(createTestFile(FILEDIR + ".prettierrc.yml"), null), "configfile_prettier_" + major(prettierVersion));
172180
}
173181

174-
@Test
175-
void configFileOptionsCanBeOverriden() throws Exception {
176-
runFormatTest(new PrettierConfig(createTestFile(FILEDIR + ".prettierrc.yml"), ImmutableMap.of("printWidth", 300)), "override");
182+
@ParameterizedTest(name = "{index}: config file options can be overriden with prettier {0}")
183+
@ValueSource(strings = {PRETTIER_VERSION_2, PRETTIER_VERSION_3})
184+
void configFileOptionsCanBeOverriden(String prettierVersion) throws Exception {
185+
runFormatTest(prettierVersion, new PrettierConfig(createTestFile(FILEDIR + ".prettierrc.yml"), ImmutableMap.of("printWidth", 300)), "override_prettier_" + major(prettierVersion));
177186
}
178187

188+
private String major(String semVer) {
189+
return semVer.split("\\.")[0];
190+
}
179191
}
180192
}

0 commit comments

Comments
 (0)