From 74790445c91d809b4a84b10ed189ccd20410df1e Mon Sep 17 00:00:00 2001 From: Justin Anastos Date: Wed, 3 Jul 2019 10:43:56 -0400 Subject: [PATCH 1/2] Fix service:list snapshot relative time The time is relative; over time the value changes, causing the snapshot to fail. --- packages/apollo/src/commands/service/list.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/apollo/src/commands/service/list.ts b/packages/apollo/src/commands/service/list.ts index b853cc03de..557e2a4e45 100644 --- a/packages/apollo/src/commands/service/list.ts +++ b/packages/apollo/src/commands/service/list.ts @@ -21,14 +21,15 @@ interface TasksOutput { } const formatImplementingService = ( - implementingService: ListServices_service_implementingServices_FederatedImplementingServices_services + implementingService: ListServices_service_implementingServices_FederatedImplementingServices_services, + effectiveDate: Date = new Date() ) => { return { name: implementingService.name, url: implementingService.url || "", updatedAt: `${moment(implementingService.updatedAt).format( "D MMMM YYYY" - )} (${moment(implementingService.updatedAt).fromNow()})` + )} (${moment(implementingService.updatedAt).from(effectiveDate)})` }; }; @@ -57,7 +58,16 @@ function formatHumanReadable({ >(implementingServices.services, [service => service.name.toUpperCase()]); table( - sortedImplementingServices.map(formatImplementingService).filter(Boolean), + sortedImplementingServices + .map(sortedImplementingService => + formatImplementingService( + sortedImplementingService, + // Force the time to a specific value if we're running tests. Otherwise the snapshots will break + // when the relative time changes. + process.env.NODE_ENV === "test" ? new Date("2019-06-13") : undefined + ) + ) + .filter(Boolean), { columns: [ { key: "name", label: "Name" }, From 88619361e7bbd11319c5e514b1a883571f3159a4 Mon Sep 17 00:00:00 2001 From: Justin Anastos Date: Wed, 3 Jul 2019 10:45:47 -0400 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=93=9A=20update=20changelog?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 95e5b952e1..93d8d229e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - `apollo` - Relax graphql version, resolve missing types "Boolean", "String" [#1355](https://github.com/apollographql/apollo-tooling/pull/1355) - Add `service:list` and tests [#1358](https://github.com/apollographql/apollo-tooling/pull/1358) + - 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) - `apollo-codegen-core` - - `apollo-codegen-flow`