1- /* eslint-env node */
2- 'use strict'
3-
41import type { JobsOptions } from '../src/types'
5- import { expect } from 'chai'
6- import { default as IORedis } from 'ioredis'
2+ import IORedis from 'ioredis'
73import { after } from 'lodash'
84import {
9- after as afterAll ,
5+ expect ,
6+ afterAll ,
107 afterEach ,
11- before ,
8+ beforeAll ,
129 beforeEach ,
1310 describe ,
1411 it ,
15- } from 'mocha '
12+ } from 'bun:test '
1613import { v4 } from 'uuid'
1714import { Job , Queue , QueueEvents , Worker } from '../src/classes'
1815import { delay , getParentKey , removeAllQueueData } from '../src/utils'
@@ -23,8 +20,9 @@ describe('Job', () => {
2320
2421 let queue : Queue
2522 let queueName : string
26- let connection
27- before ( async ( ) => {
23+ let connection : IORedis
24+
25+ beforeAll ( async ( ) => {
2826 connection = new IORedis ( redisHost , { maxRetriesPerRequest : null } )
2927 } )
3028
@@ -62,7 +60,7 @@ describe('Job', () => {
6260 expect ( storedJob ) . toHaveProperty ( 'data' )
6361
6462 expect ( storedJob . data . foo ) . toBe ( 'bar' )
65- expect ( storedJob . opts ) . to . be . an ( 'object' )
63+ expect ( storedJob . opts ) . toBeObject ( )
6664 expect ( storedJob . opts . timestamp ) . toBe ( timestamp )
6765 } )
6866
@@ -87,7 +85,7 @@ describe('Job', () => {
8785 const data = { foo : 'bar' } // 13 bytes
8886 const opts = { sizeLimit : 20 }
8987 const createdJob = await Job . create ( queue , 'test' , data , opts )
90- expect ( createdJob ) . to . not . be . null
88+ expect ( createdJob ) . not . toBeNull ( )
9189 expect ( createdJob ) . toHaveProperty ( 'opts' )
9290 expect ( createdJob . opts . sizeLimit ) . toBe ( 20 )
9391 } )
@@ -207,7 +205,7 @@ describe('Job', () => {
207205 job . progress = 20
208206 const json = JSON . stringify ( job )
209207 const parsed = JSON . parse ( json )
210- expect ( parsed ) . to . have . deep . property ( 'data' , data )
208+ expect ( parsed ) . toHaveProperty ( 'data' , data )
211209 expect ( parsed ) . toHaveProperty ( 'name' , 'test' )
212210 expect ( parsed ) . toHaveProperty ( 'returnvalue' , 1 )
213211 expect ( parsed ) . toHaveProperty ( 'progress' , 20 )
@@ -226,7 +224,7 @@ describe('Job', () => {
226224 const job = await Job . create ( queue , 'test' , data )
227225 const json = JSON . stringify ( job )
228226 const parsed = JSON . parse ( json )
229- expect ( parsed ) . to . have . deep . property ( 'data' , data )
227+ expect ( parsed ) . toHaveProperty ( 'data' , data )
230228
231229 const newQueue = new Queue ( queueName , { connection, prefix } )
232230 let worker : Worker
@@ -390,24 +388,24 @@ describe('Job', () => {
390388 const job = await Job . create ( queue , 'test' , { foo : 'bar' } )
391389 await job . updateProgress ( { total : 120 , completed : 40 } )
392390 const storedJob = await Job . fromId ( queue , job . id ! )
393- expect ( storedJob ! . progress ) . to . eql ( { total : 120 , completed : 40 } )
391+ expect ( storedJob ! . progress ) . toEqual ( { total : 120 , completed : 40 } )
394392 } )
395393
396394 it ( 'can set and get progress as string' , async ( ) => {
397395 const job = await Job . create ( queue , 'test' , { foo : 'bar' } )
398396 await job . updateProgress ( 'hello, world!' )
399397 const storedJob = await Job . fromId ( queue , job . id ! )
400- expect ( storedJob ! . progress ) . to . eql ( 'hello, world!' )
398+ expect ( storedJob ! . progress ) . toEqual ( 'hello, world!' )
401399 } )
402400
403401 it ( 'can set and get progress as boolean' , async ( ) => {
404402 const job = await Job . create ( queue , 'test' , { foo : 'bar' } )
405403 await job . updateProgress ( false )
406404 let storedJob = await Job . fromId ( queue , job . id ! )
407- expect ( storedJob ! . progress ) . to . eql ( false )
405+ expect ( storedJob ! . progress ) . toEqual ( false )
408406 await job . updateProgress ( true )
409407 storedJob = await Job . fromId ( queue , job . id ! )
410- expect ( storedJob ! . progress ) . to . eql ( true )
408+ expect ( storedJob ! . progress ) . toEqual ( true )
411409 } )
412410
413411 it ( 'can set progress as number using the Queue instance' , async ( ) => {
@@ -423,7 +421,7 @@ describe('Job', () => {
423421 const job = await Job . create ( queue , 'test' , { foo : 'bar' } )
424422 await queue . updateJobProgress ( job . id ! , { total : 120 , completed : 40 } )
425423 const storedJob = await Job . fromId ( queue , job . id ! )
426- expect ( storedJob ! . progress ) . to . eql ( { total : 120 , completed : 40 } )
424+ expect ( storedJob ! . progress ) . toEqual ( { total : 120 , completed : 40 } )
427425 } )
428426
429427 describe ( 'when job is removed' , ( ) => {
@@ -696,7 +694,7 @@ describe('Job', () => {
696694
697695 const isCompleted = await job . isCompleted ( )
698696
699- expect ( isCompleted ) . to . be . false
697+ expect ( isCompleted ) . toBeFalse ( )
700698
701699 await childrenWorker . close ( )
702700 await parentWorker . close ( )
@@ -716,7 +714,7 @@ describe('Job', () => {
716714 await job . moveToFailed ( new Error ( 'test error' ) , '0' , true )
717715 const isFailed2 = await job . isFailed ( )
718716 expect ( isFailed2 ) . toBe ( true )
719- expect ( job . stacktrace ) . not . be . equal ( null )
717+ expect ( job . stacktrace ) . not . toEqual ( null )
720718 expect ( job . stacktrace . length ) . toBe ( 1 )
721719 expect ( job . stacktrace [ 0 ] ) . toInclude ( 'test_job.ts' )
722720 await worker . close ( )
@@ -734,7 +732,7 @@ describe('Job', () => {
734732 await job . moveToFailed ( new CustomError ( 'test error' ) , '0' , true )
735733 const isFailed2 = await job . isFailed ( )
736734 expect ( isFailed2 ) . toBe ( true )
737- expect ( job . stacktrace ) . not . be . equal ( null )
735+ expect ( job . stacktrace ) . not . toEqual ( null )
738736 expect ( job . stacktrace . length ) . toBe ( 1 )
739737 expect ( job . stacktrace [ 0 ] ) . toInclude ( 'test_job.ts' )
740738 await worker . close ( )
@@ -763,7 +761,7 @@ describe('Job', () => {
763761
764762 const isFailed2 = await job . isFailed ( )
765763 expect ( isFailed2 ) . toBe ( false )
766- expect ( job . stacktrace ) . not . be . equal ( null )
764+ expect ( job . stacktrace ) . not . toEqual ( null )
767765 expect ( job . stacktrace . length ) . toBe ( 1 )
768766 const isWaiting = await job . isWaiting ( )
769767 expect ( isWaiting ) . toBe ( true )
@@ -841,7 +839,7 @@ describe('Job', () => {
841839
842840 expect ( isFailed2 ) . toBe ( true )
843841 expect ( state ) . toBe ( 'failed' )
844- expect ( job . stacktrace ) . not . be . equal ( null )
842+ expect ( job . stacktrace ) . not . toEqual ( null )
845843 expect ( job . stacktrace . length ) . toBe ( 1 )
846844 await worker . close ( )
847845 } )
@@ -867,7 +865,7 @@ describe('Job', () => {
867865 const isFailed2 = await job . isFailed ( )
868866
869867 expect ( isFailed2 ) . toBe ( false )
870- expect ( job . stacktrace ) . not . be . equal ( null )
868+ expect ( job . stacktrace ) . not . toEqual ( null )
871869 expect ( job . stacktrace . length ) . toBe ( 1 )
872870 const isDelayed = await job . isDelayed ( )
873871 expect ( isDelayed ) . toBe ( true )
@@ -893,8 +891,8 @@ describe('Job', () => {
893891 await job . moveToFailed ( new Error ( 'failed once' ) , '0' , true )
894892 const isFailed1 = await job . isFailed ( )
895893 const stackTrace1 = job . stacktrace [ 0 ]
896- expect ( isFailed1 ) . to . be . false
897- expect ( job . stacktrace ) . not . be . equal ( null )
894+ expect ( isFailed1 ) . toBeFalse ( )
895+ expect ( job . stacktrace ) . not . toEqual ( null )
898896 expect ( job . stacktrace . length ) . toBe ( stackTraceLimit )
899897 // second time failed.
900898 const again = ( await worker . getNextJob ( token ) ) as Job
@@ -904,7 +902,7 @@ describe('Job', () => {
904902 expect ( isFailed2 ) . toBeTrue ( )
905903 expect ( again . name ) . toBe ( job . name )
906904 expect ( again . stacktrace . length ) . toBe ( stackTraceLimit )
907- expect ( stackTrace1 ) . not . be . equal ( stackTrace2 )
905+ expect ( stackTrace1 ) . not . toEqual ( stackTrace2 )
908906 await worker . close ( )
909907 } )
910908
@@ -925,7 +923,7 @@ describe('Job', () => {
925923 // first time failed.
926924 await job . moveToFailed ( new Error ( 'failed once' ) , '0' , true )
927925 const isFailed1 = await job . isFailed ( )
928- expect ( isFailed1 ) . to . be . false
926+ expect ( isFailed1 ) . toBeFalse ( )
929927 expect ( job . stacktrace . length ) . toBe ( stackTraceLimit )
930928 // second time failed.
931929 const again = ( await worker . getNextJob ( token ) ) as Job
@@ -947,7 +945,7 @@ describe('Job', () => {
947945 await job . moveToFailed ( new Error ( 'test error' ) , '0' )
948946 const sameJob = await queue . getJob ( id ! )
949947 expect ( sameJob ) . toBeTruthy ( )
950- expect ( sameJob . stacktrace ) . to . be . not . empty
948+ expect ( sameJob . stacktrace ) . not . toBeEmpty ( )
951949 await worker . close ( )
952950 } )
953951 } )
@@ -1770,7 +1768,7 @@ describe('Job', () => {
17701768
17711769 const result = await job . waitUntilFinished ( queueEvents )
17721770
1773- expect ( result ) . to . be . an ( 'object' )
1771+ expect ( result ) . toBeObject ( )
17741772 expect ( result . resultFoo ) . equal ( 'bar' )
17751773
17761774 await worker . close ( )
@@ -1790,7 +1788,7 @@ describe('Job', () => {
17901788 await delay ( 600 )
17911789
17921790 const result = await job . waitUntilFinished ( queueEvents )
1793- expect ( result ) . to . be . an ( 'object' )
1791+ expect ( result ) . toBeObject ( )
17941792 expect ( result . resultFoo ) . equal ( 'bar' )
17951793
17961794 await worker . close ( )
@@ -1842,7 +1840,7 @@ describe('Job', () => {
18421840 await delay ( 500 )
18431841 const result = await job . waitUntilFinished ( queueEvents )
18441842
1845- expect ( result ) . to . be . an ( 'object' )
1843+ expect ( result ) . toBeObject ( )
18461844 expect ( result . resultFoo ) . equal ( 'bar' )
18471845
18481846 await worker . close ( )
0 commit comments