-
-
Notifications
You must be signed in to change notification settings - Fork 735
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move
addSourceType
to global object (#3420)
* Move add source type to global object * Update CHANGELOG * Fix docs
- Loading branch information
Showing
8 changed files
with
85 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import {Dispatcher} from '../util/dispatcher'; | ||
import {SourceClass, addSourceType, create} from './source'; | ||
|
||
describe('addSourceType', () => { | ||
test('adds factory function without a worker url does not dispatch to worker', async () => { | ||
const sourceType = jest.fn().mockImplementation(function (id) { this.id = id; }) as SourceClass; | ||
|
||
// expect no call to load worker source | ||
const spy = jest.spyOn(Dispatcher.prototype, 'broadcast'); | ||
|
||
await addSourceType('foo', sourceType); | ||
expect(spy).not.toHaveBeenCalled(); | ||
|
||
create('id', {type: 'foo'} as any, null, null); | ||
expect(sourceType).toHaveBeenCalled(); | ||
}); | ||
|
||
test('create a custom source without an id throws', async () => { | ||
const sourceType = jest.fn() as SourceClass; | ||
|
||
// expect no call to load worker source | ||
const spy = jest.spyOn(Dispatcher.prototype, 'broadcast'); | ||
|
||
await addSourceType('foo2', sourceType); | ||
expect(spy).not.toHaveBeenCalled(); | ||
|
||
expect(() => create('id', {type: 'foo2'} as any, null, null)).toThrow(); | ||
expect(sourceType).toHaveBeenCalled(); | ||
}); | ||
|
||
test('triggers workers to load worker source code', async () => { | ||
const sourceType = function () {} as any as SourceClass; | ||
sourceType.workerSourceURL = 'worker-source.js' as any as URL; | ||
|
||
const spy = jest.spyOn(Dispatcher.prototype, 'broadcast'); | ||
|
||
await addSourceType('bar', sourceType); | ||
expect(spy).toHaveBeenCalledWith('loadWorkerSource', 'worker-source.js'); | ||
}); | ||
|
||
test('refuses to add new type over existing name', async () => { | ||
const sourceType = function () {} as any as SourceClass; | ||
await expect(addSourceType('canvas', sourceType)).rejects.toThrow(); | ||
await expect(addSourceType('geojson', sourceType)).rejects.toThrow(); | ||
await expect(addSourceType('image', sourceType)).rejects.toThrow(); | ||
await expect(addSourceType('raster', sourceType)).rejects.toThrow(); | ||
await expect(addSourceType('raster-dem', sourceType)).rejects.toThrow(); | ||
await expect(addSourceType('vector', sourceType)).rejects.toThrow(); | ||
await expect(addSourceType('video', sourceType)).rejects.toThrow(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters