mirror of
https://github.com/atom/atom.git
synced 2026-01-24 14:28:14 -05:00
Add tests for packages with URI handlers
This commit is contained in:
5
spec/fixtures/packages/package-with-url-handler/index.js
vendored
Normal file
5
spec/fixtures/packages/package-with-url-handler/index.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
module.exports = {
|
||||
activate: () => null,
|
||||
deactivate: () => null,
|
||||
handleUrl: () => null,
|
||||
}
|
||||
6
spec/fixtures/packages/package-with-url-handler/package.json
vendored
Normal file
6
spec/fixtures/packages/package-with-url-handler/package.json
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"name": "package-with-url-handler",
|
||||
"urlHandler": {
|
||||
"method": "handleUrl"
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
const path = require('path')
|
||||
const url = require('url')
|
||||
const Package = require('../src/package')
|
||||
const PackageManager = require('../src/package-manager')
|
||||
const temp = require('temp').track()
|
||||
@@ -1038,6 +1039,20 @@ describe('PackageManager', () => {
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
describe("URL handler registration", () => {
|
||||
it("registers the package's specified URL handler", async () => {
|
||||
const uri = 'atom://package-with-url-handler/some/url?with=args'
|
||||
const mod = require('./fixtures/packages/package-with-url-handler')
|
||||
spyOn(mod, 'handleUrl')
|
||||
spyOn(atom.packages, 'hasLoadedInitialPackages').andReturn(true)
|
||||
const activationPromise = atom.packages.activatePackage('package-with-url-handler')
|
||||
atom.dispatchUrlMessage(uri)
|
||||
await activationPromise
|
||||
expect(mod.handleUrl).toHaveBeenCalledWith(url.parse(uri, true), uri)
|
||||
})
|
||||
})
|
||||
|
||||
describe('service registration', () => {
|
||||
it("registers the package's provided and consumed services", async () => {
|
||||
const consumerModule = require('./fixtures/packages/package-with-consumed-services')
|
||||
|
||||
@@ -323,15 +323,15 @@ class Package
|
||||
registerUrlHandler: ->
|
||||
handlerConfig = @getUrlHandler()
|
||||
if methodName = handlerConfig?.method
|
||||
@urlHandlerSubscription = @packageManager.registerUrlHandlerForPackage @name, (url) =>
|
||||
@handleUrl(url, methodName)
|
||||
@urlHandlerSubscription = @packageManager.registerUrlHandlerForPackage @name, (args...) =>
|
||||
@handleUrl(methodName, args)
|
||||
|
||||
unregisterUrlHandler: ->
|
||||
@urlHandlerSubscription?.dispose()
|
||||
|
||||
handleUrl: (url, methodName) ->
|
||||
handleUrl: (methodName, args) ->
|
||||
@activate().then =>
|
||||
@mainModule[methodName]?(url)
|
||||
@mainModule[methodName]?.apply(@mainModule, args)
|
||||
unless @mainActivated
|
||||
@activateNow()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user