diff --git a/package.json b/package.json index 0091558..8c4bd25 100644 --- a/package.json +++ b/package.json @@ -47,12 +47,16 @@ "@commitlint/travis-cli": "^6.1.3", "@semantic-release/apm-config": "^2.0.1", "@types/atom": "^1.25.1", + "@types/jest": "^22.2.3", "@types/node": "^9.6.5", + "atom-test-runner-jest": "^0.2.0", "husky": "^0.14.3", + "jest-preset-atom": "^0.2.1", "semantic-release": "^15.1.7" }, "scripts": { - "commitmsg": "commitlint -e $GIT_PARAMS" + "commitmsg": "commitlint -e $GIT_PARAMS", + "test": "atom --test spec" }, "atomTranspilers": [ { @@ -81,5 +85,9 @@ "title": "The Path to SwiftLint", "default": "/usr/local/bin/swiftlint" } + }, + "atomTestRunner": "atom-test-runner-jest", + "jest": { + "preset": "jest-preset-atom" } } diff --git a/spec/__snapshots__/linter-swiftlint-spec.ts.snap b/spec/__snapshots__/linter-swiftlint-spec.ts.snap new file mode 100644 index 0000000..53d7fb0 --- /dev/null +++ b/spec/__snapshots__/linter-swiftlint-spec.ts.snap @@ -0,0 +1,25 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`The swiftlint provider for Linter finds nothing wrong with a well formed file 1`] = `Array []`; + +exports[`The swiftlint provider for Linter finds something wrong with a not well formed file 1`] = ` +Array [ + Object { + "excerpt": "Identifier Name Violation: Variable name should be between 3 and 40 characters long: 's' (identifier_name)", + "location": Object { + "file": "../fixtures/not-well-formed.swift", + "position": Array [ + Array [ + 2, + 0, + ], + Array [ + 2, + 3, + ], + ], + }, + "severity": "error", + }, +] +`; diff --git a/spec/linter-swiftlint-spec.js b/spec/linter-swiftlint-spec.js deleted file mode 100644 index ec828d0..0000000 --- a/spec/linter-swiftlint-spec.js +++ /dev/null @@ -1,40 +0,0 @@ -describe("The swiftlint provider for Linter", () => { - const { lint } = require("../src/index").provideLinter(); - - beforeEach(() => { - atom.workspace.destroyActivePaneItem(); - waitsForPromise(async () => { - await atom.packages.activatePackage("linter-swiftlint"); - }); - }); - - it("should be in the packages list", () => { - expect(atom.packages.isPackageLoaded("linter-swiftlint")).toBe(true); - }); - - it("should be an active package", () => { - expect(atom.packages.isPackageActive("linter-swiftlint")).toBe(true); - }); - - it("finds nothing wrong with a well formed file", () => { - waitsForPromise(async () => { - const editor = await atom.workspace.open( - __dirname + "/fixtures/well-formed.swift" - ); - const messages = await lint(editor); - - expect(messages.length).toEqual(0); - }); - }); - - it("finds something wrong with a not well formed file", () => - waitsForPromise(async () => { - const editor = await atom.workspace.open( - __dirname + "/fixtures/not-well-formed.swift" - ); - const messages = await lint(editor); - - expect(messages.length).toEqual(1); - expect(messages[0].location.position).toEqual([[2, 0], [2, 3]]); - })); -}); diff --git a/spec/linter-swiftlint-spec.ts b/spec/linter-swiftlint-spec.ts new file mode 100644 index 0000000..b5e63c3 --- /dev/null +++ b/spec/linter-swiftlint-spec.ts @@ -0,0 +1,46 @@ +import * as path from "path"; + +// Make files in Linter results relative, so that they are consistent across environments. +expect.addSnapshotSerializer({ + test: val => val && val.hasOwnProperty("file") && path.isAbsolute(val.file), + print: (val, serialize) => { + return serialize({ + ...val, + file: path.relative(__filename, val.file) + }); + } +}); + +describe("The swiftlint provider for Linter", () => { + const { lint } = require("../src/index").provideLinter(); + + beforeEach(async () => { + await atom.packages.activatePackage("linter-swiftlint"); + }); + + it("should be in the packages list", () => { + expect(atom.packages.isPackageLoaded("linter-swiftlint")).toBe(true); + }); + + it("should be an active package", () => { + expect(atom.packages.isPackageActive("linter-swiftlint")).toBe(true); + }); + + it("finds nothing wrong with a well formed file", async () => { + const editor = await atom.workspace.open( + __dirname + "/fixtures/well-formed.swift" + ); + const messages = await lint(editor); + + expect(messages).toMatchSnapshot(); + }); + + it("finds something wrong with a not well formed file", async () => { + const editor = await atom.workspace.open( + __dirname + "/fixtures/not-well-formed.swift" + ); + const messages = await lint(editor); + + expect(messages).toMatchSnapshot(); + }); +});