Add specs for workspaceOpeners

This commit is contained in:
Wliu
2017-11-15 00:53:56 +01:00
parent 2eb9fc184b
commit c747711be5
5 changed files with 49 additions and 0 deletions

View File

@@ -0,0 +1 @@
module.exports = activate: ->

View File

@@ -0,0 +1,5 @@
{
"name": "package-with-empty-workspace-openers",
"version": "0.1.0",
"workspaceOpeners": []
}

View File

@@ -0,0 +1,9 @@
module.exports =
activateCallCount: 0
openerCount: 0
activate: ->
@activateCallCount++
atom.workspace.addOpener (filePath) =>
if filePath is 'atom://fictitious'
@openerCount++

View File

@@ -0,0 +1,5 @@
{
"name": "package-with-workspace-openers",
"version": "0.1.0",
"workspaceOpeners": ['atom://fictitious']
}

View File

@@ -772,6 +772,35 @@ describe('PackageManager', () => {
})
})
describe('when the package metadata includes `workspaceOpeners`', () => {
let mainModule, promise
beforeEach(() => {
mainModule = require('./fixtures/packages/package-with-workspace-openers/index')
spyOn(mainModule, 'activate').andCallThrough()
spyOn(Package.prototype, 'requireMainModule').andCallThrough()
})
it('defers requiring/activating the main module until a registered opener is called', async () => {
promise = atom.packages.activatePackage('package-with-workspace-openers')
expect(Package.prototype.requireMainModule.callCount).toBe(0)
atom.workspace.open('atom://fictitious')
await promise
expect(Package.prototype.requireMainModule.callCount).toBe(1)
expect(mainModule.openerCount).toBe(1)
})
it('activates the package immediately when the events are empty', async () => {
mainModule = require('./fixtures/packages/package-with-empty-workspace-openers/index')
spyOn(mainModule, 'activate').andCallThrough()
atom.packages.activatePackage('package-with-empty-workspace-openers')
expect(mainModule.activate.callCount).toBe(1)
})
})
describe('when the package has no main module', () => {
it('does not throw an exception', () => {
spyOn(console, 'error')