From a746c6f08b93461529a99a0e08c6f7e8d3a21218 Mon Sep 17 00:00:00 2001 From: Ran Byron Date: Thu, 10 Jan 2019 20:44:33 +0200 Subject: [PATCH] Fixed tests failing due to server timezone difference --- .../enzyme_setup.js} | 2 +- client/app/__tests__/mocks.js | 5 +++ .../components/queries/ScheduleDialog.test.js | 5 --- .../__snapshots__/ScheduleDialog.test.js.snap | 36 +++++++++---------- package-lock.json | 6 ++++ package.json | 11 ++++-- 6 files changed, 38 insertions(+), 27 deletions(-) rename client/app/{jest_setup.js => __tests__/enzyme_setup.js} (70%) create mode 100644 client/app/__tests__/mocks.js diff --git a/client/app/jest_setup.js b/client/app/__tests__/enzyme_setup.js similarity index 70% rename from client/app/jest_setup.js rename to client/app/__tests__/enzyme_setup.js index 8dd51397ba..82edfc9e5a 100644 --- a/client/app/jest_setup.js +++ b/client/app/__tests__/enzyme_setup.js @@ -1,4 +1,4 @@ -import { configure } from 'enzyme'; +import { configure } from 'enzyme'; import Adapter from 'enzyme-adapter-react-16'; configure({ adapter: new Adapter() }); diff --git a/client/app/__tests__/mocks.js b/client/app/__tests__/mocks.js new file mode 100644 index 0000000000..14fccbe90b --- /dev/null +++ b/client/app/__tests__/mocks.js @@ -0,0 +1,5 @@ +import MockDate from 'mockdate'; + +const date = new Date('2000-01-01T02:00:00.000'); + +MockDate.set(date); diff --git a/client/app/components/queries/ScheduleDialog.test.js b/client/app/components/queries/ScheduleDialog.test.js index 4dc11de458..beb9730fb7 100644 --- a/client/app/components/queries/ScheduleDialog.test.js +++ b/client/app/components/queries/ScheduleDialog.test.js @@ -58,11 +58,6 @@ function getSelectOptions(wrapper) { } describe('ScheduleDialog', () => { - beforeAll(() => { - // mock date string so snapshots don't get invalidated - window.Date.prototype.toISOString = jest.fn(() => 'mocked ISO'); - }); - describe('Sets correct schedule settings', () => { test('Sets to "Never"', () => { const [wrapper] = getWrapper(); diff --git a/client/app/components/queries/__snapshots__/ScheduleDialog.test.js.snap b/client/app/components/queries/__snapshots__/ScheduleDialog.test.js.snap index 3e86802c66..db4c3e1f00 100644 --- a/client/app/components/queries/__snapshots__/ScheduleDialog.test.js.snap +++ b/client/app/components/queries/__snapshots__/ScheduleDialog.test.js.snap @@ -270,7 +270,7 @@ exports[`ScheduleDialog Sets correct schedule settings Sets to "1 Day 22:15" Set } } allowEmpty={false} - defaultValue={"mocked ISO"} + defaultValue={"1999-12-31T22:15:00.000Z"} disabled={false} focusOnOpen={true} format="HH:mm" @@ -304,7 +304,7 @@ exports[`ScheduleDialog Sets correct schedule settings Sets to "1 Day 22:15" Set className="" clearText="clear" defaultOpen={false} - defaultOpenValue={"mocked ISO"} + defaultOpenValue={"2000-01-01T00:00:00.000Z"} disabled={false} disabledHours={[Function]} disabledMinutes={[Function]} @@ -331,7 +331,7 @@ exports[`ScheduleDialog Sets correct schedule settings Sets to "1 Day 22:15" Set style={Object {}} transitionName="slide-up" use12Hours={false} - value={"mocked ISO"} + value={"1999-12-31T22:15:00.000Z"} > } popupAlign={ @@ -1030,7 +1030,7 @@ exports[`ScheduleDialog Sets correct schedule settings Sets to "2 Weeks 22:15 Tu } } allowEmpty={false} - defaultValue={"mocked ISO"} + defaultValue={"1999-12-31T22:15:00.000Z"} disabled={false} focusOnOpen={true} format="HH:mm" @@ -1064,7 +1064,7 @@ exports[`ScheduleDialog Sets correct schedule settings Sets to "2 Weeks 22:15 Tu className="" clearText="clear" defaultOpen={false} - defaultOpenValue={"mocked ISO"} + defaultOpenValue={"2000-01-01T00:00:00.000Z"} disabled={false} disabledHours={[Function]} disabledMinutes={[Function]} @@ -1091,7 +1091,7 @@ exports[`ScheduleDialog Sets correct schedule settings Sets to "2 Weeks 22:15 Tu style={Object {}} transitionName="slide-up" use12Hours={false} - value={"mocked ISO"} + value={"1999-12-31T22:15:00.000Z"} > } popupAlign={ @@ -2308,7 +2308,7 @@ exports[`ScheduleDialog Sets correct schedule settings Until feature Until is se prefixCls="ant-calendar" size="small" transitionName="slide-up" - value={"mocked ISO"} + value={"2029-12-31T22:00:00.000Z"} > } @@ -2500,7 +2500,7 @@ exports[`ScheduleDialog Sets correct schedule settings Until feature Until is se style={Object {}} timePicker={null} transitionName="slide-up" - value={"mocked ISO"} + value={"2029-12-31T22:00:00.000Z"} > } diff --git a/package-lock.json b/package-lock.json index 2f81b34e73..b2d7f5c025 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11781,6 +11781,12 @@ } } }, + "mockdate": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/mockdate/-/mockdate-2.0.2.tgz", + "integrity": "sha1-WuDA6vj+I+AJzQH5iJtCxPY0rxI=", + "dev": true + }, "moment": { "version": "2.19.3", "resolved": "https://registry.npmjs.org/moment/-/moment-2.19.3.tgz", diff --git a/package.json b/package.json index 45c5e51de5..c56347ee7a 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "watch": "webpack --watch --progress --colors -d", "analyze": "npm run clean && BUNDLE_ANALYZER=on webpack", "analyze:build": "npm run clean && NODE_ENV=production BUNDLE_ANALYZER=on webpack", - "test": "jest", + "test": "TZ=Asia/Jerusalem jest", "test:watch": "jest --watch", "cypress:install": "npm install --no-save cypress @percy/cypress", "cypress": "node cypress/cypress.js" @@ -116,6 +116,7 @@ "less-loader": "^4.1.0", "less-plugin-autoprefix": "^1.5.1", "mini-css-extract-plugin": "^0.4.4", + "mockdate": "^2.0.2", "raw-loader": "^0.5.1", "react-test-renderer": "^16.5.2", "request": "^2.88.0", @@ -132,7 +133,8 @@ }, "jest": { "setupFiles": [ - "./client/app/jest_setup.js" + "./client/app/__tests__/enzyme_setup.js", + "./client/app/__tests__/mocks.js" ], "snapshotSerializers": [ "enzyme-to-json/serializer" @@ -140,6 +142,9 @@ "moduleNameMapper": { "^@/(.*)": "/client/app/$1", "\\.(css|less)$": "identity-obj-proxy" - } + }, + "testPathIgnorePatterns": [ + "/client/app/__tests__/" + ] } }