@@ -25,6 +25,7 @@ import {AsyncHooksCLS} from '../src/cls/async-hooks';
2525import { AsyncListenerCLS } from '../src/cls/async-listener' ;
2626import { CLS } from '../src/cls/base' ;
2727import { NullCLS } from '../src/cls/null' ;
28+ import { SingularCLS } from '../src/cls/singular' ;
2829import { SpanDataType } from '../src/constants' ;
2930import { createStackTrace , FORCE_NEW } from '../src/util' ;
3031
@@ -236,36 +237,44 @@ describe('Continuation-Local Storage', () => {
236237 } ) ;
237238 } ) ;
238239 }
240+
241+ describe ( 'SingularCLS' , ( ) => {
242+ it ( 'uses a single global context' , async ( ) => {
243+ const cls = new SingularCLS ( 'default' ) ;
244+ cls . enable ( ) ;
245+ cls . runWithNewContext ( ( ) => {
246+ cls . setContext ( 'modified' ) ;
247+ } ) ;
248+ await Promise . resolve ( ) ;
249+ cls . runWithNewContext ( ( ) => {
250+ assert . strictEqual ( cls . getContext ( ) , 'modified' ) ;
251+ } ) ;
252+ } ) ;
253+ } ) ;
239254 } ) ;
240255
241256 describe ( 'TraceCLS' , ( ) => {
242257 const validTestCases :
243- Array < { config : TraceCLSConfig , expectedDefaultType : SpanDataType } > =
244- asyncAwaitSupported ?
245- [
246- {
247- config : { mechanism : TraceCLSMechanism . ASYNC_HOOKS } ,
248- expectedDefaultType : SpanDataType . UNCORRELATED
249- } ,
258+ Array < { config : TraceCLSConfig , expectedDefaultType : SpanDataType } > = [
250259 {
251260 config : { mechanism : TraceCLSMechanism . ASYNC_LISTENER } ,
252261 expectedDefaultType : SpanDataType . UNCORRELATED
253262 } ,
254263 {
255- config : { mechanism : TraceCLSMechanism . NONE } ,
256- expectedDefaultType : SpanDataType . UNTRACED
257- }
258- ] :
259- [
260- {
261- config : { mechanism : TraceCLSMechanism . ASYNC_LISTENER } ,
264+ config : { mechanism : TraceCLSMechanism . SINGULAR } ,
262265 expectedDefaultType : SpanDataType . UNCORRELATED
263266 } ,
264267 {
265268 config : { mechanism : TraceCLSMechanism . NONE } ,
266269 expectedDefaultType : SpanDataType . UNTRACED
267270 }
268271 ] ;
272+ if ( asyncAwaitSupported ) {
273+ validTestCases . push ( {
274+ config : { mechanism : TraceCLSMechanism . ASYNC_HOOKS } ,
275+ expectedDefaultType : SpanDataType . UNCORRELATED
276+ } ) ;
277+ }
269278 for ( const testCase of validTestCases ) {
270279 describe ( `with configuration ${ inspect ( testCase ) } ` , ( ) => {
271280 const logger = new TestLogger ( ) ;
0 commit comments