mirror of
https://github.com/nasa/openmct.git
synced 2025-02-20 17:33:23 +00:00
Merge remote-tracking branch 'origin/open660' into open-master
This commit is contained in:
commit
26cd5b3e24
@ -160,6 +160,12 @@
|
||||
"depends": [ "$q" ]
|
||||
}
|
||||
],
|
||||
"services": [
|
||||
{
|
||||
"key": "now",
|
||||
"implementation": "services/Now.js"
|
||||
}
|
||||
],
|
||||
"roots": [
|
||||
{
|
||||
"id": "mine",
|
||||
|
27
platform/core/src/services/Now.js
Normal file
27
platform/core/src/services/Now.js
Normal file
@ -0,0 +1,27 @@
|
||||
/*global define*/
|
||||
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* Defines the `now` service, which is a simple wrapper upon
|
||||
* `Date.now()` which can be injected to support testability.
|
||||
*
|
||||
* @returns {Function} a function which returns current system time
|
||||
*/
|
||||
function Now() {
|
||||
/**
|
||||
* Get the current time.
|
||||
* @returns {number} current time, in milliseconds since
|
||||
* 1970-01-01 00:00:00Z
|
||||
*/
|
||||
return function () {
|
||||
return Date.now();
|
||||
};
|
||||
}
|
||||
|
||||
return Now;
|
||||
}
|
||||
);
|
28
platform/core/test/services/NowSpec.js
Normal file
28
platform/core/test/services/NowSpec.js
Normal file
@ -0,0 +1,28 @@
|
||||
/*global define,Promise,describe,it,expect,beforeEach,waitsFor,jasmine*/
|
||||
|
||||
define(
|
||||
["../../src/services/Now"],
|
||||
function (Now) {
|
||||
"use strict";
|
||||
|
||||
describe("The 'now' service", function () {
|
||||
var now = new Now();
|
||||
|
||||
it("reports system time", function () {
|
||||
var a = Date.now(),
|
||||
b = now(),
|
||||
c = Date.now();
|
||||
|
||||
// Clock could, in principle, tick between evaluating the
|
||||
// expressions above. We can't predict or prevent this but
|
||||
// want the test to be stable, so we only verify that now()
|
||||
// returns a value that makes sense given a previous and
|
||||
// subsequent measurement from Date.now()
|
||||
expect(a <= b).toBeTruthy();
|
||||
expect(b <= c).toBeTruthy();
|
||||
expect(b).toBeDefined();
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
);
|
@ -20,6 +20,8 @@
|
||||
"objects/DomainObject",
|
||||
"objects/DomainObjectProvider",
|
||||
|
||||
"services/Now",
|
||||
|
||||
"types/MergeModels",
|
||||
"types/TypeCapability",
|
||||
"types/TypeImpl",
|
||||
|
Loading…
x
Reference in New Issue
Block a user