2015-05-13 23:42:35 +00:00
|
|
|
/*****************************************************************************
|
2016-07-12 23:21:58 +00:00
|
|
|
* Open MCT, Copyright (c) 2014-2016, United States Government
|
2015-05-13 23:42:35 +00:00
|
|
|
* as represented by the Administrator of the National Aeronautics and Space
|
|
|
|
* Administration. All rights reserved.
|
|
|
|
*
|
2016-07-12 23:21:58 +00:00
|
|
|
* Open MCT is licensed under the Apache License, Version 2.0 (the
|
2015-05-13 23:42:35 +00:00
|
|
|
* "License"); you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0.
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
|
|
|
*
|
2016-07-12 23:21:58 +00:00
|
|
|
* Open MCT includes source code licensed under additional open source
|
2015-05-13 23:42:35 +00:00
|
|
|
* licenses. See the Open Source Licenses file (LICENSES.md) included with
|
|
|
|
* this source code distribution or the Licensing information page available
|
|
|
|
* at runtime from the About dialog for additional information.
|
|
|
|
*****************************************************************************/
|
2014-11-06 16:03:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ExtensionResolverSpec. Created by vwoeltje on 11/6/14.
|
|
|
|
*/
|
|
|
|
define(
|
2014-11-07 03:20:51 +00:00
|
|
|
["../../src/resolve/ExtensionResolver", "../../src/load/Bundle"],
|
|
|
|
function (ExtensionResolver, Bundle) {
|
2014-11-06 16:03:35 +00:00
|
|
|
|
|
|
|
describe("", function () {
|
2014-11-07 03:20:51 +00:00
|
|
|
var mockLoader,
|
|
|
|
mockLog,
|
|
|
|
resolver;
|
|
|
|
|
|
|
|
// Test implementation, to load from the mock loader
|
2016-05-19 18:29:13 +00:00
|
|
|
function Constructor() {
|
|
|
|
return { someKey: "some value" };
|
|
|
|
}
|
2014-11-20 18:56:21 +00:00
|
|
|
Constructor.someProperty = "some static value";
|
2014-11-07 03:20:51 +00:00
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
mockLoader = jasmine.createSpyObj("loader", ["load"]);
|
|
|
|
|
|
|
|
mockLog = jasmine.createSpyObj(
|
|
|
|
"$log",
|
|
|
|
["error", "warn", "info", "debug"]
|
|
|
|
);
|
|
|
|
|
|
|
|
mockLoader.load.andReturn(Promise.resolve(Constructor));
|
|
|
|
|
|
|
|
resolver = new ExtensionResolver(mockLoader, mockLog);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("requests implementations from the implementation loader", function () {
|
|
|
|
var bundle = new Bundle("w", {
|
|
|
|
sources: "x",
|
2016-05-19 18:29:13 +00:00
|
|
|
extensions: { tests: [{ implementation: "y/z.js" }] }
|
2014-11-07 03:20:51 +00:00
|
|
|
}),
|
|
|
|
extension = bundle.getExtensions("tests")[0],
|
|
|
|
result;
|
|
|
|
|
2016-05-19 18:29:13 +00:00
|
|
|
resolver.resolve(extension).then(function (v) {
|
|
|
|
result = v;
|
|
|
|
});
|
2014-11-07 03:20:51 +00:00
|
|
|
|
|
|
|
waitsFor(
|
2016-05-19 18:29:13 +00:00
|
|
|
function () {
|
|
|
|
return result !== undefined;
|
|
|
|
},
|
|
|
|
"promise resolution",
|
|
|
|
250
|
|
|
|
);
|
2014-11-07 03:20:51 +00:00
|
|
|
|
|
|
|
runs(function () {
|
|
|
|
// Verify that the right file was requested
|
|
|
|
expect(mockLoader.load).toHaveBeenCalledWith("w/x/y/z.js");
|
|
|
|
|
|
|
|
// We should have resolved to the constructor from above
|
|
|
|
expect(typeof result).toEqual('function');
|
|
|
|
expect(result().someKey).toEqual("some value");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it("issues a warning and defaults to plain definition if load fails", function () {
|
|
|
|
var bundle = new Bundle("w", {
|
|
|
|
sources: "x",
|
2016-05-19 18:29:13 +00:00
|
|
|
extensions: { tests: [{
|
2014-11-07 03:20:51 +00:00
|
|
|
someOtherKey: "some other value",
|
|
|
|
implementation: "y/z.js"
|
2016-05-19 18:29:13 +00:00
|
|
|
}] }
|
2014-11-07 03:20:51 +00:00
|
|
|
}),
|
|
|
|
extension = bundle.getExtensions("tests")[0],
|
|
|
|
result;
|
|
|
|
|
|
|
|
mockLoader.load.andReturn(Promise.reject(new Error("test error")));
|
2016-05-19 18:29:13 +00:00
|
|
|
resolver.resolve(extension).then(function (v) {
|
|
|
|
result = v;
|
|
|
|
});
|
2014-11-07 03:20:51 +00:00
|
|
|
|
|
|
|
waitsFor(
|
2016-05-19 18:29:13 +00:00
|
|
|
function () {
|
|
|
|
return result !== undefined;
|
|
|
|
},
|
|
|
|
"promise resolution",
|
|
|
|
250
|
|
|
|
);
|
2014-11-07 03:20:51 +00:00
|
|
|
|
|
|
|
runs(function () {
|
|
|
|
// Should have gotten a warning
|
|
|
|
expect(mockLog.warn).toHaveBeenCalled();
|
|
|
|
|
|
|
|
// We should have resolved to the plain definition from above
|
|
|
|
expect(typeof result).not.toEqual('function');
|
|
|
|
expect(result.someOtherKey).toEqual("some other value");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-11-20 18:56:21 +00:00
|
|
|
it("ensures implementation properties are exposed", function () {
|
|
|
|
var bundle = new Bundle("w", {
|
|
|
|
sources: "x",
|
2016-05-19 18:29:13 +00:00
|
|
|
extensions: { tests: [{ implementation: "y/z.js" }] }
|
2014-11-20 18:56:21 +00:00
|
|
|
}),
|
|
|
|
extension = bundle.getExtensions("tests")[0],
|
|
|
|
result;
|
|
|
|
|
2016-05-19 18:29:13 +00:00
|
|
|
resolver.resolve(extension).then(function (v) {
|
|
|
|
result = v;
|
|
|
|
});
|
2014-11-20 18:56:21 +00:00
|
|
|
|
|
|
|
waitsFor(
|
2016-05-19 18:29:13 +00:00
|
|
|
function () {
|
|
|
|
return result !== undefined;
|
|
|
|
},
|
|
|
|
"promise resolution",
|
|
|
|
250
|
|
|
|
);
|
2014-11-20 18:56:21 +00:00
|
|
|
|
|
|
|
runs(function () {
|
|
|
|
// Verify that the right file was requested
|
|
|
|
expect(mockLoader.load).toHaveBeenCalledWith("w/x/y/z.js");
|
|
|
|
|
|
|
|
// We should have resolved to the constructor from above
|
|
|
|
expect(typeof result).toEqual('function');
|
|
|
|
expect(result().someKey).toEqual("some value");
|
|
|
|
expect(result.someProperty).toEqual("some static value");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-11-06 16:03:35 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
}
|
2016-05-19 18:29:13 +00:00
|
|
|
);
|