You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

30 lines
786 B

const NodeEnvironment = require('jest-environment-node').TestEnvironment;
// Jest gives each test file a copy of `process`, so a test cannot change the
// time zone at run time. This environment sets `TZ` on the real process of the
// worker, which resets the internal date cache of Node.
class TimeZoneEnvironment extends NodeEnvironment {
constructor(config, context) {
super(config, context);
this.timeZone = config.projectConfig.testEnvironmentOptions?.timeZone;
}
async setup() {
this.previousTimeZone = process.env.TZ;
if (this.timeZone) {
process.env.TZ = this.timeZone;
}
await super.setup();
}
async teardown() {
await super.teardown();
process.env.TZ = this.previousTimeZone;
}
}
module.exports = TimeZoneEnvironment;