Skip to content

Commit 78b5108

Browse files
committed
Test prettier's equality checks.
1 parent f63d909 commit 78b5108

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2023 DiffPlug
2+
* Copyright 2016-2024 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,10 +16,10 @@
1616
package com.diffplug.spotless.npm;
1717

1818
import java.io.File;
19-
import java.io.IOException;
2019
import java.util.Collections;
2120

2221
import com.diffplug.spotless.ResourceHarness;
22+
import com.diffplug.spotless.ThrowingEx;
2323

2424
public abstract class NpmFormatterStepCommonTests extends ResourceHarness {
2525

@@ -41,18 +41,18 @@ private File npmrc() {
4141

4242
private File buildDir = null;
4343

44-
protected File buildDir() throws IOException {
44+
protected File buildDir() {
4545
if (this.buildDir == null) {
46-
this.buildDir = newFolder("build-dir");
46+
this.buildDir = ThrowingEx.get(() -> newFolder("build-dir"));
4747
}
4848
return this.buildDir;
4949
}
5050

5151
private File projectDir = null;
5252

53-
protected File projectDir() throws IOException {
53+
protected File projectDir() {
5454
if (this.projectDir == null) {
55-
this.projectDir = newFolder("project-dir");
55+
this.projectDir = ThrowingEx.get(() -> newFolder("project-dir"));
5656
}
5757
return this.projectDir;
5858
}

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2023 DiffPlug
2+
* Copyright 2016-2024 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,24 +19,21 @@
1919
import java.util.Collections;
2020
import java.util.Map;
2121

22-
import com.diffplug.spotless.SerializableEqualityTester;
23-
import com.diffplug.spotless.java.GoogleJavaFormatStep;
24-
2522
import org.junit.jupiter.api.Nested;
2623
import org.junit.jupiter.api.Test;
2724
import org.junit.jupiter.params.ParameterizedTest;
2825
import org.junit.jupiter.params.provider.ValueSource;
2926

3027
import com.diffplug.common.collect.ImmutableMap;
3128
import com.diffplug.spotless.FormatterStep;
32-
import com.diffplug.spotless.ResourceHarness;
29+
import com.diffplug.spotless.SerializableEqualityTester;
3330
import com.diffplug.spotless.StepHarness;
3431
import com.diffplug.spotless.StepHarnessWithFile;
3532
import com.diffplug.spotless.TestProvisioner;
3633
import com.diffplug.spotless.tag.NpmTest;
3734

3835
@NpmTest
39-
class PrettierFormatterStepTest extends ResourceHarness {
36+
class PrettierFormatterStepTest extends NpmFormatterStepCommonTests {
4037

4138
private static final String PRETTIER_VERSION_2 = PrettierFormatterStep.DEFAULT_VERSION;
4239

@@ -196,27 +193,30 @@ private String major(String semVer) {
196193
@Test
197194
void equality() {
198195
new SerializableEqualityTester() {
199-
String groupArtifact = GoogleJavaFormatStep.defaultGroupArtifact();
200-
String version = "1.11.0";
201-
String style = "";
202-
boolean reflowLongStrings = false;
196+
String prettierVersion = "3.0.0";
197+
PrettierConfig config = new PrettierConfig(null, Map.of("parser", "typescript"));
203198

204199
@Override
205200
protected void setupTest(API api) {
206201
// same version == same
207202
api.areDifferentThan();
208203
// change the groupArtifact, and it's different
209-
groupArtifact = "io.opil:google-java-format";
204+
prettierVersion = "2.8.8";
205+
api.areDifferentThan();
206+
config = new PrettierConfig(null, Map.of("parser", "css"));
210207
api.areDifferentThan();
211208
}
212209

213210
@Override
214211
protected FormatterStep create() {
215-
return PrettierFormatterStep.create(Map.of(), TestProvisioner.mavenCentral(), projectDir(),
216-
buildDir(),
217-
null,
218-
npmPathResolver(),
219-
);
212+
return PrettierFormatterStep.create(
213+
ImmutableMap.of("prettier", prettierVersion),
214+
TestProvisioner.mavenCentral(),
215+
projectDir(),
216+
buildDir(),
217+
null,
218+
npmPathResolver(),
219+
config); // should select parser based on this name
220220
}
221221
}.testEquals();
222222
}

0 commit comments

Comments
 (0)