Switch specs to use activationCommands instead of activationEvents

The activationEvents are converted to the same format as
activationCommands, and that property will be deprecated.
This commit is contained in:
Nathan Sobo
2014-09-23 18:28:08 -06:00
parent 63181a17c8
commit 47f8f7eb11
7 changed files with 28 additions and 50 deletions

View File

@@ -1,2 +1,13 @@
module.exports =
activateCallCount: 0
activationCommandCallCount: 0
legacyActivationCommandCallCount: 0
activate: ->
@activateCallCount++
atom.commands.add '.workspace', 'activation-command', =>
@activationCommandCallCount++
atom.workspaceView.getActiveView()?.command 'activation-command', =>
@legacyActivationCommandCallCount++

View File

@@ -1,3 +1,2 @@
activationCommands:
'.workspace': 'workspace-command'
'.editor': ['editor-command-1', 'editor-command-2']
'activationCommands':
'.workspace': 'activation-command'

View File

@@ -1,16 +0,0 @@
class Foo
atom.deserializers.add(this)
@deserialize: ({data}) -> new Foo(data)
constructor: (@data) ->
module.exports =
activateCallCount: 0
activationEventCallCount: 0
activationCommandCallCount: 0
activate: ->
@activateCallCount++
atom.workspaceView.getActiveView()?.command 'activation-event', =>
@activationEventCallCount++
atom.commands.add '.workspace', 'activation-event', =>
@activationCommandCallCount++

View File

@@ -1 +0,0 @@
'activationEvents': ['activation-event']

View File

@@ -1,5 +1,5 @@
{
"name": "no events",
"version": "0.1.0",
"activationEvents": []
"activationCommands": {".workspace": []}
}

View File

@@ -92,25 +92,25 @@ describe "PackageManager", ->
expect(atom.config.get('package-with-config-defaults.numbers.one')).toBe 1
expect(atom.config.get('package-with-config-defaults.numbers.two')).toBe 2
describe "when the package metadata includes `activationEvents`", ->
describe "when the package metadata includes `activationCommands`", ->
[mainModule, promise, workspaceCommandListener] = []
beforeEach ->
atom.workspaceView.attachToDom()
mainModule = require './fixtures/packages/package-with-activation-events/index'
mainModule.activationEventCallCount = 0
mainModule = require './fixtures/packages/package-with-activation-commands/index'
mainModule.legacyActivationCommandCallCount = 0
mainModule.activationCommandCallCount = 0
spyOn(mainModule, 'activate').andCallThrough()
spyOn(Package.prototype, 'requireMainModule').andCallThrough()
workspaceCommandListener = jasmine.createSpy('workspaceCommandListener')
atom.commands.add '.workspace', 'activation-event', workspaceCommandListener
atom.commands.add '.workspace', 'activation-command', workspaceCommandListener
promise = atom.packages.activatePackage('package-with-activation-events')
promise = atom.packages.activatePackage('package-with-activation-commands')
it "defers requiring/activating the main module until an activation event bubbles to the root view", ->
expect(promise.isFulfilled()).not.toBeTruthy()
atom.workspaceView[0].dispatchEvent(new CustomEvent('activation-event', bubbles: true))
atom.workspaceView[0].dispatchEvent(new CustomEvent('activation-command', bubbles: true))
waitsForPromise ->
promise
@@ -122,18 +122,18 @@ describe "PackageManager", ->
runs ->
editorView = atom.workspaceView.getActiveView()
legacyCommandListener = jasmine.createSpy("legacyCommandListener")
editorView.command 'activation-event', legacyCommandListener
editorView.command 'activation-command', legacyCommandListener
editorCommandListener = jasmine.createSpy("editorCommandListener")
atom.commands.add '.editor', 'activation-event', editorCommandListener
editorView[0].dispatchEvent(new CustomEvent('activation-event', bubbles: true))
atom.commands.add '.editor', 'activation-command', editorCommandListener
editorView[0].dispatchEvent(new CustomEvent('activation-command', bubbles: true))
expect(mainModule.activate.callCount).toBe 1
expect(mainModule.activationEventCallCount).toBe 1
expect(mainModule.legacyActivationCommandCallCount).toBe 1
expect(mainModule.activationCommandCallCount).toBe 1
expect(legacyCommandListener.callCount).toBe 1
expect(editorCommandListener.callCount).toBe 1
expect(workspaceCommandListener.callCount).toBe 1
editorView[0].dispatchEvent(new CustomEvent('activation-event', bubbles: true))
expect(mainModule.activationEventCallCount).toBe 2
editorView[0].dispatchEvent(new CustomEvent('activation-command', bubbles: true))
expect(mainModule.legacyActivationCommandCallCount).toBe 2
expect(mainModule.activationCommandCallCount).toBe 2
expect(legacyCommandListener.callCount).toBe 2
expect(editorCommandListener.callCount).toBe 2
@@ -141,30 +141,15 @@ describe "PackageManager", ->
expect(mainModule.activate.callCount).toBe 1
it "activates the package immediately when the events are empty", ->
mainModule = require './fixtures/packages/package-with-empty-activation-events/index'
mainModule = require './fixtures/packages/package-with-empty-activation-commands/index'
spyOn(mainModule, 'activate').andCallThrough()
waitsForPromise ->
atom.packages.activatePackage('package-with-empty-activation-events')
atom.packages.activatePackage('package-with-empty-activation-commands')
runs ->
expect(mainModule.activate.callCount).toBe 1
describe "when the package metadata includes `activationCommands`", ->
it "defers activation until one of the commands is invoked", ->
atom.workspaceView.attachToDom()
mainModule = require './fixtures/packages/package-with-activation-commands/index'
mainModule.commands = []
spyOn(mainModule, 'activate').andCallThrough()
spyOn(Package.prototype, 'requireMainModule').andCallThrough()
promise = atom.packages.activatePackage('package-with-activation-commands')
expect(promise.isFulfilled()).not.toBeTruthy()
atom.workspaceView[0].dispatchEvent(new CustomEvent('workspace-command', bubbles: true))
waitsForPromise -> promise
describe "when the package has no main module", ->
it "does not throw an exception", ->
spyOn(console, "error")