Skip to content

Commit

Permalink
✅ Add more specs
Browse files Browse the repository at this point in the history
  • Loading branch information
steelbrain committed Feb 16, 2016
1 parent ed317b2 commit 1d21ff1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
27 changes: 15 additions & 12 deletions spec/main-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,11 @@ import {it, wait} from './helpers'

describe('Main Module', function() {
function uninstallPackage(name) {
waitsForPromise(function() {
return atom.packages.uninstallDirectory(
Path.join(atom.packages.getPackageDirPaths().pop(), name)
)
})
return atom.packages.uninstallDirectory(
Path.join(atom.packages.getPackageDirPaths().pop(), name)
)
}

afterEach(function() {
uninstallPackage('auto-semicolon')
uninstallPackage('glow')
})

it('works as a whole', async function() {
const _ = atom.packages.getLoadedPackage
const packageName = 'auto-semicolon'
Expand All @@ -35,6 +28,7 @@ describe('Main Module', function() {
expect(atom.packages.getActivePackage(packageName)).not.toBeDefined()
await require('./fixtures/packages/some-package').activate()
expect(atom.packages.getActivePackage(packageName)).toBeDefined()
await uninstallPackage(packageName)

const notifications = atom.notifications.getNotifications()
expect(notifications.length).toBe(1)
Expand Down Expand Up @@ -64,7 +58,7 @@ describe('Main Module', function() {

it('can install multiple packages at once', async function() {
const _ = atom.packages.getLoadedPackage
const packageNameFirst = 'auto-semicolon'
const packageNameFirst = 'atom-idle-autosave'
const packageNameSecond = 'glow'
spyOn(atom.packages, 'getLoadedPackage').andCallFake(function(name) {
if (name === 'some-package') {
Expand All @@ -83,6 +77,8 @@ describe('Main Module', function() {
await require('./fixtures/packages/some-package').activate()
expect(atom.packages.getActivePackage(packageNameFirst)).toBeDefined()
expect(atom.packages.getActivePackage(packageNameSecond)).toBeDefined()
await uninstallPackage(packageNameFirst)
await uninstallPackage(packageNameSecond)

const notifications = atom.notifications.getNotifications()
expect(notifications.length).toBe(1)
Expand All @@ -92,7 +88,7 @@ describe('Main Module', function() {

it('works with hardcoded package names', async function() {
const _ = atom.packages.getLoadedPackage
const packageName = 'auto-semicolon'
const packageName = 'atom-bracket-highlight'
spyOn(atom.packages, 'getLoadedPackage').andCallFake(function(name) {
if (name === 'some-package') {
return {
Expand All @@ -107,9 +103,16 @@ describe('Main Module', function() {
expect(atom.packages.getActivePackage(packageName)).not.toBeDefined()
await require('./fixtures/packages/some-package/index-hardcoded-name').activate()
expect(atom.packages.getActivePackage(packageName)).toBeDefined()
await uninstallPackage(packageName)

const notifications = atom.notifications.getNotifications()
expect(notifications.length).toBe(1)
expect(notifications[0].type).toBe('info')
})

it('stays silent when that package name is not found in active packages', async function() {
await require('./fixtures/packages/some-package/index-hardcoded-name').activate()
const notifications = atom.notifications.getNotifications()
expect(notifications.length).toBe(0)
})
})
2 changes: 2 additions & 0 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ export function getDependencies(name) {
}
}
}
} else {
console.error(`[Package-Deps] Unable to get package info for ${name}`)
}

return toReturn
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export async function install(name = null) {
name = require('atom-package-path').guessFromCallIndex(5)
}
if (!name) {
console.log(`Unable to get package name for file: ${filePath}`)
console.error(`[Package-Deps] Unable to get package name for file: ${filePath}`)
return
}

Expand Down

0 comments on commit 1d21ff1

Please sign in to comment.