2012-12-19 06:47:20 +04:00
|
|
|
RootView = require 'root-view'
|
2013-01-04 02:10:11 +04:00
|
|
|
{$$} = require 'space-pen'
|
2012-12-19 06:47:20 +04:00
|
|
|
|
2013-02-08 02:37:48 +04:00
|
|
|
describe "the `atom` global", ->
|
2013-02-08 00:17:34 +04:00
|
|
|
beforeEach ->
|
2013-02-20 04:18:25 +04:00
|
|
|
window.rootView = new RootView
|
2013-02-08 23:51:51 +04:00
|
|
|
|
2013-02-14 04:29:51 +04:00
|
|
|
describe "when a package is built and loaded", ->
|
2013-01-03 04:40:03 +04:00
|
|
|
[extension, stylesheetPath] = []
|
2012-12-19 06:47:20 +04:00
|
|
|
|
|
|
|
beforeEach ->
|
2012-12-20 06:24:44 +04:00
|
|
|
extension = require "package-with-module"
|
2013-01-03 04:40:03 +04:00
|
|
|
stylesheetPath = require.resolve("fixtures/packages/package-with-module/stylesheets/styles.css")
|
|
|
|
|
|
|
|
afterEach ->
|
|
|
|
removeStylesheet(stylesheetPath)
|
2012-12-19 06:47:20 +04:00
|
|
|
|
|
|
|
it "requires and activates the package's main module if it exists", ->
|
2013-02-09 05:19:45 +04:00
|
|
|
spyOn(atom, 'activateAtomPackage').andCallThrough()
|
2013-02-14 04:29:51 +04:00
|
|
|
window.loadPackage("package-with-module")
|
2013-02-09 05:19:45 +04:00
|
|
|
expect(atom.activateAtomPackage).toHaveBeenCalled()
|
2013-01-03 04:40:03 +04:00
|
|
|
|
2013-01-09 21:20:19 +04:00
|
|
|
it "logs warning instead of throwing an exception if a package fails to load", ->
|
2013-01-27 23:12:39 +04:00
|
|
|
config.set("core.disabledPackages", [])
|
2013-01-09 21:20:19 +04:00
|
|
|
spyOn(console, "warn")
|
2013-02-14 04:29:51 +04:00
|
|
|
expect(-> window.loadPackage("package-that-throws-an-exception")).not.toThrow()
|
2013-01-09 21:20:19 +04:00
|
|
|
expect(console.warn).toHaveBeenCalled()
|
|
|
|
|
2013-01-04 02:10:11 +04:00
|
|
|
describe "keymap loading", ->
|
|
|
|
describe "when package.json does not contain a 'keymaps' manifest", ->
|
2013-02-15 00:33:33 +04:00
|
|
|
it "loads all the .cson/.json files in the keymaps directory", ->
|
2013-01-04 02:10:11 +04:00
|
|
|
element1 = $$ -> @div class: 'test-1'
|
|
|
|
element2 = $$ -> @div class: 'test-2'
|
2013-02-01 00:01:02 +04:00
|
|
|
element3 = $$ -> @div class: 'test-3'
|
2013-01-04 02:10:11 +04:00
|
|
|
|
|
|
|
expect(keymap.bindingsForElement(element1)['ctrl-z']).toBeUndefined()
|
|
|
|
expect(keymap.bindingsForElement(element2)['ctrl-z']).toBeUndefined()
|
2013-02-01 00:01:02 +04:00
|
|
|
expect(keymap.bindingsForElement(element3)['ctrl-z']).toBeUndefined()
|
2013-01-04 02:10:11 +04:00
|
|
|
|
2013-02-14 04:29:51 +04:00
|
|
|
window.loadPackage("package-with-module")
|
2013-01-04 02:10:11 +04:00
|
|
|
|
2013-02-15 01:23:45 +04:00
|
|
|
expect(keymap.bindingsForElement(element1)['ctrl-z']).toBe "test-1"
|
|
|
|
expect(keymap.bindingsForElement(element2)['ctrl-z']).toBe "test-2"
|
2013-02-01 00:01:02 +04:00
|
|
|
expect(keymap.bindingsForElement(element3)['ctrl-z']).toBeUndefined()
|
2013-01-04 02:10:11 +04:00
|
|
|
|
|
|
|
describe "when package.json contains a 'keymaps' manifest", ->
|
|
|
|
it "loads only the keymaps specified by the manifest, in the specified order", ->
|
|
|
|
element1 = $$ -> @div class: 'test-1'
|
|
|
|
element3 = $$ -> @div class: 'test-3'
|
|
|
|
|
|
|
|
expect(keymap.bindingsForElement(element1)['ctrl-z']).toBeUndefined()
|
|
|
|
|
2013-02-14 04:29:51 +04:00
|
|
|
window.loadPackage("package-with-keymaps-manifest")
|
2013-01-04 02:10:11 +04:00
|
|
|
|
|
|
|
expect(keymap.bindingsForElement(element1)['ctrl-z']).toBe 'keymap-1'
|
|
|
|
expect(keymap.bindingsForElement(element1)['ctrl-n']).toBe 'keymap-2'
|
|
|
|
expect(keymap.bindingsForElement(element3)['ctrl-y']).toBeUndefined()
|
|
|
|
|
2013-01-03 04:40:03 +04:00
|
|
|
it "loads stylesheets associated with the package", ->
|
|
|
|
stylesheetPath = require.resolve("fixtures/packages/package-with-module/stylesheets/styles.css")
|
|
|
|
expect(stylesheetElementForId(stylesheetPath).length).toBe 0
|
2013-02-14 04:29:51 +04:00
|
|
|
window.loadPackage("package-with-module")
|
2013-01-03 04:40:03 +04:00
|
|
|
expect(stylesheetElementForId(stylesheetPath).length).toBe 1
|
2013-01-28 10:38:11 +04:00
|
|
|
|
|
|
|
describe ".loadPackages()", ->
|
|
|
|
beforeEach ->
|
2013-01-29 02:23:16 +04:00
|
|
|
spyOn(syntax, 'addGrammar')
|
|
|
|
|
2013-02-20 00:12:29 +04:00
|
|
|
it "aborts the worker when all packages have been loaded", ->
|
|
|
|
LoadTextMatePackagesTask = require 'load-text-mate-packages-task'
|
|
|
|
spyOn(LoadTextMatePackagesTask.prototype, 'abort').andCallThrough()
|
2013-01-28 10:38:11 +04:00
|
|
|
eventHandler = jasmine.createSpy('eventHandler')
|
2013-01-29 02:34:45 +04:00
|
|
|
syntax.on 'grammars-loaded', eventHandler
|
2013-02-20 00:12:29 +04:00
|
|
|
config.get("core.disabledPackages").push('textmate-package.tmbundle', 'package-with-snippets')
|
2013-01-28 10:38:11 +04:00
|
|
|
atom.loadPackages()
|
|
|
|
|
|
|
|
waitsFor "all packages to load", 5000, -> eventHandler.callCount > 0
|
|
|
|
|
|
|
|
runs ->
|
2013-02-20 00:12:29 +04:00
|
|
|
expect(LoadTextMatePackagesTask.prototype.abort).toHaveBeenCalled()
|
|
|
|
expect(LoadTextMatePackagesTask.prototype.abort.calls.length).toBe 1
|
2013-02-09 05:19:45 +04:00
|
|
|
|
|
|
|
describe "package lifecycle", ->
|
2013-02-14 04:32:50 +04:00
|
|
|
describe "activation", ->
|
|
|
|
it "calls activate on the package main with its previous state", ->
|
|
|
|
pack = window.loadPackage('package-with-module')
|
|
|
|
spyOn(pack.packageMain, 'activate')
|
2013-02-09 05:19:45 +04:00
|
|
|
|
|
|
|
serializedState = rootView.serialize()
|
|
|
|
rootView.deactivate()
|
|
|
|
RootView.deserialize(serializedState)
|
2013-02-14 04:32:50 +04:00
|
|
|
window.loadPackage('package-with-module')
|
2013-02-09 05:19:45 +04:00
|
|
|
|
2013-02-14 04:32:50 +04:00
|
|
|
expect(pack.packageMain.activate).toHaveBeenCalledWith(someNumber: 1)
|
2013-02-09 05:19:45 +04:00
|
|
|
|
2013-02-14 04:32:50 +04:00
|
|
|
describe "deactivation", ->
|
2013-02-09 05:19:45 +04:00
|
|
|
it "deactivates and removes the package module from the package module map", ->
|
2013-02-14 04:32:50 +04:00
|
|
|
pack = window.loadPackage('package-with-module')
|
2013-02-13 03:47:31 +04:00
|
|
|
expect(atom.activatedAtomPackages.length).toBe 1
|
2013-02-14 04:32:50 +04:00
|
|
|
spyOn(pack.packageMain, "deactivate").andCallThrough()
|
2013-02-09 05:19:45 +04:00
|
|
|
atom.deactivateAtomPackages()
|
2013-02-14 04:32:50 +04:00
|
|
|
expect(pack.packageMain.deactivate).toHaveBeenCalled()
|
2013-02-13 03:47:31 +04:00
|
|
|
expect(atom.activatedAtomPackages.length).toBe 0
|
2013-02-09 05:19:45 +04:00
|
|
|
|
2013-02-14 04:32:50 +04:00
|
|
|
describe "serialization", ->
|
|
|
|
it "uses previous serialization state on unactivated packages", ->
|
|
|
|
atom.atomPackageStates['package-with-activation-events'] = {previousData: 'exists'}
|
|
|
|
unactivatedPackage = window.loadPackage('package-with-activation-events')
|
|
|
|
activatedPackage = window.loadPackage('package-with-module')
|
|
|
|
|
|
|
|
expect(atom.serializeAtomPackages()).toEqual
|
|
|
|
'package-with-module':
|
|
|
|
'someNumber': 1
|
|
|
|
'package-with-activation-events':
|
|
|
|
'previousData': 'exists'
|
|
|
|
|
|
|
|
# ensure serialization occurs when the packageis activated
|
|
|
|
unactivatedPackage.activatePackageMain()
|
|
|
|
expect(atom.serializeAtomPackages()).toEqual
|
|
|
|
'package-with-module':
|
|
|
|
'someNumber': 1
|
|
|
|
'package-with-activation-events':
|
|
|
|
'previousData': 'overwritten'
|
|
|
|
|
2013-02-09 05:19:45 +04:00
|
|
|
it "absorbs exceptions that are thrown by the package module's serialize methods", ->
|
|
|
|
spyOn(console, 'error')
|
2013-02-14 04:32:50 +04:00
|
|
|
window.loadPackage('package-with-module')
|
|
|
|
window.loadPackage('package-with-serialize-error', activateImmediately: true)
|
2013-02-09 05:19:45 +04:00
|
|
|
|
|
|
|
packageStates = atom.serializeAtomPackages()
|
2013-02-14 04:32:50 +04:00
|
|
|
expect(packageStates['package-with-module']).toEqual someNumber: 1
|
|
|
|
expect(packageStates['package-with-serialize-error']).toBeUndefined()
|
2013-02-09 05:19:45 +04:00
|
|
|
expect(console.error).toHaveBeenCalled()
|