@@ -90,7 +90,21 @@ export function isTestContext(context: BaseContext): context is TestContext {
90
90
) ;
91
91
}
92
92
93
- let __test_context__ : BaseContext | undefined ;
93
+ /**
94
+ @private
95
+ @param {Object } it the global object to test
96
+ @returns {Boolean } it exists
97
+ */
98
+ function check ( it : any ) {
99
+ // Math is known to exist as a global in every environment.
100
+ return it && it . Math === Math && it ;
101
+ }
102
+
103
+ const globalObject =
104
+ check ( typeof globalThis == 'object' && globalThis ) ||
105
+ check ( typeof window === 'object' && window ) ||
106
+ check ( typeof self === 'object' && self ) ||
107
+ check ( typeof global === 'object' && global ) ;
94
108
95
109
/**
96
110
Stores the provided context as the "global testing context".
@@ -101,17 +115,17 @@ let __test_context__: BaseContext | undefined;
101
115
@param {Object } context the context to use
102
116
*/
103
117
export function setContext ( context : BaseContext ) : void {
104
- __test_context__ = context ;
118
+ globalObject . __test_context__ = context ;
105
119
}
106
120
107
121
/**
108
- Retrive the "global testing context" as stored by `setContext`.
122
+ Retrieve the "global testing context" as stored by `setContext`.
109
123
110
124
@public
111
125
@returns {Object } the previously stored testing context
112
126
*/
113
127
export function getContext ( ) : BaseContext | undefined {
114
- return __test_context__ ;
128
+ return globalObject . __test_context__ ;
115
129
}
116
130
117
131
/**
@@ -122,7 +136,7 @@ export function getContext(): BaseContext | undefined {
122
136
@public
123
137
*/
124
138
export function unsetContext ( ) : void {
125
- __test_context__ = undefined ;
139
+ globalObject . __test_context__ = undefined ;
126
140
}
127
141
128
142
/**
0 commit comments