Skip to content

Commit 5e1e44f

Browse files
author
Justin Anastos
authored
Fix service:list snapshot relative time (#1374)
Fix service:list snapshot relative time
2 parents 07b6041 + 8861936 commit 5e1e44f

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- `apollo`
66
- Relax graphql version, resolve missing types "Boolean", "String" [#1355](https://github.com/apollographql/apollo-tooling/pull/1355)
77
- Add `service:list` and tests [#1358](https://github.com/apollographql/apollo-tooling/pull/1358)
8+
- Update `service:list` test to use a simulated time to prevent relative dates causing snapshot failures [#1374](https://github.com/apollographql/apollo-tooling/pull/1374)
89
- `apollo-codegen-core`
910
- <First `apollo-codegen-core` related entry goes here>
1011
- `apollo-codegen-flow`

packages/apollo/src/commands/service/list.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@ interface TasksOutput {
2121
}
2222

2323
const formatImplementingService = (
24-
implementingService: ListServices_service_implementingServices_FederatedImplementingServices_services
24+
implementingService: ListServices_service_implementingServices_FederatedImplementingServices_services,
25+
effectiveDate: Date = new Date()
2526
) => {
2627
return {
2728
name: implementingService.name,
2829
url: implementingService.url || "",
2930
updatedAt: `${moment(implementingService.updatedAt).format(
3031
"D MMMM YYYY"
31-
)} (${moment(implementingService.updatedAt).fromNow()})`
32+
)} (${moment(implementingService.updatedAt).from(effectiveDate)})`
3233
};
3334
};
3435

@@ -57,7 +58,16 @@ function formatHumanReadable({
5758
>(implementingServices.services, [service => service.name.toUpperCase()]);
5859

5960
table(
60-
sortedImplementingServices.map(formatImplementingService).filter(Boolean),
61+
sortedImplementingServices
62+
.map(sortedImplementingService =>
63+
formatImplementingService(
64+
sortedImplementingService,
65+
// Force the time to a specific value if we're running tests. Otherwise the snapshots will break
66+
// when the relative time changes.
67+
process.env.NODE_ENV === "test" ? new Date("2019-06-13") : undefined
68+
)
69+
)
70+
.filter(Boolean),
6171
{
6272
columns: [
6373
{ key: "name", label: "Name" },

0 commit comments

Comments
 (0)