-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2695 from Azure/dpwatrous/vnext-logger
Refactored logger to add context
- Loading branch information
Showing
34 changed files
with
650 additions
and
173 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
3 changes: 3 additions & 0 deletions
3
packages/common/src/ui-common/action/__tests__/action.spec.ts
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
4 changes: 2 additions & 2 deletions
4
.../src/ui-common/__tests__/datetime.spec.ts → .../datetime/__tests__/datetime-util.spec.ts
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
34 changes: 34 additions & 0 deletions
34
packages/common/src/ui-common/datetime/__tests__/fake-clock.spec.ts
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,34 @@ | ||
import { initMockEnvironment } from "../../environment"; | ||
import { fromIso, getClock } from "../datetime-util"; | ||
import { FakeClock } from "../fake-clock"; | ||
|
||
describe("Fake clock", () => { | ||
beforeEach(() => initMockEnvironment()); | ||
|
||
test("Can manipulate fake clock", () => { | ||
const clock = getClock() as FakeClock; | ||
|
||
// Hard-coded current time | ||
expect(clock.now().getTime()).toEqual( | ||
fromIso("2022-02-02T00:00:00Z").getTime() | ||
); | ||
|
||
// Advance 60 seconds | ||
clock.advance(60_000); | ||
expect(clock.now().getTime()).toEqual( | ||
fromIso("2022-02-02T00:01:00Z").getTime() | ||
); | ||
|
||
// Set time to 2011-01-01 00:00:00 UTC | ||
clock.setTime(1293840000000); | ||
expect(clock.now().getTime()).toEqual( | ||
fromIso("2011-01-01T00:00:00Z").getTime() | ||
); | ||
|
||
// Reset back to original time | ||
clock.reset(); | ||
expect(clock.now().getTime()).toEqual( | ||
fromIso("2022-02-02T00:00:00Z").getTime() | ||
); | ||
}); | ||
}); |
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,3 @@ | ||
export interface Clock { | ||
now(): Date; | ||
} |
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,27 @@ | ||
import { Clock } from "./clock"; | ||
|
||
// 2022-02-02 00:00:00 UTC | ||
const INITIAL_MS = 1643760000000; | ||
|
||
export class FakeClock implements Clock { | ||
private _ms: number = INITIAL_MS; | ||
|
||
now(): Date { | ||
return new Date(this._ms); | ||
} | ||
|
||
advance(ms: number) { | ||
if (ms <= 0) { | ||
throw new Error("Can't advance clock by zero or a negative number"); | ||
} | ||
this._ms = ms + this._ms; | ||
} | ||
|
||
setTime(ms: number) { | ||
this._ms = ms; | ||
} | ||
|
||
reset() { | ||
this._ms = INITIAL_MS; | ||
} | ||
} |
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,3 @@ | ||
export * from "./datetime-util"; | ||
export * from "./clock"; | ||
export * from "./standard-clock"; |
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,7 @@ | ||
import { Clock } from "./clock"; | ||
|
||
export class StandardClock implements Clock { | ||
now(): Date { | ||
return new Date(); | ||
} | ||
} |
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
Oops, something went wrong.