UNPKG

1.82 kBJavaScriptView Raw
1/* global describe, it, expect */
2
3const { prepareESLint, lint } = require("../../test_utils");
4
5const engine = prepareESLint("recommended", "node");
6
7it("Doesn't warn on console.log", async () => {
8 const result = await lint(engine, `console.log("Yeah");\n`);
9
10 expect(result.messages).toEqual([], "no messages");
11 expect(result.warningCount).toBe(0, "no warnings");
12 expect(result.errorCount).toBe(0, "no errors");
13});
14
15it("Works with ES6", async () => {
16 const result = await lint(
17 engine,
18 `
19const something = [];
20
21something.push("a value");
22
23console.log(something);
24`
25 );
26
27 expect(result.messages).toEqual([], "no messages");
28 expect(result.warningCount).toBe(0, "no warnings");
29 expect(result.errorCount).toBe(0, "no errors");
30});
31
32it("Works with TypeScript", async () => {
33 const result = await lint(
34 engine,
35 `
36import useSWROrig from "swr";
37
38export type UnPromisify<T> = T extends Promise<infer U> ? U : T;
39
40export function obviousString(): string {
41 const myString: string = "a string";
42 console.log(myString);
43 return myString;
44}
45
46export function useSWR<T, Error = any>(
47 url
48): {
49 data?: T;
50 error?: Error;
51 revalidate: () => Promise<boolean>;
52 isValidating: boolean;
53} {
54 // Skip it on the server side.
55 if (typeof window === undefined) {
56 return {
57 async revalidate() {
58 return true;
59 },
60 isValidating: true
61 };
62 }
63
64 return useSWROrig<T, Error>(
65 url,
66 async (u): Promise<T> => {
67 const result = await fetch(u);
68
69 if (result.status == 200) {
70 return await result.json();
71 }
72
73 throw new Error(result.statusText);
74 },
75 {}
76 );
77}
78`,
79 "utils.ts"
80 );
81
82 expect(result.messages).toMatchSnapshot();
83 expect(result.warningCount).toBe(0, "no warnings");
84 expect(result.errorCount).toBe(3, "no errors");
85});