Skip to content

Commit

Permalink
test: 🐛 lock timezone for jest testing
Browse files Browse the repository at this point in the history
  • Loading branch information
thkruz committed Jan 15, 2024
1 parent ff1a6ad commit 60c39de
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const jestConfig = {
modulePathIgnorePatterns: ['<rootDir>/node_modules/', '<rootDir>/test/sgp4/sgp4prop'],
coverageReporters: ['lcov', 'html', 'text'],
coveragePathIgnorePatterns: ['/node_modules/', '/dist/', '/lib/', '/commonjs/', '/test/', '/scripts/', '/coverage/'],
globalSetup: '<rootDir>/test/lib/globalSetup.js',
};

export default jestConfig;
2 changes: 1 addition & 1 deletion test/body/Moon.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ describe('Moon', () => {
* 'rise', 'set', 'ye', 'alwaysUp', 'alwaysDown', and 'highest' properties.
*/
it('should return with \'rise\', \'set\', \'ye\', \'alwaysUp\', \'alwaysDown\', and \'highest\' properties', () => {
const date = exampleDate;
const date = new Date(exampleDate.getTime() - exampleDate.getTimezoneOffset() * 60000);
const lat = 37.7749 as Degrees; // San Francisco latitude
const lon = -122.4194 as Degrees; // San Francisco longitude
const isUtc = false;
Expand Down
4 changes: 4 additions & 0 deletions test/lib/globalSetup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export default () => {
// eslint-disable-next-line no-process-env
process.env.TZ = 'EST';
};
6 changes: 6 additions & 0 deletions test/lib/globalSetup.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
describe('Timezones', () => {
it('should always be EST', () => {
// This is so that we can check local and utc calculations
expect(new Date().getTimezoneOffset()).toBe(300);
});
});

0 comments on commit 60c39de

Please sign in to comment.