|
| 1 | +/** |
| 2 | + * @author Toru Nagashima <https://github.com/mysticatea> |
| 3 | + * @copyright 2016 Toru Nagashima. All rights reserved. |
| 4 | + * See LICENSE file in root directory for full license. |
| 5 | + */ |
| 6 | +"use strict" |
| 7 | + |
| 8 | +//------------------------------------------------------------------------------ |
| 9 | +// Requirements |
| 10 | +//------------------------------------------------------------------------------ |
| 11 | + |
| 12 | +const assert = require("assert") |
| 13 | +const path = require("path") |
| 14 | +const CLIEngine = require("eslint").CLIEngine |
| 15 | +const fs = require("fs-extra") |
| 16 | + |
| 17 | +//------------------------------------------------------------------------------ |
| 18 | +// Helpers |
| 19 | +//------------------------------------------------------------------------------ |
| 20 | + |
| 21 | +const ORIGINAL_FIXTURE_DIR = path.join(__dirname, "fixtures") |
| 22 | +const FIXTURE_DIR = path.join(__dirname, "temp") |
| 23 | +const PARSER_PATH = path.resolve(__dirname, "../index.js") |
| 24 | + |
| 25 | +//------------------------------------------------------------------------------ |
| 26 | +// Tests |
| 27 | +//------------------------------------------------------------------------------ |
| 28 | + |
| 29 | +describe("About fixtures/hello.vue", () => { |
| 30 | + beforeEach(() => { |
| 31 | + fs.copySync(ORIGINAL_FIXTURE_DIR, FIXTURE_DIR) |
| 32 | + }) |
| 33 | + afterEach(() => { |
| 34 | + fs.removeSync(FIXTURE_DIR) |
| 35 | + }) |
| 36 | + |
| 37 | + it("should notify 2 'semi' errors", () => { |
| 38 | + const cli = new CLIEngine({ |
| 39 | + cwd: FIXTURE_DIR, |
| 40 | + envs: ["es6", "node"], |
| 41 | + parser: PARSER_PATH, |
| 42 | + rules: {semi: "error"}, |
| 43 | + useEslintrc: false, |
| 44 | + }) |
| 45 | + const report = cli.executeOnFiles(["hello.vue"]) |
| 46 | + const messages = report.results[0].messages |
| 47 | + |
| 48 | + assert(messages.length === 2) |
| 49 | + assert(messages[0].ruleId === "semi") |
| 50 | + assert(messages[0].line === 8) |
| 51 | + assert(messages[0].column === 35) |
| 52 | + assert(messages[0].source === " return {greeting: \"Hello\"}") |
| 53 | + assert(messages[1].ruleId === "semi") |
| 54 | + assert(messages[1].line === 10) |
| 55 | + assert(messages[1].column === 2) |
| 56 | + assert(messages[1].source === "}") |
| 57 | + }) |
| 58 | + |
| 59 | + it("should fix 2 'semi' errors with --fix option", () => { |
| 60 | + const cli = new CLIEngine({ |
| 61 | + cwd: FIXTURE_DIR, |
| 62 | + envs: ["es6", "node"], |
| 63 | + fix: true, |
| 64 | + parser: PARSER_PATH, |
| 65 | + rules: {semi: "error"}, |
| 66 | + useEslintrc: false, |
| 67 | + }) |
| 68 | + CLIEngine.outputFixes(cli.executeOnFiles(["hello.vue"])) |
| 69 | + |
| 70 | + const actual = fs.readFileSync(path.join(FIXTURE_DIR, "hello.vue"), "utf8") |
| 71 | + const expected = fs.readFileSync(path.join(FIXTURE_DIR, "hello.vue.fixed"), "utf8") |
| 72 | + |
| 73 | + assert(actual === expected) |
| 74 | + }) |
| 75 | +}) |
0 commit comments