Skip to content

Commit 4134290

Browse files
committed
CHG: use globalThis
1 parent 1de950c commit 4134290

File tree

12 files changed

+16
-21
lines changed

12 files changed

+16
-21
lines changed

source/ci.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { getLogger } from 'source/node/logger.js'
22
import { commonInfoPatchCombo } from './ci.js'
33

4-
const { describe, it, info = console.log } = global
4+
const { describe, it, info = console.log } = globalThis
55

66
describe('CI', () => {
77
it('commonInfoPatchCombo()', async () => {

source/common/dev.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { getGlobal } from '@dr-js/core/module/env/global.js'
21
import { clock } from '@dr-js/core/module/common/time.js'
32
import { time } from '@dr-js/core/module/common/format.js'
43
import { isCompactArrayShallowEqual } from '@dr-js/core/module/common/immutable/check.js'
@@ -67,9 +66,7 @@ const hijackSetTimeoutInterval = () => {
6766
const setIntervalOrg = setInterval
6867
const clearIntervalOrg = clearInterval
6968

70-
const global = getGlobal()
71-
72-
global.setTimeout = (func, delay, ...args) => {
69+
globalThis.setTimeout = (func, delay, ...args) => {
7370
const token = setTimeoutOrg((...args) => {
7471
hijackPool.delete(token)
7572
return func(...args)
@@ -82,12 +79,12 @@ const hijackSetTimeoutInterval = () => {
8279
})
8380
return token
8481
}
85-
global.clearTimeout = (token) => {
82+
globalThis.clearTimeout = (token) => {
8683
hijackPool.delete(token)
8784
clearTimeoutOrg(token)
8885
}
8986

90-
global.setInterval = (func, delay, ...args) => {
87+
globalThis.setInterval = (func, delay, ...args) => {
9188
const token = setIntervalOrg(func, delay, ...args)
9289
hijackPool.set(token, {
9390
type: 'setInterval',
@@ -97,7 +94,7 @@ const hijackSetTimeoutInterval = () => {
9794
})
9895
return token
9996
}
100-
global.clearInterval = (token) => {
97+
globalThis.clearInterval = (token) => {
10198
hijackPool.delete(token)
10299
clearIntervalOrg(token)
103100
}

source/common/test.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { getGlobal } from '@dr-js/core/module/env/global.js'
2-
31
import { string, basicFunction } from '@dr-js/core/module/common/verify.js'
42
import { isString, isBasicFunction } from '@dr-js/core/module/common/check.js'
53
import { catchSync, catchAsync } from '@dr-js/core/module/common/error.js'
@@ -105,8 +103,8 @@ const createTest = ({
105103
RESULT = { passList: [], failList: [] }
106104
CONFIG = { log, logLevel, timeout }
107105

108-
// inject global for test script
109-
!isSkipGlobalAssign && Object.assign(getGlobal(), { describe, it, before, after, info })
106+
// inject globalThis for test script
107+
!isSkipGlobalAssign && Object.assign(globalThis, { describe, it, before, after, info })
110108

111109
CONFIG.log(colorMain('[TEST] setup'))
112110
}

source/docker.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
getContainerLsList
55
} from './docker.js'
66

7-
const { describe, it, info = console.log } = global
7+
const { describe, it, info = console.log } = globalThis
88

99
describe('Docker', () => {
1010
__DEV__ && info(`DOCKER_BIN_PATH: ${resolveCommandName('docker')}`)

source/node/cache/checksum.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
checksumUpdate, checksumDetectChange
1313
} from './checksum.js'
1414

15-
const { describe, it, before, after, info = console.log } = global
15+
const { describe, it, before, after, info = console.log } = globalThis
1616

1717
const TEST_ROOT = resolve(__dirname, './test-checksum-gitignore/')
1818
const fromRoot = (...args) => resolve(TEST_ROOT, ...args)

source/node/cache/staleCheck.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
loadStatFile, saveStatFile
1111
} from './staleCheck.js'
1212

13-
const { describe, it, before, after, info = console.log } = global
13+
const { describe, it, before, after, info = console.log } = globalThis
1414

1515
const TEST_ROOT = resolve(__dirname, './test-stale-check-gitignore/')
1616
const fromRoot = (...args) => resolve(TEST_ROOT, ...args)

source/node/file.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
filterPrecompressFileList
77
} from './file'
88

9-
const { describe, it } = global
9+
const { describe, it } = globalThis
1010

1111
const PATH_ROOT = resolve(__dirname, __dirname.includes('output-gitignore') ? '../../../' : '../../')
1212

source/node/npm/npxLazy.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { doNotThrowAsync } from '@dr-js/core/module/common/verify.js'
22

33
import { runNpx } from './npxLazy.js'
44

5-
const { describe, it, info = console.log } = global
5+
const { describe, it, info = console.log } = globalThis
66

77
const tabLog = (level, ...args) => info(`${' '.repeat(level)}${args.join(' ')}`)
88

source/node/npm/parseScript.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
parsePackageScript
88
} from './parseScript.js'
99

10-
const { describe, it, info = console.log } = global
10+
const { describe, it, info = console.log } = globalThis
1111

1212
const tabLog = (level, ...args) => info(`${' '.repeat(level)}${args.join(' ')}`)
1313

source/node/preset.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
FILTER_SOURCE_JS_FILE
1010
} from './preset.js'
1111

12-
const { describe, it } = global
12+
const { describe, it } = globalThis
1313

1414
const TEST_PATH_LIST = []
1515
const EXPECT_LIST = []

0 commit comments

Comments
 (0)