Skip to content

Commit a80b6c8

Browse files
tests: explicitly set TZ for local tests (#4304)
In #4297 we explicitly set the TZ in a part of the code that CI uses, but when running the unit tests locally it does not trigger that part of the code. Due to this the tests still fail when run locally. Solution: Add the TZ assignment to a part of the code when unit tests are running locally. Now unit tests will pass when run locally Signed-off-by: nkomonen <[email protected]>
1 parent cdc01ff commit a80b6c8

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

scripts/test/launchTestUtilities.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ import { runTests } from '@vscode/test-electron'
1111
import { VSCODE_EXTENSION_ID } from '../../src/shared/extensions'
1212
import { TestOptions } from '@vscode/test-electron/out/runTest'
1313

14-
// Set a fixed timezone. Intentionally _not_ UTC, to increase variation in tests.
15-
process.env.TZ = 'US/Pacific'
16-
// process.env.TZ = 'Europe/London'
17-
1814
const envvarVscodeTestVersion = 'VSCODE_TEST_VERSION'
1915

2016
const stable = 'stable'

src/test/cloudWatchLogs/registry/logDataRegistry.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,11 @@ describe('LogDataRegistry', async function () {
210210
it('matches CloudWatch insights timestamps', function () {
211211
const time = 1624201162222 // 2021-06-20 14:59:22.222 GMT+0
212212
const timestamp = formatDateTimestamp(true, new Date(time))
213-
assert.strictEqual(timestamp, '2021-06-20T14:59:22.222-07:00')
213+
assert.strictEqual(
214+
timestamp,
215+
'2021-06-20T14:59:22.222-07:00',
216+
'`process.env.TZ` assignment may have been modified'
217+
)
214218
})
215219
})
216220
})

src/test/testRunner.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ import Mocha from 'mocha'
99
import glob from 'glob'
1010
import * as fs from 'fs-extra'
1111

12+
// Set explicit timezone to ensure that tests run locally do not use the user's actual timezone, otherwise
13+
// the test can pass on one persons machine but not anothers.
14+
// Intentionally _not_ UTC, to increase variation in tests.
15+
// process.env.TZ = 'Europe/London'
16+
process.env.TZ = 'US/Pacific'
17+
1218
/**
1319
* @param initTests List of relative paths to test files containing root hooks: https://mochajs.org/#available-root-hooks
1420
*/

0 commit comments

Comments
 (0)