Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WAITP-1269: Fix front end tests config #4726

Merged
merged 1 commit into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/utils/jest-setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* Tupaia
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/

module.exports = async () => {
process.env.TZ = 'Australia/Melbourne';
};
1 change: 1 addition & 0 deletions packages/utils/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ const baseConfig = require('../../jest.config-js.json');
module.exports = async () => ({
...baseConfig,
rootDir: '.',
globalSetup: '<rootDir>/jest-setup.js',
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,21 @@
* Copyright (c) 2017 - 2020 Beyond Essential Systems Pty Ltd
*/

import moment from 'moment-timezone';
import moment from 'moment';
import sinon from 'sinon';
import { roundStartEndDates, getDefaultDates, getLimits } from '../../period/periodGranularities';

const DEFAULT_NOW_TIMESTAMP = 1549360800000; // 2019-02-05T10:00:00.000Z

const mockNow = (whenIsNow = DEFAULT_NOW_TIMESTAMP) => {
sinon.useFakeTimers(whenIsNow);
moment.tz.setDefault('Australia/Melbourne');
};

const resetMocks = () => {
sinon.restore();
moment.tz.setDefault();
};

describe.skip('chartGranularities', () => {
describe('chartGranularities', () => {
beforeEach(() => {
mockNow(1549360800 * 1000); // (2019-02-05 10:00 UTC)
});
Expand Down
8 changes: 8 additions & 0 deletions packages/web-frontend/config/jest/jest-setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* Tupaia
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/

module.exports = async () => {
process.env.TZ = 'Australia/Melbourne';
};
1 change: 1 addition & 0 deletions packages/web-frontend/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const baseConfig = require('../../jest.config-js.json');
module.exports = {
...baseConfig,
rootDir: '.',
globalSetup: '<rootDir>/config/jest/jest-setup.js',
setupFiles: ['<rootDir>/config/polyfills.js'],
testMatch: ['<rootDir>/src/**/__tests__/**/*.js?(x)', '<rootDir>/src/**/?(*.)(spec|test).js?(x)'],
testURL: 'http://localhost',
Expand Down
1 change: 0 additions & 1 deletion packages/web-frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
"material-ui": "^0.18.3",
"material-ui-datetimepicker": "^1.0.7",
"moment": "^2.21.0",
"moment-timezone": "^0.5.28",
"numeral": "^2.0.6",
"polished": "^3.0.0",
"prop-types": "^15.6.2",
Expand Down
3 changes: 0 additions & 3 deletions packages/web-frontend/src/tests/testutil.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import sinon from 'sinon';
import moment from 'moment-timezone';

const DEFAULT_NOW_TIMESTAMP = 1549360800000; // 2019-02-05T10:00:00.000Z

export const mockNow = (whenIsNow = DEFAULT_NOW_TIMESTAMP) => {
sinon.useFakeTimers(whenIsNow);
moment.tz.setDefault('Australia/Melbourne');
};

export const resetMocks = () => {
sinon.restore();
moment.tz.setDefault();
};
5 changes: 2 additions & 3 deletions packages/web-frontend/src/utils/formatDateForApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
* found in the LICENSE file in the root directory of this source tree.
*/

import moment from 'moment-timezone';
import moment from 'moment';

const DATE_FORMAT = 'YYYY-MM-DD';

export const formatDateForApi = (date, timezone) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The timezone prop was never being used and removing support for it means that we can completely remove moment-timezone as a dependency from web-frontend.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one. There is actually a function in utils called formatDateForApi which looks like it does the same thing. Might not be worth swapping it out tho, since we are going to eventually get rid of web-frontend

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good spotting but yeah probably not worth it at this point in web-frontend.

export const formatDateForApi = date => {
if (!date) return undefined;
const dateAsMoment = moment(date);
if (timezone) dateAsMoment.tz(timezone);
return dateAsMoment.format(DATE_FORMAT);
};
1 change: 0 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10859,7 +10859,6 @@ __metadata:
material-ui-datetimepicker: ^1.0.7
mockdate: ^3.0.5
moment: ^2.21.0
moment-timezone: ^0.5.28
npm-run-all: ^4.1.5
numeral: ^2.0.6
object-assign: 4.1.1
Expand Down