mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Add specs for workspaceOpeners
This commit is contained in:
1
spec/fixtures/packages/package-with-empty-workspace-openers/index.coffee
vendored
Normal file
1
spec/fixtures/packages/package-with-empty-workspace-openers/index.coffee
vendored
Normal file
@@ -0,0 +1 @@
|
||||
module.exports = activate: ->
|
||||
5
spec/fixtures/packages/package-with-empty-workspace-openers/package.json
vendored
Normal file
5
spec/fixtures/packages/package-with-empty-workspace-openers/package.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "package-with-empty-workspace-openers",
|
||||
"version": "0.1.0",
|
||||
"workspaceOpeners": []
|
||||
}
|
||||
9
spec/fixtures/packages/package-with-workspace-openers/index.coffee
vendored
Normal file
9
spec/fixtures/packages/package-with-workspace-openers/index.coffee
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
module.exports =
|
||||
activateCallCount: 0
|
||||
openerCount: 0
|
||||
|
||||
activate: ->
|
||||
@activateCallCount++
|
||||
atom.workspace.addOpener (filePath) =>
|
||||
if filePath is 'atom://fictitious'
|
||||
@openerCount++
|
||||
5
spec/fixtures/packages/package-with-workspace-openers/package.cson
vendored
Normal file
5
spec/fixtures/packages/package-with-workspace-openers/package.cson
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "package-with-workspace-openers",
|
||||
"version": "0.1.0",
|
||||
"workspaceOpeners": ['atom://fictitious']
|
||||
}
|
||||
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user