tests/e2e: update jest environment settings
Usage of GO_DISCOVERY_E2E_ENVIRONMENT is updated so that if it is set to
"staging" or "prod", then the staging snapshots are used. Otherwise, the
ci snapshots are used.
A license header is add to tests/e2e/snapshotResolver.js and comments
are added for future readers.
Change-Id: Ib9d0ba2032b27479b3ecab93347fdfb939bd2aee
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/341109
Trust: Julie Qiu <julie@golang.org>
Reviewed-by: Jamal Carvalho <jamal@golang.org>
diff --git a/jest.config.js b/jest.config.js
index e6dc477..304209d 100644
--- a/jest.config.js
+++ b/jest.config.js
@@ -17,11 +17,16 @@
testPathIgnorePatterns: ['tests/e2e'],
};
+// When GO_DISCOVERY_E2E_ENVIRONMENT is not set to staging or prod, use the
+// snapshots in tests/e2e/__snapshots__/ci. Otherwise, use
+// tests/e2e/__snapshots__/staging. Data in staging and prod are always expected
+// to be the same.
+//
// eslint-disable-next-line no-undef
const env = process.env.GO_DISCOVERY_E2E_ENVIRONMENT;
-let ignore = 'ci';
-if (env == 'ci') {
- ignore = 'staging';
+let ignore = 'staging';
+if (env === 'staging' || env === 'prod') {
+ ignore = 'ci';
}
// eslint-disable-next-line no-undef
diff --git a/tests/e2e/setup.ts b/tests/e2e/setup.ts
index 0d3e3d4..111de41 100644
--- a/tests/e2e/setup.ts
+++ b/tests/e2e/setup.ts
@@ -7,11 +7,18 @@
import { configureToMatchImageSnapshot } from 'jest-image-snapshot';
+// When GO_DISCOVERY_E2E_ENVIRONMENT is not set to staging or prod, use the
+// snapshots in tests/e2e/__snapshots__/ci. Otherwise, use
+// tests/e2e/__snapshots__/staging. Data in taging and prod are always expected
+// to be the same.
+//
+// eslint-disable-next-line no-undef
let env = process.env.GO_DISCOVERY_E2E_ENVIRONMENT;
-if (env != 'ci') {
+if (env === 'staging' || env === 'prod') {
env = 'staging';
+} else {
+ env = 'ci';
}
-
const snapshotDir = `tests/e2e/__image_snapshots__/${env}`;
// Extends jest to compare image snapshots.
diff --git a/tests/e2e/snapshotResolver.js b/tests/e2e/snapshotResolver.js
index bbe9c06..1ef93af 100644
--- a/tests/e2e/snapshotResolver.js
+++ b/tests/e2e/snapshotResolver.js
@@ -1,9 +1,22 @@
+/**
+ * @license
+ * Copyright 2021 The Go Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style
+ * license that can be found in the LICENSE file.
+ */
+
+// When GO_DISCOVERY_E2E_ENVIRONMENT is not set to staging or prod, use the
+// snapshots in tests/e2e/__snapshots__/ci. Otherwise, use
+// tests/e2e/__snapshots__/staging. Data in staging and prod are always
+// expected to be the same.
+//
// eslint-disable-next-line no-undef
let env = process.env.GO_DISCOVERY_E2E_ENVIRONMENT;
-if (env != 'ci') {
+if (env === 'staging' || env === 'prod') {
env = 'staging';
+} else {
+ env = 'ci';
}
-
const snapshotDir = `tests/e2e/__snapshots__/${env}`;
// eslint-disable-next-line no-undef