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

Add specs #271

Merged
merged 1 commit into from
Apr 20, 2016
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
Add specs
Add some basic tests verifying the package is minimally working.
  • Loading branch information
Arcanemagus committed Apr 20, 2016
commit 0cae58dab8b7981d3de5c78ed65bbf46f0838498
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
spec/fixtures
8 changes: 8 additions & 0 deletions spec/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
globals: {
waitsForPromise: true
},
env: {
jasmine: true
}
}
1 change: 1 addition & 0 deletions spec/fixtures/.jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
3 changes: 3 additions & 0 deletions spec/fixtures/bitwise/.jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"bitwise": true
}
1 change: 1 addition & 0 deletions spec/fixtures/bitwise/bitwise.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var a = 4 & 2;
Empty file added spec/fixtures/empty.js
Empty file.
1 change: 1 addition & 0 deletions spec/fixtures/good.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var a = 42;
1 change: 1 addition & 0 deletions spec/fixtures/syntax/badSyntax.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var a = 42+
103 changes: 103 additions & 0 deletions spec/linter-jshint-spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
'use babel'

import linter from '../lib/main'
import * as path from 'path'

const bitwisePath = path.join(__dirname, 'fixtures', 'bitwise', 'bitwise.js')
const syntaxPath = path.join(__dirname, 'fixtures', 'syntax', 'badSyntax.js')
const emptyPath = path.join(__dirname, 'fixtures', 'empty.js')
const goodPath = path.join(__dirname, 'fixtures', 'good.js')

describe('The JSHint provider for Linter', () => {
const lint = linter.provideLinter().lint

beforeEach(() => {
waitsForPromise(() =>
atom.packages.activatePackage('linter-jshint')
)
waitsForPromise(() =>
atom.packages.activatePackage('language-javascript')
)
waitsForPromise(() =>
atom.workspace.open(bitwisePath)
)
})

it('should be in the packages list', () =>
expect(atom.packages.isPackageLoaded('linter-jshint')).toBe(true)
)

it('should be an active package', () =>
expect(atom.packages.isPackageActive('linter-jshint')).toBe(true)
)

describe('shows errors in a file with issues', () => {
let editor = null
beforeEach(() => {
waitsForPromise(() =>
atom.workspace.open(bitwisePath).then(openEditor => {
editor = openEditor
})
)
})

it('verifies the first message', () => {
const message = '<a href="http://jslinterrors.com/W016">W016</a>' +
" - Unexpected use of '&'."
waitsForPromise(() =>
lint(editor).then(messages => {
expect(messages[0].type).toBe('Warning')
expect(messages[0].text).not.toBeDefined()
expect(messages[0].html).toBe(message)
expect(messages[0].filePath).toBe(bitwisePath)
expect(messages[0].range).toEqual([[0, 10], [0, 14]])
})
)
})
})

it('finds nothing wrong with an empty file', () => {
waitsForPromise(() =>
atom.workspace.open(emptyPath).then(editor =>
lint(editor).then(messages => {
expect(messages.length).toBe(0)
})
)
)
})

it('finds nothing wrong with a valid file', () => {
waitsForPromise(() =>
atom.workspace.open(goodPath).then(editor =>
lint(editor).then(messages => {
expect(messages.length).toBe(0)
})
)
)
})

describe('shows syntax errors', () => {
let editor = null
beforeEach(() => {
waitsForPromise(() =>
atom.workspace.open(syntaxPath).then(openEditor => {
editor = openEditor
})
)
})

it('verifies the first message', () => {
const message = '<a href="http://jslinterrors.com/E006">E006</a>' +
' - Unexpected early end of program.'
waitsForPromise(() =>
lint(editor).then(messages => {
expect(messages[0].type).toBe('Error')
expect(messages[0].text).not.toBeDefined()
expect(messages[0].html).toBe(message)
expect(messages[0].filePath).toBe(syntaxPath)
expect(messages[0].range).toEqual([[0, 10], [0, 11]])
})
)
})
})
})