File tree 3 files changed +48
-3
lines changed
scripts/emulator-testing/emulators
3 files changed +48
-3
lines changed Original file line number Diff line number Diff line change @@ -618,10 +618,20 @@ export const setTimeoutNonBlocking = function (
618
618
time : number
619
619
) : number | object {
620
620
const timeout : number | object = setTimeout ( fn , time ) ;
621
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
622
- if ( typeof timeout === 'object' && ( timeout as any ) [ 'unref' ] ) {
621
+ // @ts -ignore Deno and unrefTimer are only defined in Deno environments.
622
+ // Note: at the time of this comment, unrefTimer is under the unstable set of APIs. Run with --unstable to enable the API.
623
+ if (
624
+ typeof timeout === 'number' &&
625
+ typeof Deno !== 'undefined' &&
626
+ Deno [ 'unrefTimer' ]
627
+ ) {
628
+ // @ts -ignore Deno and unrefTimer are only defined in Deno environments.
629
+ Deno . unrefTimer ( timeout ) ;
630
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
631
+ } else if ( typeof timeout === 'object' && ( timeout as any ) [ 'unref' ] ) {
623
632
// eslint-disable-next-line @typescript-eslint/no-explicit-any
624
633
( timeout as any ) [ 'unref' ] ( ) ;
625
634
}
635
+
626
636
return timeout ;
627
637
} ;
Original file line number Diff line number Diff line change
1
+ import { expect , use } from 'chai' ;
2
+ import * as sinon from 'sinon' ;
3
+ import sinonChai from 'sinon-chai' ;
4
+
5
+ import { setTimeoutNonBlocking } from '../src/core/util/util' ;
6
+ use ( sinonChai ) ;
7
+ describe ( 'Deno tests' , ( ) => {
8
+ let oldSetTimeout ;
9
+ beforeEach ( ( ) => {
10
+ oldSetTimeout = globalThis . setTimeout ;
11
+ } ) ;
12
+ afterEach ( ( ) => {
13
+ globalThis . setTimeout = oldSetTimeout ;
14
+ } ) ;
15
+ it ( 'should call the deno unrefTimer() if in Deno' , ( ) => {
16
+ // @ts -ignore override nodejs behavior
17
+ global . Deno = {
18
+ unrefTimer : sinon . spy ( )
19
+ } ;
20
+ // @ts -ignore override nodejs behavior
21
+ global . setTimeout = ( ) => 1 ;
22
+ setTimeoutNonBlocking ( ( ) => { } , 0 ) ;
23
+ expect ( globalThis . Deno . unrefTimer ) . to . have . been . called ;
24
+ } ) ;
25
+ it ( 'should not call the deno unrefTimer() if not in Deno' , ( ) => {
26
+ // @ts -ignore override nodejs behavior
27
+ global . Deno2 = {
28
+ unrefTimer : sinon . spy ( )
29
+ } ;
30
+ // @ts -ignore override node.js behavior
31
+ global . setTimeout = ( ) => 1 ;
32
+ setTimeoutNonBlocking ( ( ) => { } , 0 ) ;
33
+ expect ( globalThis . Deno2 . unrefTimer ) . to . not . have . been . called ;
34
+ } ) ;
35
+ } ) ;
Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ import * as request from 'request';
19
19
20
20
import { Emulator } from './emulator' ;
21
21
22
- import * as rulesJSON from '../../../config/database.rules.json' ;
22
+ import rulesJSON from '../../../config/database.rules.json' ;
23
23
24
24
export class DatabaseEmulator extends Emulator {
25
25
namespace : string ;
You can’t perform that action at this time.
0 commit comments