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

Migrate to Jest and Make Use of Snapshot Testing #56

Merged
merged 3 commits into from
Apr 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand Down Expand Up @@ -81,5 +85,9 @@
"title": "The Path to SwiftLint",
"default": "/usr/local/bin/swiftlint"
}
},
"atomTestRunner": "atom-test-runner-jest",
"jest": {
"preset": "jest-preset-atom"
}
}
25 changes: 25 additions & 0 deletions spec/__snapshots__/linter-swiftlint-spec.ts.snap
Original file line number Diff line number Diff line change
@@ -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",
},
]
`;
40 changes: 0 additions & 40 deletions spec/linter-swiftlint-spec.js

This file was deleted.

46 changes: 46 additions & 0 deletions spec/linter-swiftlint-spec.ts
Original file line number Diff line number Diff line change
@@ -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();
});
});