Skip to content

Commit 51f76c7

Browse files
committed
test: always use UTC timezone for unit tests
1 parent 41c6a96 commit 51f76c7

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

app/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
]
7777
},
7878
"jest": {
79+
"globalSetup": "./src/setupTestsGlobal.ts",
7980
"collectCoverageFrom": [
8081
"src/**/*.{js,jsx,ts,tsx}",
8182
"!src/**/*.d.ts",

app/src/__tests__/timezone.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { loopListSwaps } from 'util/tests/sampleData';
2+
import { Swap } from 'store/models';
3+
4+
/**
5+
* These test just ensure that the test runner is executing with
6+
* the system time zone set to UTC. This prevents tests from passing
7+
* on one machine and failing on another due to different time zones
8+
*
9+
* The `process.env.TZ` value is set to UTC in the jest global
10+
* config file setupTestsGlobal.ts
11+
*/
12+
describe('Timezone', () => {
13+
it('should always run unit tests in UTC', () => {
14+
expect(new Date().getTimezoneOffset()).toBe(0);
15+
});
16+
17+
it('should format the swap timestamps correctly', () => {
18+
const swap = new Swap(loopListSwaps.swapsList[0]);
19+
expect(swap.createdOnLabel).toEqual('4/8/2020 11:59:13 PM');
20+
expect(swap.updatedOnLabel).toEqual('4/9/2020 2:12:49 AM');
21+
});
22+
});

app/src/__tests__/util/csv.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe('csv Util', () => {
1616
const actual = csv.convert(Swap.csvColumns, swaps);
1717
const expected = [
1818
'"Swap ID","Type","Amount","Status","Created On","Updated On"',
19-
'"f4eb118383c2b09d8c7289ce21c25900cfb4545d46c47ed23a31ad2aa57ce830","Loop Out","500000","Failed","4/8/2020 7:59:13 PM","4/8/2020 10:12:49 PM"',
19+
'"f4eb118383c2b09d8c7289ce21c25900cfb4545d46c47ed23a31ad2aa57ce830","Loop Out","500000","Failed","4/8/2020 11:59:13 PM","4/9/2020 2:12:49 AM"',
2020
].join('\n');
2121
expect(actual).toEqual(expected);
2222
});

app/src/setupTestsGlobal.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default () => {
2+
process.env.TZ = 'UTC';
3+
};

0 commit comments

Comments
 (0)