Skip to content

Commit

Permalink
chore: make sure to test prettier 3 also on configuration parts
Browse files Browse the repository at this point in the history
  • Loading branch information
simschla committed Jul 18, 2023
1 parent 97e6b60 commit d475ea1
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ public class PrettierFormatterStep {

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

public static final String DEFAULT_VERSION = "2.8.8";

public static final Map<String, String> defaultDevDependencies() {
return defaultDevDependenciesWithPrettier("2.8.8");
return defaultDevDependenciesWithPrettier(DEFAULT_VERSION);
}

public static final Map<String, String> defaultDevDependenciesWithPrettier(String version) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
parser: typescript
printWidth: 50
printWidth: 20
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export class MyVeryOwnControllerWithARatherLongNameThatIsNotReallyNecessary
extends AbstractController
implements
DisposeAware,
CallbackAware
{
public myValue: string[];

constructor(
private myService: Service,
name: string,
private field: any
) {
super(name);
}

//...
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export class MyVeryOwnControllerWithARatherLongNameThatIsNotReallyNecessary
extends AbstractController
implements
DisposeAware,
CallbackAware
{
public myValue: string[];

constructor(
private myService: Service,
name: string,
private field: any,
) {
super(name);
}

//...
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export class MyVeryOwnControllerWithARatherLongNameThatIsNotReallyNecessary
constructor(
private myService: Service,
name: string,
private field: any
private field: any,
) {
super(name);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export class MyVeryOwnControllerWithARatherLongNameThatIsNotReallyNecessary extends AbstractController implements DisposeAware, CallbackAware {
public myValue: string[];

constructor(
private myService: Service,
name: string,
private field: any,
) {
super(name);
}

//...
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
@NpmTest
class PrettierFormatterStepTest extends ResourceHarness {

private static final String PRETTIER_VERSION_2 = PrettierFormatterStep.DEFAULT_VERSION;

private static final String PRETTIER_VERSION_3 = "3.0.0";

@NpmTest
@Nested
class PrettierFormattingOfFileTypesIsWorking extends NpmFormatterStepCommonTests {
Expand Down Expand Up @@ -77,15 +81,16 @@ private void runTestUsingPrettier(String fileType, Map<String, String> dependenc
@Nested
class SpecificPrettierFormatterStepTests extends NpmFormatterStepCommonTests {

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

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

final FormatterStep formatterStep = PrettierFormatterStep.create(
PrettierFormatterStep.defaultDevDependencies(),
ImmutableMap.of("prettier", prettierVersion),
TestProvisioner.mavenCentral(),
projectDir(),
buildDir(),
Expand All @@ -98,15 +103,16 @@ void parserInferenceBasedOnExplicitFilepathIsWorking() throws Exception {
}
}

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

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

final FormatterStep formatterStep = PrettierFormatterStep.create(
PrettierFormatterStep.defaultDevDependencies(),
ImmutableMap.of("prettier", prettierVersion),
TestProvisioner.mavenCentral(),
projectDir(),
buildDir(),
Expand Down Expand Up @@ -142,13 +148,13 @@ class PrettierFormattingOptionsAreWorking extends NpmFormatterStepCommonTests {

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

void runFormatTest(PrettierConfig config, String cleanFileNameSuffix) throws Exception {
void runFormatTest(String prettierVersion, PrettierConfig config, String cleanFileNameSuffix) throws Exception {

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

final FormatterStep formatterStep = PrettierFormatterStep.create(
PrettierFormatterStep.defaultDevDependencies(),
ImmutableMap.of("prettier", prettierVersion),
TestProvisioner.mavenCentral(),
projectDir(),
buildDir(),
Expand All @@ -161,20 +167,26 @@ void runFormatTest(PrettierConfig config, String cleanFileNameSuffix) throws Exc
}
}

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

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

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

private String major(String semVer) {
return semVer.split("\\.")[0];
}
}
}

0 comments on commit d475ea1

Please sign in to comment.