Skip to content

Commit 3d8e3e0

Browse files
committed
integration tests for prettier formatter
1 parent 276c5a7 commit 3d8e3e0

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright 2016 DiffPlug
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.diffplug.gradle.spotless;
17+
18+
import java.io.File;
19+
import java.io.IOException;
20+
21+
import org.junit.Test;
22+
import org.junit.experimental.categories.Category;
23+
24+
@Category(NpmTest.class)
25+
public class PrettierIntegrationTest extends GradleIntegrationTest {
26+
@Test
27+
public void useInlineConfig() throws IOException {
28+
setFile("build.gradle").toLines(
29+
"buildscript { repositories { mavenCentral() } }",
30+
"plugins {",
31+
" id 'com.diffplug.gradle.spotless'",
32+
"}",
33+
"def prettierConfig = [:]",
34+
"prettierConfig['printWidth'] = 50",
35+
"prettierConfig['parser'] = 'typescript'",
36+
"spotless {",
37+
" format 'mytypescript', {",
38+
" target 'test.ts'",
39+
" prettier().config(prettierConfig)",
40+
" }",
41+
"}");
42+
setFile("test.ts").toResource("npm/prettier/config/typescript.dirty");
43+
gradleRunner().withArguments("spotlessApply").build();
44+
assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile.clean");
45+
}
46+
47+
@Test
48+
public void useFileConfig() throws IOException {
49+
File formattingFile = setFile(".prettierrc.yml").toResource("npm/prettier/config/.prettierrc.yml");
50+
setFile("build.gradle").toLines(
51+
"buildscript { repositories { mavenCentral() } }",
52+
"plugins {",
53+
" id 'com.diffplug.gradle.spotless'",
54+
"}",
55+
"spotless {",
56+
" format 'mytypescript', {",
57+
" target 'test.ts'",
58+
" prettier().configFile('" + formattingFile.getAbsolutePath() + "')",
59+
" }",
60+
"}");
61+
setFile("test.ts").toResource("npm/prettier/config/typescript.dirty");
62+
gradleRunner().withArguments("spotlessApply").build();
63+
assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile.clean");
64+
}
65+
66+
}

0 commit comments

Comments
 (0)