Skip to content
This repository has been archived by the owner on Nov 10, 2023. It is now read-only.

Commit

Permalink
fix: test for linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Craig Bilner committed Sep 20, 2018
1 parent 7dae636 commit 6cfcc6f
Show file tree
Hide file tree
Showing 10 changed files with 2,248 additions and 1,044 deletions.
2 changes: 1 addition & 1 deletion analyse.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { test } from "ava";
import test from "ava";
import * as path from "path";
import analyse from "./analyse";

Expand Down
26 changes: 26 additions & 0 deletions bad-snaps/__snapshots__/bad-snapshots.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`1. snapshot for simple-rn-component 1`] = `
<View>
<Text
accessible={true}
allowFontScaling={true}
ellipsizeMode="tail"
ellipsizeMode="tail"
ellipsizeMode="tail"
ellipsizeMode="tail"
ellipsizeMode="tail"
ellipsizeMode="tail"
ellipsizeMode="tail"
ellipsizeMode="tail"
ellipsizeMode="tail"
ellipsizeMode="tail"
ellipsizeMode="tail"
ellipsizeMode="tail"
ellipsizeMode="tail"
ellipsizeMode="tail"
>
Hello World!
</Text>
</View>
`;
13 changes: 13 additions & 0 deletions good-snaps/__snapshots__/good-snapshots.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`1. snapshot for simple-rn-component 1`] = `
<View>
<Text
accessible={true}
allowFontScaling={true}
ellipsizeMode="tail"
>
Hello World!
</Text>
</View>
`;
2 changes: 1 addition & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ readFile(path.join(process.cwd(), ".jestlint"), "utf8")
main(process.cwd(), {
usingCI: ci,
isVerbose: verbose
});
}).catch(() => process.exit(1));
});
22 changes: 22 additions & 0 deletions main.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import test from "ava";
import * as path from "path";
import main from "./main";

test("a snapshot with no errors should resolve successfully", async t => {
console.log("running");
await t.notThrowsAsync(
main(path.join(process.cwd(), "good-snaps"), {
usingCI: true,
isVerbose: false
})
);
});

test.only("a snapshot with errors should reject", async t => {
await t.throwsAsync(
main(path.join(process.cwd(), "bad-snaps"), {
usingCI: true,
isVerbose: false
})
);
});
9 changes: 6 additions & 3 deletions main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as glob from "glob";
import * as path from "path";
import chalk from "chalk";
import analyse from "./analyse";
import report from "./report";
Expand All @@ -22,12 +23,14 @@ const getSnapshots = (cwd: Dir, snapPattern?: string) =>
console.log(chalk.yellow("No snaps were found"));
}

return res(matches);
return res(matches.map(p => path.join(cwd, p)));
}
);
});

const reportHasError = (r: Report) => r.errors.length > 0;
const reportHasError = (r: Report) =>
r.errors.length > 0 ||
r.lints.some(l => (l.error && l.error.length > 0) || l.errors.length > 0);

export default async (cwd: Dir, opts: Options) => {
const snapshots = await getSnapshots(cwd, opts.snapPattern);
Expand Down Expand Up @@ -56,6 +59,6 @@ export default async (cwd: Dir, opts: Options) => {
});

if (output.some(reportHasError)) {
process.exit(1);
throw new Error("Report has at least one error");
}
};

0 comments on commit 6cfcc6f

Please sign in to comment.