Skip to content

Commit

Permalink
Add indent & whitespace rule testing to TSX tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adidahiya committed Aug 5, 2015
1 parent 27e733e commit a839c0c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
20 changes: 19 additions & 1 deletion test/files/tsx/react.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
import * as React from 'react'; // quotemark failure

export class MyComponent extends React.Component<{}, {}> {
interface IFooProps extends React.Props<FooComponent> {
//
}

interface IFooState {
bar:string[] // whitespace failure
}

export class FooComponent extends React.Component<IFooProps, IFooState> {
public state = {
bar: [] as string[]
}

public render() {
return (
<div>
{this.state.bar.map((s) => <span>{s}</span>)}
</div>
);
} // indent failure
}
24 changes: 21 additions & 3 deletions test/tsxTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe("TSX syntax", () => {
const path = require("path");
const fileName = "react.test.tsx";

it("doesn't blow up", () => {
it("doesn't blow up linter", () => {
const validConfiguration = {};
const result = runLinterWithConfiguration(validConfiguration);
const parsedResult = JSON.parse(result.output);
Expand All @@ -28,12 +28,26 @@ describe("TSX syntax", () => {
});

it("catches common lint failures", () => {
const IndentRule = Lint.Test.getRule("indent");
const QuotemarkRule = Lint.Test.getRule("quotemark");
const WhitespaceRule = Lint.Test.getRule("whitespace");
const indentFailure = Lint.Test.createFailuresOnFile(`tsx/${fileName}`, IndentRule.FAILURE_STRING_SPACES);
const quotemarkFailure = Lint.Test.createFailuresOnFile(`tsx/${fileName}`, QuotemarkRule.DOUBLE_QUOTE_FAILURE);
const whitespaceFailure = Lint.Test.createFailuresOnFile(`tsx/${fileName}`, WhitespaceRule.FAILURE_STRING);

const result = runLinterWithConfiguration({
rules: {
"quotemark": [true, "double"]
"indent": [true, "spaces"],
"quotemark": [true, "double"],
"whitespace": [true,
"check-branch",
"check-decl",
"check-operator",
"check-module",
"check-separator",
"check-type",
"check-typecast"
]
}
});
const parsedResult = JSON.parse(result.output);
Expand All @@ -44,9 +58,13 @@ describe("TSX syntax", () => {
actualFailures.push(Lint.Test.createFailure(`tsx/${fileName}`, startArray, endArray, failure.failure));
}
const expectedFailure1 = quotemarkFailure([1, 24], [1, 31]);
const expectedFailure2 = whitespaceFailure([8, 9], [8, 10]);
const expectedFailure3 = indentFailure([22, 1], [22, 2]);

Lint.Test.assertContainsFailure(actualFailures, expectedFailure1);
assert.lengthOf(actualFailures, 1);
Lint.Test.assertContainsFailure(actualFailures, expectedFailure2);
Lint.Test.assertContainsFailure(actualFailures, expectedFailure3);
assert.lengthOf(actualFailures, 3);
});

function runLinterWithConfiguration(config: any): Lint.LintResult {
Expand Down

0 comments on commit a839c0c

Please sign in to comment.