-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2e72c05
commit 20cef2f
Showing
2 changed files
with
57 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* Copyright 2024 Google LLC. | ||
* Copyright (c) Microsoft Corporation. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "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. | ||
*/ | ||
import {expect} from 'chai'; | ||
|
||
import {getTimestamp} from './time.js'; | ||
|
||
describe('getTimestamp', () => { | ||
it('should return a number', () => { | ||
const timestamp = getTimestamp(); | ||
expect(timestamp).to.be.a('number'); | ||
}); | ||
|
||
it(`should return a timestamp between '2020-01-01 00:00:00' and '2100-01-01 00:00:00'`, () => { | ||
const timestamp = getTimestamp(); | ||
// Using a large delta to account for execution time and clock drift. | ||
// In a real test, consider mocking the underlying time source. | ||
expect(timestamp).to.be.within(1577833200000, 4102441200000); | ||
}); | ||
}); |
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,24 @@ | ||
/** | ||
* Copyright 2024 Google LLC. | ||
* Copyright (c) Microsoft Corporation. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "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. | ||
*/ | ||
|
||
export function getTimestamp(): number { | ||
// `timestamp` from the event is MonotonicTime, not real time, so | ||
// the best Mapper can do is to set the timestamp to the epoch time | ||
// of the event arrived. | ||
// https://chromedevtools.github.io/devtools-protocol/tot/Network/#type-MonotonicTime | ||
return new Date().getTime(); | ||
} |