1 |
|
2 |
|
3 | const { prepareESLint, lint } = require("../../test_utils");
|
4 |
|
5 | const engine = prepareESLint("format");
|
6 |
|
7 | describe("ES6 Formatting", () => {
|
8 | it("Gives no warning on correct code", async () => {
|
9 | const result = await lint(
|
10 | engine,
|
11 | `
|
12 | module.exports = function initJS(gulp, config, watchers) {
|
13 | const js = config.js,
|
14 | jsTasks = [];
|
15 |
|
16 | for (const name in js) {
|
17 | if (!js.hasOwnProperty(name)) {
|
18 | continue;
|
19 | }
|
20 |
|
21 | const taskName = \`js_\${name}\`;
|
22 |
|
23 | if (!compileWithWebpack(js[name])) {
|
24 | gulp.task(taskName, jsTaskES5(gulp, config, watchers, js[name]));
|
25 | watchers.add(js[name].watch || js[name].source, taskName);
|
26 | }
|
27 |
|
28 | jsTasks.push(taskName);
|
29 | }
|
30 |
|
31 | gulp.task("js", jsTasks);
|
32 |
|
33 | return ["js"];
|
34 | };
|
35 | `
|
36 | );
|
37 |
|
38 | expect(result.messages).toMatchSnapshot();
|
39 | expect(result.warningCount).toBe(0);
|
40 | expect(result.errorCount).toBe(0);
|
41 | });
|
42 |
|
43 | it("Fails on badly formatted code", async () => {
|
44 | const result = await lint(
|
45 | engine,
|
46 | `
|
47 | module.exports = function initJS(gulp, config, watchers) {
|
48 | const js = config.js,
|
49 | jsTasks = [];
|
50 |
|
51 | for (const name in js) {
|
52 | if (!js.hasOwnProperty(name)) {
|
53 | continue;
|
54 | }
|
55 |
|
56 | const taskName = \`js_\${name}\`;
|
57 |
|
58 | if (!compileWithWebpack(js[name])) {
|
59 | gulp.task(taskName, jsTaskES5(gulp, config, watchers, js[name]));
|
60 | watchers.add(js[name].watch || js[name].source, taskName);
|
61 | }
|
62 |
|
63 | jsTasks.push( taskName );
|
64 | }
|
65 |
|
66 | gulp.task("js", jsTasks);
|
67 |
|
68 | return ["js"];
|
69 | };
|
70 | `
|
71 | );
|
72 |
|
73 | expect(result.messages).toMatchSnapshot();
|
74 | expect(result.warningCount).toBe(0);
|
75 | expect(result.errorCount).toBe(4);
|
76 | });
|
77 | });
|