forked from PolymerLabs/arcs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduces a StubLoader for tests (PolymerLabs#1387)
- Loading branch information
1 parent
bec3d58
commit f288ce5
Showing
8 changed files
with
72 additions
and
73 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* @license | ||
* Copyright (c) 2018 Google Inc. All rights reserved. | ||
* This code may only be used under the BSD style license found at | ||
* http://polymer.github.io/LICENSE.txt | ||
* Code distributed by Google as part of this project is also | ||
* subject to an additional IP rights grant found at | ||
* http://polymer.github.io/PATENTS.txt | ||
*/ | ||
import {Loader} from '../loader.js'; | ||
|
||
/** @class StubLoader | ||
* A Loader initialized with a per-path canned responses. | ||
* Value for '*' key can be specified for a response if the path did not match. | ||
* If '*' is not specified and path is not matched, Loader logic is invoked. | ||
*/ | ||
export class StubLoader extends Loader { | ||
constructor(fileMap) { | ||
super(); | ||
this._fileMap = fileMap; | ||
if (fileMap.hasOwnProperty('*')) { | ||
this._cannedResponse = fileMap['*']; | ||
} | ||
} | ||
loadResource(path) { | ||
return this._fileMap.hasOwnProperty(path) | ||
? this._fileMap[path] | ||
: (this._cannedResponse || super.loadResource(path)); | ||
} | ||
path(fileName) { | ||
return (this._fileMap.hasOwnProperty(fileName) || this._cannedResponse) | ||
? fileName | ||
: super.path(fileName); | ||
} | ||
join(prefix, path) { | ||
// If referring from stubbed content, don't prepend stubbed filename. | ||
return (this._fileMap.hasOwnProperty(prefix) || this._cannedResponse) | ||
? path | ||
: super.join(prefix, path); | ||
} | ||
} |
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