Skip to content

Commit

Permalink
integration tests for prettier formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
simschla committed Sep 6, 2018
1 parent 45167b7 commit 7b96736
Showing 1 changed file with 66 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright 2016 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.diffplug.gradle.spotless;

import java.io.File;
import java.io.IOException;

import org.junit.Test;
import org.junit.experimental.categories.Category;

@Category(NpmTest.class)
public class PrettierIntegrationTest extends GradleIntegrationTest {
@Test
public void useInlineConfig() throws IOException {
setFile("build.gradle").toLines(
"buildscript { repositories { mavenCentral() } }",
"plugins {",
" id 'com.diffplug.gradle.spotless'",
"}",
"def prettierConfig = [:]",
"prettierConfig['printWidth'] = 50",
"prettierConfig['parser'] = 'typescript'",
"spotless {",
" format 'mytypescript', {",
" target 'test.ts'",
" prettier().config(prettierConfig)",
" }",
"}");
setFile("test.ts").toResource("npm/prettier/config/typescript.dirty");
gradleRunner().withArguments("--stacktrace", "spotlessApply").build();
assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile.clean");
}

@Test
public void useFileConfig() throws IOException {
File formattingFile = setFile(".prettierrc.yml").toResource("npm/prettier/config/.prettierrc.yml");
setFile("build.gradle").toLines(
"buildscript { repositories { mavenCentral() } }",
"plugins {",
" id 'com.diffplug.gradle.spotless'",
"}",
"spotless {",
" format 'mytypescript', {",
" target 'test.ts'",
" prettier().configFile('" + formattingFile.getAbsolutePath() + "')",
" }",
"}");
setFile("test.ts").toResource("npm/prettier/config/typescript.dirty");
gradleRunner().withArguments("--stacktrace", "spotlessApply").build();
assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile.clean");
}

}

0 comments on commit 7b96736

Please sign in to comment.