diff --git a/desktop/package.json b/desktop/package.json index 357621859..269a4cff9 100644 --- a/desktop/package.json +++ b/desktop/package.json @@ -250,13 +250,13 @@ "start": "yarn dev-server --inspect=9229", "start:break": "yarn dev-server --inspect-brk=9229", "start:no-embedded-plugins": "yarn start --no-embedded-plugins", - "test": "jest", + "test": "cross-env TZ=Pacific/Pohnpei jest", "test-e2e": "cd e2e && yarn test", - "test-electron": "yarn build:tsc && jest --testMatch=\"**/**.electron\\.(js|jsx|ts|tsx)\" --testEnvironment=@jest-runner/electron/environment --runner=@jest-runner/electron", - "test-with-device": "yarn build:tsc && USE_ELECTRON_STUBS=1 jest --testMatch=\"**/**.device\\.(js|jsx|ts|tsx)\" --detectOpenHandles", - "test:debug": "yarn build:tsc && node --inspect node_modules/.bin/jest --runInBand", + "test-electron": "yarn build:tsc && cross-env TZ=Pacific/Pohnpei jest --testMatch=\"**/**.electron\\.(js|jsx|ts|tsx)\" --testEnvironment=@jest-runner/electron/environment --runner=@jest-runner/electron", + "test-with-device": "yarn build:tsc && cross-env TZ=Pacific/Pohnpei USE_ELECTRON_STUBS=1 jest --testMatch=\"**/**.device\\.(js|jsx|ts|tsx)\" --detectOpenHandles", + "test:debug": "yarn build:tsc && cross-env TZ=Pacific/Pohnpei node --inspect node_modules/.bin/jest --runInBand", "tsc-plugins": "./ts-node scripts/tsc-plugins.ts", - "watch": "node --expose-gc --stack-trace-limit=40 ./node_modules/.bin/jest --watch" + "watch": "cross-env TZ=Pacific/Pohnpei node --expose-gc --stack-trace-limit=40 ./node_modules/.bin/jest --watch" }, "version": "0.93.0", "workspaces": { diff --git a/desktop/scripts/jest-setup.js b/desktop/scripts/jest-setup.js index 5cca3996c..7d8ff848f 100644 --- a/desktop/scripts/jest-setup.js +++ b/desktop/scripts/jest-setup.js @@ -11,6 +11,22 @@ // eslint-disable-next-line global.fetch = require('jest-fetch-mock'); +// make sure test run everywhere in the same timezone! +// +11, somewhere in the middle of nowhere, so this deviates for everyone and will fail early :) +const timezone = 'Pacific/Pohnpei'; +if (process.env.TZ !== timezone) { + throw new Error( + `Test started in the wrong timezone, got ${process.env.TZ}, but expected ${timezone}. Please use the package.json commands to start Jest, or prefix the command with TZ=${timezone}`, + ); +} + +// Make sure we have identical formatting of Dates everywhere +const toLocaleString = Date.prototype.toLocaleString; +// eslint-disable-next-line no-extend-native +Date.prototype.toLocaleString = function (_locale, ...args) { + return toLocaleString.call(this, 'en-US', ...args); +}; + require('immer').enableMapSet(); require('../app/src/fb-stubs/Logger').init(undefined, {isTest: true});