Skip to content

Commit

Permalink
test prettier configuration behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
simschla committed Aug 26, 2018
1 parent 74ddb1c commit 07a3b5c
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,43 @@ public void parserInferenceIsWorking() throws Exception {
stepHarness.testResource(dirtyFile, cleanFile);
}
}

}

@Category(NpmTest.class)
public static class PrettierFormattingOptionsAreWorking extends NpmFormatterStepCommonTests {

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

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

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

final FormatterStep formatterStep = PrettierFormatterStep.create(
TestProvisioner.mavenCentral(),
buildDir(),
npmExecutable(),
config); // should select parser based on this name

try (StepHarness stepHarness = StepHarness.forStep(formatterStep)) {
stepHarness.testResource(dirtyFile, cleanFile);
}
}

@Test
public void defaultsAreApplied() throws Exception {
runFormatTest(new PrettierConfig(null, ImmutableMap.of("parser", "typescript")), "defaults");
}

@Test
public void configFileOptionsAreApplied() throws Exception {
runFormatTest(new PrettierConfig(createTestFile(FILEDIR + ".prettierrc.yml"), null), "configfile");
}

@Test
public void configFileOptionsCanBeOverriden() throws Exception {
runFormatTest(new PrettierConfig(createTestFile(FILEDIR + ".prettierrc.yml"), ImmutableMap.of("printWidth", 300)), "override");
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
parser: typescript
printWidth: 50
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
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,11 @@
export class MyVeryOwnControllerWithARatherLongNameThatIsNotReallyNecessary
extends AbstractController
implements DisposeAware, CallbackAware {
public myValue: string[];

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

//...
}
10 changes: 10 additions & 0 deletions lib-extra/src/test/resources/npm/prettier/config/typescript.dirty
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
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,9 @@
export class MyVeryOwnControllerWithARatherLongNameThatIsNotReallyNecessary extends AbstractController implements DisposeAware, CallbackAware {
public myValue: string[];

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

//...
}

0 comments on commit 07a3b5c

Please sign in to comment.