@@ -400,7 +400,7 @@ describe('<%%', () => {
400
400
expect ( await ets . render ( '<%%- "foo" %>' ) ) . toEqual ( '<%- "foo" %>' ) ;
401
401
} ) ;
402
402
403
- test ( 'work without an end tag' , ( ) => {
403
+ test ( 'work without an end tag' , async ( ) => {
404
404
expect ( ets . render ( '<%%' ) ) . toEqual ( '<%' ) ;
405
405
expect (
406
406
await ets . render ( {
@@ -412,98 +412,102 @@ describe('<%%', () => {
412
412
} ) ;
413
413
} ) ;
414
414
415
- suite ( '%%>' , ( ) => {
416
- test ( 'produce literal' , ( ) => {
417
- assert . equal ( ets . render ( '%%>' ) , '%>' ) ;
418
- assert . equal ( ets . render ( ' >' , { } , { delimiter : ' ' } ) , ' >' ) ;
415
+ describe ( '%%>' , ( ) => {
416
+ test ( 'produce literal' , async ( ) => {
417
+ expect ( await ets . render ( '%%>' ) ) . toEqual ( '%>' ) ;
418
+ expect (
419
+ await ets . render ( { template : ' >' , options : { delimiter : ' ' } } )
420
+ ) . toEqual ( ' >' ) ;
419
421
} ) ;
420
422
} ) ;
421
423
422
- suite ( '<%_ and _%>' , ( ) => {
423
- test ( 'slurps spaces and tabs' , ( ) => {
424
- assert . equal (
425
- ets . render ( fixture ( 'space-and-tab-slurp.ets' ) , { users } ) ,
426
- fixture ( 'space-and-tab-slurp.html' )
427
- ) ;
424
+ describe ( '<%_ and _%>' , ( ) => {
425
+ test ( 'slurps spaces and tabs' , async ( ) => {
426
+ expect (
427
+ await ets . render ( {
428
+ template : fixture ( 'space-and-tab-slurp.ets' ) ,
429
+ data : { users } ,
430
+ } )
431
+ ) . toEqual ( fixture ( 'space-and-tab-slurp.html' ) ) ;
428
432
} ) ;
429
433
} ) ;
430
434
431
- suite ( 'single quotes' , ( ) => {
432
- test ( 'not mess up the constructed function' , ( ) => {
433
- assert . equal (
434
- ets . render ( fixture ( 'single-quote.ets' ) ) ,
435
+ describe ( 'single quotes' , ( ) => {
436
+ test ( 'not mess up the constructed function' , async ( ) => {
437
+ expect ( await ets . render ( fixture ( 'single-quote.ets' ) ) ) . toEqual (
435
438
fixture ( 'single-quote.html' )
436
439
) ;
437
440
} ) ;
438
441
} ) ;
439
442
440
- suite ( 'double quotes' , ( ) => {
441
- test ( 'not mess up the constructed function' , ( ) => {
442
- assert . equal (
443
- ets . render ( fixture ( 'double-quote.ets' ) ) ,
443
+ describe ( 'double quotes' , ( ) => {
444
+ test ( 'not mess up the constructed function' , async ( ) => {
445
+ expect ( await ets . render ( fixture ( 'double-quote.ets' ) ) ) . toEqual (
444
446
fixture ( 'double-quote.html' )
445
447
) ;
446
448
} ) ;
447
449
} ) ;
448
450
449
- suite ( 'backslashes' , ( ) => {
450
- test ( 'escape' , ( ) => {
451
- assert . equal (
452
- ets . render ( fixture ( 'backslash.ets' ) ) ,
451
+ describe ( 'backslashes' , ( ) => {
452
+ test ( 'escape' , async ( ) => {
453
+ expect ( await ets . render ( fixture ( 'backslash.ets' ) ) ) . toEqual (
453
454
fixture ( 'backslash.html' )
454
455
) ;
455
456
} ) ;
456
457
} ) ;
457
458
458
- suite ( 'messed up whitespace' , ( ) => {
459
- test ( 'work' , ( ) => {
460
- assert . equal (
461
- ets . render ( fixture ( 'messed.ets' ) , { users } ) ,
462
- fixture ( 'messed.html' )
463
- ) ;
459
+ describe ( 'messed up whitespace' , ( ) => {
460
+ test ( 'work' , async ( ) => {
461
+ expect (
462
+ await ets . render ( { template : fixture ( 'messed.ets' ) , data : { users } } )
463
+ ) . toEqual ( fixture ( 'messed.html' ) ) ;
464
464
} ) ;
465
465
} ) ;
466
466
467
- suite ( 'exceptions' , ( ) => {
468
- test ( 'produce useful stack traces' , ( ) => {
467
+ describe ( 'exceptions' , ( ) => {
468
+ test ( 'produce useful stack traces' , async ( ) => {
469
469
try {
470
- ets . render ( fixture ( 'error.ets' ) , { } , { filename : 'error.ets' } ) ;
471
- } catch ( error ) {
472
- assert . equal ( error . path , 'error.ets' ) ;
473
- let errstck = error . stack . split ( '\n' ) . slice ( 0 , 8 ) . join ( '\n' ) ;
474
- errstck = errstck . replace ( / \n / g, lf ) ;
475
- errstck = errstck . replace ( / \r \r \n / g, lf ) ;
476
- assert . equal ( errstck , fixture ( 'error.out' ) ) ;
470
+ await ets . render ( {
471
+ template : fixture ( 'error.ets' ) ,
472
+ options : { filename : 'error.ets' } ,
473
+ } ) ;
474
+ } catch ( error : unknown ) {
475
+ const err = error as { path : string ; stack : string } ;
476
+ expect ( err . path ) . toEqual ( 'error.ets' ) ;
477
+ let errorStack = err . stack . split ( '\n' ) . slice ( 0 , 8 ) . join ( '\n' ) ;
478
+ errorStack = errorStack . replace ( / \n / g, '\n' ) ;
479
+ errorStack = errorStack . replace ( / \r \r \n / g, '\n' ) ;
480
+ expect ( errorStack ) . toEqual ( fixture ( 'error.out' ) ) ;
477
481
return ;
478
482
}
479
483
480
484
throw new Error ( 'no error reported when there should be' ) ;
481
485
} ) ;
482
486
483
- test ( 'not include fancy stack info if compileDebug is false' , ( ) => {
487
+ test ( 'not include fancy stack info if compileDebug is false' , async ( ) => {
484
488
try {
485
- ets . render (
486
- fixture ( 'error.ets' ) ,
487
- { } ,
488
- {
489
+ await ets . render ( {
490
+ template : fixture ( 'error.ets' ) ,
491
+ options : {
489
492
filename : 'error.ets' ,
490
493
compileDebug : false ,
491
- }
492
- ) ;
493
- } catch ( error ) {
494
- assert . ok ( ! error . path ) ;
495
- let errstck = error . stack . split ( '\n' ) . slice ( 0 , 8 ) . join ( '\n' ) ;
496
- errstck = errstck . replace ( / \n / g, lf ) ;
497
- errstck = errstck . replace ( / \r \r \n / g, lf ) ;
498
- assert . notEqual ( errstck , fixture ( 'error.out' ) ) ;
494
+ } ,
495
+ } ) ;
496
+ } catch ( error : unknown ) {
497
+ const err = error as { path : string ; stack : string } ;
498
+ expect ( ! err . path ) . toBe ( true ) ;
499
+ let errorStack = err . stack . split ( '\n' ) . slice ( 0 , 8 ) . join ( '\n' ) ;
500
+ errorStack = errorStack . replace ( / \n / g, '\n' ) ;
501
+ errorStack = errorStack . replace ( / \r \r \n / g, '\n' ) ;
502
+ expect ( errorStack ) . toEqual ( fixture ( 'error.out' ) ) ;
499
503
return ;
500
504
}
501
505
502
506
throw new Error ( 'no error reported when there should be' ) ;
503
507
} ) ;
504
508
505
509
let unhook = null ;
506
- test ( 'log JS source when debug is set' , ( done ) => {
510
+ test ( 'log JS source when debug is set' , async ( ) => {
507
511
let out = '' ;
508
512
let needToExit = false ;
509
513
unhook = hook_stdio ( process . stdout , ( str ) => {
@@ -522,29 +526,27 @@ suite('exceptions', () => {
522
526
ets . render ( fixture ( 'hello-world.ets' ) , { } , { debug : true } ) ;
523
527
} ) ;
524
528
525
- test ( 'escape filename in errors' , ( ) => {
526
- assert . throws ( ( ) => {
527
- ets . render (
528
- '<% throw new Error("whoops"); %>' ,
529
- { } ,
530
- { filename : '<script>' }
531
- ) ;
532
- } , / E r r o r : & l t ; s c r i p t & g t ; / ) ;
529
+ test ( 'escape filename in errors' , async ( ) => {
530
+ await expect ( async ( ) => {
531
+ await ets . render ( {
532
+ template : '<% throw new Error("whoops"); %>' ,
533
+ options : { filename : '<script>' } ,
534
+ } ) ;
535
+ } ) . rejects . toThrow ( / E r r o r : & l t ; s c r i p t & g t ; / ) ;
533
536
} ) ;
534
537
535
- test ( 'filename in errors uses custom escape' , ( ) => {
536
- assert . throws ( ( ) => {
537
- ets . render (
538
- '<% throw new Error("whoops"); %>' ,
539
- { } ,
540
- {
538
+ test ( 'filename in errors uses custom escape' , async ( ) => {
539
+ await expect ( async ( ) => {
540
+ await ets . render ( {
541
+ template : '<% throw new Error("whoops"); %>' ,
542
+ options : {
541
543
filename : '<script>' ,
542
544
escape ( ) {
543
545
return 'zooby' ;
544
546
} ,
545
- }
546
- ) ;
547
- } , / E r r o r : z o o b y / ) ;
547
+ } ,
548
+ } ) ;
549
+ } ) . rejects . toThrow ( / E r r o r : z o o b y / ) ;
548
550
} ) ;
549
551
550
552
teardown ( ( ) => {
0 commit comments