2014-02-24 05:19:00 +04:00
|
|
|
|
{$, $$, WorkspaceView} = require 'atom'
|
2013-04-11 03:02:13 +04:00
|
|
|
|
Exec = require('child_process').exec
|
2013-06-21 00:42:16 +04:00
|
|
|
|
path = require 'path'
|
2014-02-18 00:59:03 +04:00
|
|
|
|
Package = require '../src/package'
|
2013-10-22 03:13:04 +04:00
|
|
|
|
ThemeManager = require '../src/theme-manager'
|
2012-12-19 06:47:20 +04:00
|
|
|
|
|
2014-04-22 22:04:14 +04:00
|
|
|
|
describe "the `atom` global", ->
|
2013-02-08 00:17:34 +04:00
|
|
|
|
beforeEach ->
|
2013-11-26 22:11:31 +04:00
|
|
|
|
atom.workspaceView = new WorkspaceView
|
2013-02-08 23:51:51 +04:00
|
|
|
|
|
2013-03-25 20:57:58 +04:00
|
|
|
|
describe "package lifecycle methods", ->
|
2013-05-22 01:15:26 +04:00
|
|
|
|
describe ".loadPackage(name)", ->
|
2014-02-06 02:46:49 +04:00
|
|
|
|
it "continues if the package has an invalid package.json", ->
|
|
|
|
|
spyOn(console, 'warn')
|
|
|
|
|
atom.config.set("core.disabledPackages", [])
|
|
|
|
|
expect(-> atom.packages.loadPackage("package-with-broken-package-json")).not.toThrow()
|
2013-03-27 01:46:19 +04:00
|
|
|
|
|
2014-02-06 02:46:49 +04:00
|
|
|
|
it "continues if the package has an invalid keymap", ->
|
|
|
|
|
atom.config.set("core.disabledPackages", [])
|
|
|
|
|
expect(-> atom.packages.loadPackage("package-with-broken-keymap")).not.toThrow()
|
2013-10-11 22:35:59 +04:00
|
|
|
|
|
2013-05-22 01:15:26 +04:00
|
|
|
|
describe ".unloadPackage(name)", ->
|
|
|
|
|
describe "when the package is active", ->
|
|
|
|
|
it "throws an error", ->
|
2014-02-07 23:21:52 +04:00
|
|
|
|
pack = null
|
|
|
|
|
waitsForPromise ->
|
|
|
|
|
atom.packages.activatePackage('package-with-main').then (p) -> pack = p
|
|
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
|
expect(atom.packages.isPackageLoaded(pack.name)).toBeTruthy()
|
|
|
|
|
expect(atom.packages.isPackageActive(pack.name)).toBeTruthy()
|
|
|
|
|
expect( -> atom.packages.unloadPackage(pack.name)).toThrow()
|
|
|
|
|
expect(atom.packages.isPackageLoaded(pack.name)).toBeTruthy()
|
|
|
|
|
expect(atom.packages.isPackageActive(pack.name)).toBeTruthy()
|
2013-05-22 01:15:26 +04:00
|
|
|
|
|
|
|
|
|
describe "when the package is not loaded", ->
|
|
|
|
|
it "throws an error", ->
|
2013-11-20 05:31:41 +04:00
|
|
|
|
expect(atom.packages.isPackageLoaded('unloaded')).toBeFalsy()
|
|
|
|
|
expect( -> atom.packages.unloadPackage('unloaded')).toThrow()
|
|
|
|
|
expect(atom.packages.isPackageLoaded('unloaded')).toBeFalsy()
|
2013-05-22 01:15:26 +04:00
|
|
|
|
|
|
|
|
|
describe "when the package is loaded", ->
|
|
|
|
|
it "no longers reports it as being loaded", ->
|
2013-11-20 05:31:41 +04:00
|
|
|
|
pack = atom.packages.loadPackage('package-with-main')
|
|
|
|
|
expect(atom.packages.isPackageLoaded(pack.name)).toBeTruthy()
|
|
|
|
|
atom.packages.unloadPackage(pack.name)
|
|
|
|
|
expect(atom.packages.isPackageLoaded(pack.name)).toBeFalsy()
|
2013-05-22 01:15:26 +04:00
|
|
|
|
|
2013-03-25 20:57:58 +04:00
|
|
|
|
describe ".activatePackage(id)", ->
|
2013-03-26 03:55:21 +04:00
|
|
|
|
describe "atom packages", ->
|
2014-02-08 03:22:58 +04:00
|
|
|
|
describe "when called multiple times", ->
|
|
|
|
|
it "it only calls activate on the package once", ->
|
2014-02-18 00:59:03 +04:00
|
|
|
|
spyOn(Package.prototype, 'activateNow').andCallThrough()
|
2014-02-08 03:22:58 +04:00
|
|
|
|
atom.packages.activatePackage('package-with-index')
|
|
|
|
|
atom.packages.activatePackage('package-with-index')
|
|
|
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
|
atom.packages.activatePackage('package-with-index')
|
|
|
|
|
|
|
|
|
|
runs ->
|
2014-02-18 00:59:03 +04:00
|
|
|
|
expect(Package.prototype.activateNow.callCount).toBe 1
|
2014-02-08 03:22:58 +04:00
|
|
|
|
|
2013-03-26 04:57:30 +04:00
|
|
|
|
describe "when the package has a main module", ->
|
|
|
|
|
describe "when the metadata specifies a main module path˜", ->
|
|
|
|
|
it "requires the module at the specified path", ->
|
2013-09-18 02:58:08 +04:00
|
|
|
|
mainModule = require('./fixtures/packages/package-with-main/main-module')
|
2013-03-26 04:57:30 +04:00
|
|
|
|
spyOn(mainModule, 'activate')
|
2014-02-07 23:21:52 +04:00
|
|
|
|
pack = null
|
|
|
|
|
waitsForPromise ->
|
|
|
|
|
atom.packages.activatePackage('package-with-main').then (p) -> pack = p
|
|
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
|
expect(mainModule.activate).toHaveBeenCalled()
|
|
|
|
|
expect(pack.mainModule).toBe mainModule
|
2013-03-26 04:57:30 +04:00
|
|
|
|
|
|
|
|
|
describe "when the metadata does not specify a main module", ->
|
|
|
|
|
it "requires index.coffee", ->
|
2013-09-18 02:58:08 +04:00
|
|
|
|
indexModule = require('./fixtures/packages/package-with-index/index')
|
2013-03-26 04:57:30 +04:00
|
|
|
|
spyOn(indexModule, 'activate')
|
2014-02-07 23:21:52 +04:00
|
|
|
|
pack = null
|
|
|
|
|
waitsForPromise ->
|
|
|
|
|
atom.packages.activatePackage('package-with-index').then (p) -> pack = p
|
|
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
|
expect(indexModule.activate).toHaveBeenCalled()
|
|
|
|
|
expect(pack.mainModule).toBe indexModule
|
2013-03-26 04:57:30 +04:00
|
|
|
|
|
2013-03-26 22:12:47 +04:00
|
|
|
|
it "assigns config defaults from the module", ->
|
2013-11-11 21:16:44 +04:00
|
|
|
|
expect(atom.config.get('package-with-config-defaults.numbers.one')).toBeUndefined()
|
2014-02-18 02:06:59 +04:00
|
|
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
|
atom.packages.activatePackage('package-with-config-defaults')
|
|
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
|
expect(atom.config.get('package-with-config-defaults.numbers.one')).toBe 1
|
|
|
|
|
expect(atom.config.get('package-with-config-defaults.numbers.two')).toBe 2
|
2013-03-26 22:12:47 +04:00
|
|
|
|
|
2013-03-27 01:42:58 +04:00
|
|
|
|
describe "when the package metadata includes activation events", ->
|
2014-02-07 23:21:52 +04:00
|
|
|
|
[mainModule, promise] = []
|
2013-03-27 01:42:58 +04:00
|
|
|
|
|
|
|
|
|
beforeEach ->
|
2013-09-18 02:58:08 +04:00
|
|
|
|
mainModule = require './fixtures/packages/package-with-activation-events/index'
|
2013-03-27 01:42:58 +04:00
|
|
|
|
spyOn(mainModule, 'activate').andCallThrough()
|
2014-02-18 00:59:03 +04:00
|
|
|
|
spyOn(Package.prototype, 'requireMainModule').andCallThrough()
|
2014-02-07 23:21:52 +04:00
|
|
|
|
|
|
|
|
|
promise = atom.packages.activatePackage('package-with-activation-events')
|
|
|
|
|
|
2013-03-27 01:42:58 +04:00
|
|
|
|
it "defers requiring/activating the main module until an activation event bubbles to the root view", ->
|
2014-02-07 23:21:52 +04:00
|
|
|
|
expect(promise.isFulfilled()).not.toBeTruthy()
|
2013-11-26 22:11:31 +04:00
|
|
|
|
atom.workspaceView.trigger 'activation-event'
|
2014-02-07 23:21:52 +04:00
|
|
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
|
promise
|
2013-03-27 01:42:58 +04:00
|
|
|
|
|
|
|
|
|
it "triggers the activation event on all handlers registered during activation", ->
|
2014-04-22 22:01:21 +04:00
|
|
|
|
waitsForPromise ->
|
|
|
|
|
atom.workspaceView.open()
|
|
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
|
editorView = atom.workspaceView.getActiveView()
|
|
|
|
|
eventHandler = jasmine.createSpy("activation-event")
|
|
|
|
|
editorView.command 'activation-event', eventHandler
|
|
|
|
|
editorView.trigger 'activation-event'
|
|
|
|
|
expect(mainModule.activate.callCount).toBe 1
|
|
|
|
|
expect(mainModule.activationEventCallCount).toBe 1
|
|
|
|
|
expect(eventHandler.callCount).toBe 1
|
|
|
|
|
editorView.trigger 'activation-event'
|
|
|
|
|
expect(mainModule.activationEventCallCount).toBe 2
|
|
|
|
|
expect(eventHandler.callCount).toBe 2
|
|
|
|
|
expect(mainModule.activate.callCount).toBe 1
|
2013-03-27 01:42:58 +04:00
|
|
|
|
|
2014-03-12 02:12:13 +04:00
|
|
|
|
it "activates the package immediately when the events are empty", ->
|
|
|
|
|
mainModule = require './fixtures/packages/package-with-empty-activation-events/index'
|
|
|
|
|
spyOn(mainModule, 'activate').andCallThrough()
|
|
|
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
|
atom.packages.activatePackage('package-with-empty-activation-events')
|
|
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
|
expect(mainModule.activate.callCount).toBe 1
|
|
|
|
|
|
2013-03-26 04:57:30 +04:00
|
|
|
|
describe "when the package has no main module", ->
|
|
|
|
|
it "does not throw an exception", ->
|
|
|
|
|
spyOn(console, "error")
|
|
|
|
|
spyOn(console, "warn").andCallThrough()
|
2013-11-20 22:48:55 +04:00
|
|
|
|
expect(-> atom.packages.activatePackage('package-without-module')).not.toThrow()
|
2013-03-26 04:57:30 +04:00
|
|
|
|
expect(console.error).not.toHaveBeenCalled()
|
|
|
|
|
expect(console.warn).not.toHaveBeenCalled()
|
2013-01-04 02:10:11 +04:00
|
|
|
|
|
2013-03-26 20:50:40 +04:00
|
|
|
|
it "passes the activate method the package's previously serialized state if it exists", ->
|
2014-02-07 23:21:52 +04:00
|
|
|
|
pack = null
|
|
|
|
|
waitsForPromise ->
|
|
|
|
|
atom.packages.activatePackage("package-with-serialization").then (p) -> pack = p
|
|
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
|
expect(pack.mainModule.someNumber).not.toBe 77
|
|
|
|
|
pack.mainModule.someNumber = 77
|
|
|
|
|
atom.packages.deactivatePackage("package-with-serialization")
|
|
|
|
|
spyOn(pack.mainModule, 'activate').andCallThrough()
|
|
|
|
|
atom.packages.activatePackage("package-with-serialization")
|
|
|
|
|
expect(pack.mainModule.activate).toHaveBeenCalledWith({someNumber: 77})
|
2013-01-04 02:10:11 +04:00
|
|
|
|
|
2013-03-26 20:50:40 +04:00
|
|
|
|
it "logs warning instead of throwing an exception if the package fails to load", ->
|
2013-11-11 21:16:44 +04:00
|
|
|
|
atom.config.set("core.disabledPackages", [])
|
2013-03-26 03:55:21 +04:00
|
|
|
|
spyOn(console, "warn")
|
2013-11-20 22:48:55 +04:00
|
|
|
|
expect(-> atom.packages.activatePackage("package-that-throws-an-exception")).not.toThrow()
|
2013-03-26 03:55:21 +04:00
|
|
|
|
expect(console.warn).toHaveBeenCalled()
|
2013-01-04 02:10:11 +04:00
|
|
|
|
|
2013-03-26 03:55:21 +04:00
|
|
|
|
describe "keymap loading", ->
|
2013-03-26 04:57:30 +04:00
|
|
|
|
describe "when the metadata does not contain a 'keymaps' manifest", ->
|
2013-03-26 03:55:21 +04:00
|
|
|
|
it "loads all the .cson/.json files in the keymaps directory", ->
|
|
|
|
|
element1 = $$ -> @div class: 'test-1'
|
|
|
|
|
element2 = $$ -> @div class: 'test-2'
|
|
|
|
|
element3 = $$ -> @div class: 'test-3'
|
2013-01-04 02:10:11 +04:00
|
|
|
|
|
2014-04-22 22:01:21 +04:00
|
|
|
|
expect(atom.keymaps.findKeyBindings(keystrokes:'ctrl-z', target:element1[0])).toHaveLength 0
|
|
|
|
|
expect(atom.keymaps.findKeyBindings(keystrokes:'ctrl-z', target:element2[0])).toHaveLength 0
|
|
|
|
|
expect(atom.keymaps.findKeyBindings(keystrokes:'ctrl-z', target:element3[0])).toHaveLength 0
|
2013-01-04 02:10:11 +04:00
|
|
|
|
|
2013-11-20 22:48:55 +04:00
|
|
|
|
atom.packages.activatePackage("package-with-keymaps")
|
2013-01-28 10:38:11 +04:00
|
|
|
|
|
2014-04-22 22:01:21 +04:00
|
|
|
|
expect(atom.keymaps.findKeyBindings(keystrokes:'ctrl-z', target:element1[0])[0].command).toBe "test-1"
|
|
|
|
|
expect(atom.keymaps.findKeyBindings(keystrokes:'ctrl-z', target:element2[0])[0].command).toBe "test-2"
|
|
|
|
|
expect(atom.keymaps.findKeyBindings(keystrokes:'ctrl-z', target:element3[0])).toHaveLength 0
|
2013-02-09 05:19:45 +04:00
|
|
|
|
|
2013-03-26 04:57:30 +04:00
|
|
|
|
describe "when the metadata contains a 'keymaps' manifest", ->
|
2013-03-26 03:55:21 +04:00
|
|
|
|
it "loads only the keymaps specified by the manifest, in the specified order", ->
|
|
|
|
|
element1 = $$ -> @div class: 'test-1'
|
|
|
|
|
element3 = $$ -> @div class: 'test-3'
|
2013-03-23 06:46:32 +04:00
|
|
|
|
|
2014-04-22 22:01:21 +04:00
|
|
|
|
expect(atom.keymaps.findKeyBindings(keystrokes:'ctrl-z', target:element1[0])).toHaveLength 0
|
2013-03-23 06:46:32 +04:00
|
|
|
|
|
2013-11-20 22:48:55 +04:00
|
|
|
|
atom.packages.activatePackage("package-with-keymaps-manifest")
|
2013-02-09 05:19:45 +04:00
|
|
|
|
|
2014-04-22 22:01:21 +04:00
|
|
|
|
expect(atom.keymaps.findKeyBindings(keystrokes:'ctrl-z', target:element1[0])[0].command).toBe 'keymap-1'
|
|
|
|
|
expect(atom.keymaps.findKeyBindings(keystrokes:'ctrl-n', target:element1[0])[0].command).toBe 'keymap-2'
|
|
|
|
|
expect(atom.keymaps.findKeyBindings(keystrokes:'ctrl-y', target:element3[0])).toHaveLength 0
|
2013-02-09 05:19:45 +04:00
|
|
|
|
|
2013-09-20 01:21:31 +04:00
|
|
|
|
describe "menu loading", ->
|
2013-10-09 03:23:34 +04:00
|
|
|
|
beforeEach ->
|
|
|
|
|
atom.contextMenu.definitions = []
|
|
|
|
|
atom.menu.template = []
|
2013-09-20 01:55:17 +04:00
|
|
|
|
|
2013-09-20 01:21:31 +04:00
|
|
|
|
describe "when the metadata does not contain a 'menus' manifest", ->
|
2013-09-20 01:55:17 +04:00
|
|
|
|
it "loads all the .cson/.json files in the menus directory", ->
|
2013-09-20 01:21:31 +04:00
|
|
|
|
element = ($$ -> @div class: 'test-1')[0]
|
|
|
|
|
|
|
|
|
|
expect(atom.contextMenu.definitionsForElement(element)).toEqual []
|
|
|
|
|
|
2013-11-20 22:48:55 +04:00
|
|
|
|
atom.packages.activatePackage("package-with-menus")
|
2013-09-20 01:21:31 +04:00
|
|
|
|
|
2013-10-18 21:19:39 +04:00
|
|
|
|
expect(atom.menu.template.length).toBe 2
|
2013-10-09 03:23:34 +04:00
|
|
|
|
expect(atom.menu.template[0].label).toBe "Second to Last"
|
|
|
|
|
expect(atom.menu.template[1].label).toBe "Last"
|
2013-09-20 01:21:31 +04:00
|
|
|
|
expect(atom.contextMenu.definitionsForElement(element)[0].label).toBe "Menu item 1"
|
|
|
|
|
expect(atom.contextMenu.definitionsForElement(element)[1].label).toBe "Menu item 2"
|
|
|
|
|
expect(atom.contextMenu.definitionsForElement(element)[2].label).toBe "Menu item 3"
|
|
|
|
|
|
2013-09-20 01:55:17 +04:00
|
|
|
|
describe "when the metadata contains a 'menus' manifest", ->
|
2013-09-20 01:21:31 +04:00
|
|
|
|
it "loads only the menus specified by the manifest, in the specified order", ->
|
|
|
|
|
element = ($$ -> @div class: 'test-1')[0]
|
|
|
|
|
|
|
|
|
|
expect(atom.contextMenu.definitionsForElement(element)).toEqual []
|
|
|
|
|
|
2013-11-20 22:48:55 +04:00
|
|
|
|
atom.packages.activatePackage("package-with-menus-manifest")
|
2013-09-20 01:21:31 +04:00
|
|
|
|
|
2013-10-09 03:23:34 +04:00
|
|
|
|
expect(atom.menu.template[0].label).toBe "Second to Last"
|
|
|
|
|
expect(atom.menu.template[1].label).toBe "Last"
|
2013-09-20 01:21:31 +04:00
|
|
|
|
expect(atom.contextMenu.definitionsForElement(element)[0].label).toBe "Menu item 2"
|
|
|
|
|
expect(atom.contextMenu.definitionsForElement(element)[1].label).toBe "Menu item 1"
|
|
|
|
|
expect(atom.contextMenu.definitionsForElement(element)[2]).toBeUndefined()
|
|
|
|
|
|
2013-03-26 04:57:30 +04:00
|
|
|
|
describe "stylesheet loading", ->
|
|
|
|
|
describe "when the metadata contains a 'stylesheets' manifest", ->
|
2013-03-26 20:50:40 +04:00
|
|
|
|
it "loads stylesheets from the stylesheets directory as specified by the manifest", ->
|
2013-09-18 02:58:08 +04:00
|
|
|
|
one = require.resolve("./fixtures/packages/package-with-stylesheets-manifest/stylesheets/1.css")
|
|
|
|
|
two = require.resolve("./fixtures/packages/package-with-stylesheets-manifest/stylesheets/2.less")
|
|
|
|
|
three = require.resolve("./fixtures/packages/package-with-stylesheets-manifest/stylesheets/3.css")
|
2013-11-05 04:33:11 +04:00
|
|
|
|
|
|
|
|
|
one = atom.themes.stringToId(one)
|
|
|
|
|
two = atom.themes.stringToId(two)
|
|
|
|
|
three = atom.themes.stringToId(three)
|
|
|
|
|
|
2013-09-25 19:39:16 +04:00
|
|
|
|
expect(atom.themes.stylesheetElementForId(one)).not.toExist()
|
|
|
|
|
expect(atom.themes.stylesheetElementForId(two)).not.toExist()
|
|
|
|
|
expect(atom.themes.stylesheetElementForId(three)).not.toExist()
|
2013-03-26 20:50:40 +04:00
|
|
|
|
|
2013-11-20 22:48:55 +04:00
|
|
|
|
atom.packages.activatePackage("package-with-stylesheets-manifest")
|
2013-03-26 20:50:40 +04:00
|
|
|
|
|
2013-09-25 19:39:16 +04:00
|
|
|
|
expect(atom.themes.stylesheetElementForId(one)).toExist()
|
|
|
|
|
expect(atom.themes.stylesheetElementForId(two)).toExist()
|
|
|
|
|
expect(atom.themes.stylesheetElementForId(three)).not.toExist()
|
2013-03-26 20:50:40 +04:00
|
|
|
|
expect($('#jasmine-content').css('font-size')).toBe '1px'
|
2013-03-26 04:57:30 +04:00
|
|
|
|
|
2013-03-26 22:12:53 +04:00
|
|
|
|
describe "when the metadata does not contain a 'stylesheets' manifest", ->
|
2013-03-26 04:57:30 +04:00
|
|
|
|
it "loads all stylesheets from the stylesheets directory", ->
|
2013-09-18 02:58:08 +04:00
|
|
|
|
one = require.resolve("./fixtures/packages/package-with-stylesheets/stylesheets/1.css")
|
|
|
|
|
two = require.resolve("./fixtures/packages/package-with-stylesheets/stylesheets/2.less")
|
|
|
|
|
three = require.resolve("./fixtures/packages/package-with-stylesheets/stylesheets/3.css")
|
2013-11-05 04:33:11 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
one = atom.themes.stringToId(one)
|
|
|
|
|
two = atom.themes.stringToId(two)
|
|
|
|
|
three = atom.themes.stringToId(three)
|
|
|
|
|
|
2013-09-25 19:39:16 +04:00
|
|
|
|
expect(atom.themes.stylesheetElementForId(one)).not.toExist()
|
|
|
|
|
expect(atom.themes.stylesheetElementForId(two)).not.toExist()
|
|
|
|
|
expect(atom.themes.stylesheetElementForId(three)).not.toExist()
|
2013-03-26 04:57:30 +04:00
|
|
|
|
|
2013-11-20 22:48:55 +04:00
|
|
|
|
atom.packages.activatePackage("package-with-stylesheets")
|
2013-09-25 19:39:16 +04:00
|
|
|
|
expect(atom.themes.stylesheetElementForId(one)).toExist()
|
|
|
|
|
expect(atom.themes.stylesheetElementForId(two)).toExist()
|
|
|
|
|
expect(atom.themes.stylesheetElementForId(three)).toExist()
|
2013-03-26 04:57:30 +04:00
|
|
|
|
expect($('#jasmine-content').css('font-size')).toBe '3px'
|
2013-03-26 03:55:21 +04:00
|
|
|
|
|
2013-03-26 21:21:44 +04:00
|
|
|
|
describe "grammar loading", ->
|
|
|
|
|
it "loads the package's grammars", ->
|
2014-02-18 02:06:59 +04:00
|
|
|
|
waitsForPromise ->
|
|
|
|
|
atom.packages.activatePackage('package-with-grammars')
|
|
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
|
expect(atom.syntax.selectGrammar('a.alot').name).toBe 'Alot'
|
|
|
|
|
expect(atom.syntax.selectGrammar('a.alittle').name).toBe 'Alittle'
|
2013-03-26 21:21:44 +04:00
|
|
|
|
|
2013-03-26 22:17:05 +04:00
|
|
|
|
describe "scoped-property loading", ->
|
|
|
|
|
it "loads the scoped properties", ->
|
2014-02-07 23:21:52 +04:00
|
|
|
|
waitsForPromise ->
|
|
|
|
|
atom.packages.activatePackage("package-with-scoped-properties")
|
|
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
|
expect(atom.syntax.getProperty ['.source.omg'], 'editor.increaseIndentPattern').toBe '^a'
|
2013-03-26 22:17:05 +04:00
|
|
|
|
|
2014-02-18 02:24:26 +04:00
|
|
|
|
describe "converted textmate packages", ->
|
2013-03-26 03:55:21 +04:00
|
|
|
|
it "loads the package's grammars", ->
|
2013-11-11 20:53:52 +04:00
|
|
|
|
expect(atom.syntax.selectGrammar("file.rb").name).toBe "Null Grammar"
|
2014-02-07 23:21:52 +04:00
|
|
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
|
atom.packages.activatePackage('language-ruby')
|
|
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
|
expect(atom.syntax.selectGrammar("file.rb").name).toBe "Ruby"
|
2013-03-25 20:57:58 +04:00
|
|
|
|
|
2014-02-18 02:24:26 +04:00
|
|
|
|
it "loads the translated scoped properties", ->
|
2013-11-11 20:53:52 +04:00
|
|
|
|
expect(atom.syntax.getProperty(['.source.ruby'], 'editor.commentStart')).toBeUndefined()
|
2014-02-07 23:21:52 +04:00
|
|
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
|
atom.packages.activatePackage('language-ruby')
|
|
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
|
expect(atom.syntax.getProperty(['.source.ruby'], 'editor.commentStart')).toBe '# '
|
2013-03-27 03:27:21 +04:00
|
|
|
|
|
2013-03-25 20:57:58 +04:00
|
|
|
|
describe ".deactivatePackage(id)", ->
|
2013-03-26 03:55:21 +04:00
|
|
|
|
describe "atom packages", ->
|
2013-08-30 01:44:00 +04:00
|
|
|
|
it "calls `deactivate` on the package's main module if activate was successful", ->
|
2014-02-07 23:21:52 +04:00
|
|
|
|
pack = null
|
|
|
|
|
waitsForPromise ->
|
|
|
|
|
atom.packages.activatePackage("package-with-deactivate").then (p) -> pack = p
|
2013-03-26 03:55:21 +04:00
|
|
|
|
|
2014-02-07 23:21:52 +04:00
|
|
|
|
runs ->
|
|
|
|
|
expect(atom.packages.isPackageActive("package-with-deactivate")).toBeTruthy()
|
|
|
|
|
spyOn(pack.mainModule, 'deactivate').andCallThrough()
|
2013-03-26 03:55:21 +04:00
|
|
|
|
|
2014-02-07 23:21:52 +04:00
|
|
|
|
atom.packages.deactivatePackage("package-with-deactivate")
|
|
|
|
|
expect(pack.mainModule.deactivate).toHaveBeenCalled()
|
|
|
|
|
expect(atom.packages.isPackageActive("package-with-module")).toBeFalsy()
|
2013-08-30 01:44:00 +04:00
|
|
|
|
|
2014-02-07 23:21:52 +04:00
|
|
|
|
spyOn(console, 'warn')
|
|
|
|
|
|
|
|
|
|
badPack = null
|
|
|
|
|
waitsForPromise ->
|
|
|
|
|
atom.packages.activatePackage("package-that-throws-on-activate").then (p) -> badPack = p
|
|
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
|
expect(atom.packages.isPackageActive("package-that-throws-on-activate")).toBeTruthy()
|
|
|
|
|
spyOn(badPack.mainModule, 'deactivate').andCallThrough()
|
|
|
|
|
|
|
|
|
|
atom.packages.deactivatePackage("package-that-throws-on-activate")
|
|
|
|
|
expect(badPack.mainModule.deactivate).not.toHaveBeenCalled()
|
|
|
|
|
expect(atom.packages.isPackageActive("package-that-throws-on-activate")).toBeFalsy()
|
2013-08-30 01:44:00 +04:00
|
|
|
|
|
|
|
|
|
it "does not serialize packages that have not been activated called on their main module", ->
|
|
|
|
|
spyOn(console, 'warn')
|
2014-02-07 23:21:52 +04:00
|
|
|
|
badPack = null
|
|
|
|
|
waitsForPromise ->
|
|
|
|
|
atom.packages.activatePackage("package-that-throws-on-activate").then (p) -> badPack = p
|
2013-08-30 01:44:00 +04:00
|
|
|
|
|
2014-02-07 23:21:52 +04:00
|
|
|
|
runs ->
|
|
|
|
|
spyOn(badPack.mainModule, 'serialize').andCallThrough()
|
|
|
|
|
|
|
|
|
|
atom.packages.deactivatePackage("package-that-throws-on-activate")
|
|
|
|
|
expect(badPack.mainModule.serialize).not.toHaveBeenCalled()
|
2013-08-30 01:44:00 +04:00
|
|
|
|
|
2013-03-26 03:55:21 +04:00
|
|
|
|
it "absorbs exceptions that are thrown by the package module's serialize methods", ->
|
|
|
|
|
spyOn(console, 'error')
|
2014-02-11 03:16:58 +04:00
|
|
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
|
atom.packages.activatePackage('package-with-serialize-error')
|
|
|
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
|
atom.packages.activatePackage('package-with-serialization')
|
|
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
|
atom.packages.deactivatePackages()
|
|
|
|
|
expect(atom.packages.packageStates['package-with-serialize-error']).toBeUndefined()
|
|
|
|
|
expect(atom.packages.packageStates['package-with-serialization']).toEqual someNumber: 1
|
|
|
|
|
expect(console.error).toHaveBeenCalled()
|
2013-03-26 03:55:21 +04:00
|
|
|
|
|
2013-03-26 21:25:09 +04:00
|
|
|
|
it "removes the package's grammars", ->
|
2014-02-07 23:21:52 +04:00
|
|
|
|
waitsForPromise ->
|
|
|
|
|
atom.packages.activatePackage('package-with-grammars')
|
|
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
|
atom.packages.deactivatePackage('package-with-grammars')
|
|
|
|
|
expect(atom.syntax.selectGrammar('a.alot').name).toBe 'Null Grammar'
|
|
|
|
|
expect(atom.syntax.selectGrammar('a.alittle').name).toBe 'Null Grammar'
|
2013-03-26 21:25:09 +04:00
|
|
|
|
|
2013-03-26 22:03:48 +04:00
|
|
|
|
it "removes the package's keymaps", ->
|
2014-02-07 23:21:52 +04:00
|
|
|
|
waitsForPromise ->
|
|
|
|
|
atom.packages.activatePackage('package-with-keymaps')
|
|
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
|
atom.packages.deactivatePackage('package-with-keymaps')
|
2014-05-31 00:57:26 +04:00
|
|
|
|
expect(atom.keymaps.findKeyBindings(keystrokes:'ctrl-z', target: ($$ -> @div class: 'test-1')[0])).toHaveLength 0
|
|
|
|
|
expect(atom.keymaps.findKeyBindings(keystrokes:'ctrl-z', target: ($$ -> @div class: 'test-2')[0])).toHaveLength 0
|
2013-03-26 22:03:48 +04:00
|
|
|
|
|
2013-03-26 22:07:05 +04:00
|
|
|
|
it "removes the package's stylesheets", ->
|
2014-02-07 23:21:52 +04:00
|
|
|
|
waitsForPromise ->
|
|
|
|
|
atom.packages.activatePackage('package-with-stylesheets')
|
|
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
|
atom.packages.deactivatePackage('package-with-stylesheets')
|
|
|
|
|
one = require.resolve("./fixtures/packages/package-with-stylesheets-manifest/stylesheets/1.css")
|
|
|
|
|
two = require.resolve("./fixtures/packages/package-with-stylesheets-manifest/stylesheets/2.less")
|
|
|
|
|
three = require.resolve("./fixtures/packages/package-with-stylesheets-manifest/stylesheets/3.css")
|
|
|
|
|
expect(atom.themes.stylesheetElementForId(one)).not.toExist()
|
|
|
|
|
expect(atom.themes.stylesheetElementForId(two)).not.toExist()
|
|
|
|
|
expect(atom.themes.stylesheetElementForId(three)).not.toExist()
|
2013-03-26 22:07:05 +04:00
|
|
|
|
|
2013-03-26 22:49:48 +04:00
|
|
|
|
it "removes the package's scoped-properties", ->
|
2014-02-07 23:21:52 +04:00
|
|
|
|
waitsForPromise ->
|
|
|
|
|
atom.packages.activatePackage("package-with-scoped-properties")
|
|
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
|
expect(atom.syntax.getProperty ['.source.omg'], 'editor.increaseIndentPattern').toBe '^a'
|
|
|
|
|
atom.packages.deactivatePackage("package-with-scoped-properties")
|
|
|
|
|
expect(atom.syntax.getProperty ['.source.omg'], 'editor.increaseIndentPattern').toBeUndefined()
|
2013-03-26 22:49:48 +04:00
|
|
|
|
|
2013-08-30 01:44:00 +04:00
|
|
|
|
describe "textmate packages", ->
|
2013-03-26 03:55:21 +04:00
|
|
|
|
it "removes the package's grammars", ->
|
2013-11-11 20:53:52 +04:00
|
|
|
|
expect(atom.syntax.selectGrammar("file.rb").name).toBe "Null Grammar"
|
2014-02-11 03:16:58 +04:00
|
|
|
|
|
|
|
|
|
waitsForPromise ->
|
|
|
|
|
atom.packages.activatePackage('language-ruby')
|
|
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
|
expect(atom.syntax.selectGrammar("file.rb").name).toBe "Ruby"
|
|
|
|
|
atom.packages.deactivatePackage('language-ruby')
|
|
|
|
|
expect(atom.syntax.selectGrammar("file.rb").name).toBe "Null Grammar"
|
2013-02-25 23:25:11 +04:00
|
|
|
|
|
2013-03-27 03:30:42 +04:00
|
|
|
|
it "removes the package's scoped properties", ->
|
2014-02-11 03:16:58 +04:00
|
|
|
|
waitsForPromise ->
|
|
|
|
|
atom.packages.activatePackage('language-ruby')
|
|
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
|
atom.packages.deactivatePackage('language-ruby')
|
|
|
|
|
expect(atom.syntax.getProperty(['.source.ruby'], 'editor.commentStart')).toBeUndefined()
|
2013-10-19 04:38:18 +04:00
|
|
|
|
|
2013-10-22 23:57:37 +04:00
|
|
|
|
describe ".activate()", ->
|
|
|
|
|
packageActivator = null
|
|
|
|
|
themeActivator = null
|
|
|
|
|
|
2013-10-19 04:38:18 +04:00
|
|
|
|
beforeEach ->
|
|
|
|
|
spyOn(console, 'warn')
|
|
|
|
|
atom.packages.loadPackages()
|
|
|
|
|
|
2013-10-22 23:57:37 +04:00
|
|
|
|
loadedPackages = atom.packages.getLoadedPackages()
|
|
|
|
|
expect(loadedPackages.length).toBeGreaterThan 0
|
|
|
|
|
|
|
|
|
|
packageActivator = spyOn(atom.packages, 'activatePackages')
|
|
|
|
|
themeActivator = spyOn(atom.themes, 'activatePackages')
|
|
|
|
|
|
2013-10-19 04:38:18 +04:00
|
|
|
|
afterEach ->
|
|
|
|
|
atom.packages.unloadPackages()
|
|
|
|
|
|
|
|
|
|
Syntax = require '../src/syntax'
|
|
|
|
|
atom.syntax = window.syntax = new Syntax()
|
|
|
|
|
|
|
|
|
|
it "activates all the packages, and none of the themes", ->
|
2013-10-22 23:57:37 +04:00
|
|
|
|
atom.packages.activate()
|
|
|
|
|
|
|
|
|
|
expect(packageActivator).toHaveBeenCalled()
|
|
|
|
|
expect(themeActivator).toHaveBeenCalled()
|
2013-10-19 04:38:18 +04:00
|
|
|
|
|
2013-10-22 23:57:37 +04:00
|
|
|
|
packages = packageActivator.mostRecentCall.args[0]
|
|
|
|
|
expect(['atom', 'textmate']).toContain(pack.getType()) for pack in packages
|
2013-10-19 04:38:18 +04:00
|
|
|
|
|
2013-10-22 23:57:37 +04:00
|
|
|
|
themes = themeActivator.mostRecentCall.args[0]
|
|
|
|
|
expect(['theme']).toContain(theme.getType()) for theme in themes
|
2013-10-22 02:47:15 +04:00
|
|
|
|
|
2014-02-07 23:21:52 +04:00
|
|
|
|
describe ".enablePackage() and disablePackage()", ->
|
2013-10-22 03:13:04 +04:00
|
|
|
|
describe "with packages", ->
|
|
|
|
|
it ".enablePackage() enables a disabled package", ->
|
|
|
|
|
packageName = 'package-with-main'
|
|
|
|
|
atom.config.pushAtKeyPath('core.disabledPackages', packageName)
|
|
|
|
|
atom.packages.observeDisabledPackages()
|
2013-11-11 21:16:44 +04:00
|
|
|
|
expect(atom.config.get('core.disabledPackages')).toContain packageName
|
2013-10-22 03:13:04 +04:00
|
|
|
|
|
|
|
|
|
pack = atom.packages.enablePackage(packageName)
|
|
|
|
|
loadedPackages = atom.packages.getLoadedPackages()
|
2014-02-07 23:21:52 +04:00
|
|
|
|
activatedPackages = null
|
|
|
|
|
waitsFor ->
|
|
|
|
|
activatedPackages = atom.packages.getActivePackages()
|
|
|
|
|
activatedPackages.length > 0
|
|
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
|
expect(loadedPackages).toContain(pack)
|
|
|
|
|
expect(activatedPackages).toContain(pack)
|
|
|
|
|
expect(atom.config.get('core.disabledPackages')).not.toContain packageName
|
2013-10-22 03:13:04 +04:00
|
|
|
|
|
|
|
|
|
it ".disablePackage() disables an enabled package", ->
|
|
|
|
|
packageName = 'package-with-main'
|
2014-02-07 23:21:52 +04:00
|
|
|
|
waitsForPromise ->
|
|
|
|
|
atom.packages.activatePackage(packageName)
|
2013-10-22 03:13:04 +04:00
|
|
|
|
|
2014-02-07 23:21:52 +04:00
|
|
|
|
runs ->
|
|
|
|
|
atom.packages.observeDisabledPackages()
|
|
|
|
|
expect(atom.config.get('core.disabledPackages')).not.toContain packageName
|
2013-10-22 03:13:04 +04:00
|
|
|
|
|
2014-02-07 23:21:52 +04:00
|
|
|
|
pack = atom.packages.disablePackage(packageName)
|
|
|
|
|
|
|
|
|
|
activatedPackages = atom.packages.getActivePackages()
|
|
|
|
|
expect(activatedPackages).not.toContain(pack)
|
|
|
|
|
expect(atom.config.get('core.disabledPackages')).toContain packageName
|
2013-10-22 03:13:04 +04:00
|
|
|
|
|
|
|
|
|
describe "with themes", ->
|
|
|
|
|
beforeEach ->
|
2014-02-07 23:21:52 +04:00
|
|
|
|
waitsForPromise ->
|
|
|
|
|
atom.themes.activateThemes()
|
2013-10-22 03:13:04 +04:00
|
|
|
|
|
|
|
|
|
afterEach ->
|
|
|
|
|
atom.themes.deactivateThemes()
|
|
|
|
|
atom.config.unobserve('core.themes')
|
|
|
|
|
|
|
|
|
|
it ".enablePackage() and .disablePackage() enables and disables a theme", ->
|
|
|
|
|
packageName = 'theme-with-package-file'
|
|
|
|
|
|
2013-11-11 21:16:44 +04:00
|
|
|
|
expect(atom.config.get('core.themes')).not.toContain packageName
|
|
|
|
|
expect(atom.config.get('core.disabledPackages')).not.toContain packageName
|
2013-10-22 03:13:04 +04:00
|
|
|
|
|
|
|
|
|
# enabling of theme
|
|
|
|
|
pack = atom.packages.enablePackage(packageName)
|
|
|
|
|
|
2014-05-17 01:05:44 +04:00
|
|
|
|
waitsFor ->
|
|
|
|
|
pack in atom.packages.getActivePackages()
|
2014-02-07 23:21:52 +04:00
|
|
|
|
|
|
|
|
|
runs ->
|
|
|
|
|
expect(atom.config.get('core.themes')).toContain packageName
|
|
|
|
|
expect(atom.config.get('core.disabledPackages')).not.toContain packageName
|
|
|
|
|
|
|
|
|
|
# disabling of theme
|
|
|
|
|
pack = atom.packages.disablePackage(packageName)
|
2014-05-16 18:33:28 +04:00
|
|
|
|
|
2014-05-17 01:05:44 +04:00
|
|
|
|
waitsFor ->
|
|
|
|
|
not (pack in atom.packages.getActivePackages())
|
2014-05-16 18:33:28 +04:00
|
|
|
|
|
|
|
|
|
runs ->
|
2014-02-07 23:21:52 +04:00
|
|
|
|
expect(atom.config.get('core.themes')).not.toContain packageName
|
|
|
|
|
expect(atom.config.get('core.themes')).not.toContain packageName
|
|
|
|
|
expect(atom.config.get('core.disabledPackages')).not.toContain packageName
|
2013-12-12 00:28:20 +04:00
|
|
|
|
|
|
|
|
|
describe ".isReleasedVersion()", ->
|
|
|
|
|
it "returns false if the version is a SHA and true otherwise", ->
|
|
|
|
|
version = '0.1.0'
|
2013-12-12 08:37:52 +04:00
|
|
|
|
spyOn(atom.constructor, 'getVersion').andCallFake -> version
|
2013-12-12 00:28:20 +04:00
|
|
|
|
expect(atom.isReleasedVersion()).toBe true
|
|
|
|
|
version = '36b5518'
|
|
|
|
|
expect(atom.isReleasedVersion()).toBe false
|