11// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
22// See LICENSE in the project root for license information.
33
4- /// <reference types='mocha' />
5-
6- import { assert } from 'chai' ;
74import * as path from 'path' ;
85import { LockFile , getProcessStartTime , getProcessStartTimeFromProcStat } from '../LockFile' ;
96import { FileSystem } from '../FileSystem' ;
@@ -21,33 +18,34 @@ describe('LockFile', () => {
2118
2219 describe ( 'getLockFilePath' , ( ) => {
2320 it ( 'only acceps alphabetical characters for resource name' , ( ) => {
24- assert . doesNotThrow ( ( ) => {
21+ expect ( ( ) => {
2522 LockFile . getLockFilePath ( process . cwd ( ) , 'foo123' ) ;
26- } ) ;
27- assert . doesNotThrow ( ( ) => {
23+ } ) . not . toThrow ( ) ;
24+ expect ( ( ) => {
2825 LockFile . getLockFilePath ( process . cwd ( ) , 'bar.123' ) ;
29- } ) ;
30- assert . doesNotThrow ( ( ) => {
26+ } ) . not . toThrow ( ) ;
27+ expect ( ( ) => {
3128 LockFile . getLockFilePath ( process . cwd ( ) , 'foo.bar' ) ;
32- } ) ;
33- assert . doesNotThrow ( ( ) => {
29+ } ) . not . toThrow ( ) ;
30+ expect ( ( ) => {
3431 LockFile . getLockFilePath ( process . cwd ( ) , 'lock-file.123' ) ;
35- } ) ;
36- assert . throws ( ( ) => {
32+ } ) . not . toThrow ( ) ;
33+
34+ expect ( ( ) => {
3735 LockFile . getLockFilePath ( process . cwd ( ) , '.foo123' ) ;
38- } ) ;
39- assert . throws ( ( ) => {
36+ } ) . toThrow ( ) ;
37+ expect ( ( ) => {
4038 LockFile . getLockFilePath ( process . cwd ( ) , 'foo123.' ) ;
41- } ) ;
42- assert . throws ( ( ) => {
39+ } ) . toThrow ( ) ;
40+ expect ( ( ) => {
4341 LockFile . getLockFilePath ( process . cwd ( ) , '-foo123' ) ;
44- } ) ;
45- assert . throws ( ( ) => {
42+ } ) . toThrow ( ) ;
43+ expect ( ( ) => {
4644 LockFile . getLockFilePath ( process . cwd ( ) , 'foo123-' ) ;
47- } ) ;
48- assert . throws ( ( ) => {
45+ } ) . toThrow ( ) ;
46+ expect ( ( ) => {
4947 LockFile . getLockFilePath ( process . cwd ( ) , '' ) ;
50- } ) ;
48+ } ) . toThrow ( ) ;
5149 } ) ;
5250 } ) ;
5351
@@ -63,50 +61,52 @@ describe('LockFile', () => {
6361 it ( 'returns undefined if too few values are contained in /proc/[pid]/stat (1)' , ( ) => {
6462 const stat : string = createStatOutput ( '(bash)' , 1 ) ;
6563 const ret : string | undefined = getProcessStartTimeFromProcStat ( stat ) ;
66- assert . strictEqual ( ret , undefined ) ;
64+ expect ( ret ) . toBeUndefined ( ) ;
6765 } ) ;
6866 it ( 'returns undefined if too few values are contained in /proc/[pid]/stat (2)' , ( ) => {
6967 const stat : string = createStatOutput ( '(bash)' , 0 ) ;
7068 const ret : string | undefined = getProcessStartTimeFromProcStat ( stat ) ;
71- assert . strictEqual ( ret , undefined ) ;
69+ expect ( ret ) . toBeUndefined ( ) ;
7270 } ) ;
7371 it ( 'returns the correct start time if the second value in /proc/[pid]/stat contains spaces' , ( ) => {
7472 let stat : string = createStatOutput ( '(bash 2)' , 18 ) ;
7573 const value22 : string = '12345' ;
7674 stat += ` ${ value22 } ` ;
7775 const ret : string | undefined = getProcessStartTimeFromProcStat ( stat ) ;
78- assert . strictEqual ( ret , value22 ) ;
76+ expect ( ret ) . toEqual ( value22 ) ;
7977 } ) ;
8078 it ( 'returns the correct start time if there are 22 values in /proc/[pid]/stat, including a trailing line '
8179 + 'terminator' , ( ) => {
8280 let stat : string = createStatOutput ( '(bash)' , 18 ) ;
8381 const value22 : string = '12345' ;
8482 stat += ` ${ value22 } \n` ;
8583 const ret : string | undefined = getProcessStartTimeFromProcStat ( stat ) ;
86- assert . strictEqual ( ret , value22 ) ;
84+ expect ( ret ) . toEqual ( value22 ) ;
8785 } ) ;
8886 it ( 'returns the correct start time if the second value in /proc/[pid]/stat does not contain spaces' , ( ) => {
8987 let stat : string = createStatOutput ( '(bash)' , 18 ) ;
9088 const value22 : string = '12345' ;
9189 stat += ` ${ value22 } ` ;
9290 const ret : string | undefined = getProcessStartTimeFromProcStat ( stat ) ;
93- assert . strictEqual ( ret , value22 ) ;
91+ expect ( ret ) . toEqual ( value22 ) ;
9492 } ) ;
9593 } ) ;
9694
9795 if ( process . platform === 'darwin' || process . platform === 'linux' ) {
9896 describe ( 'Linux and Mac' , ( ) => {
9997 describe ( 'getLockFilePath()' , ( ) => {
10098 it ( 'returns a resolved path containing the pid' , ( ) => {
101- assert . equal (
102- path . join ( process . cwd ( ) , `test#${ process . pid } .lock` ) ,
99+ expect (
100+ path . join ( process . cwd ( ) , `test#${ process . pid } .lock` )
101+ ) . toEqual (
103102 LockFile . getLockFilePath ( './' , 'test' )
104103 ) ;
105104 } ) ;
106105
107106 it ( 'allows for overridden pid' , ( ) => {
108- assert . equal (
109- path . join ( process . cwd ( ) , `test#99.lock` ) ,
107+ expect (
108+ path . join ( process . cwd ( ) , `test#99.lock` )
109+ ) . toEqual (
110110 LockFile . getLockFilePath ( './' , 'test' , 99 )
111111 ) ;
112112 } ) ;
@@ -122,20 +122,20 @@ describe('LockFile', () => {
122122 const lock : LockFile | undefined = LockFile . tryAcquire ( testFolder , resourceName ) ;
123123
124124 // The lockfile should exist and be in a clean state
125- assert . isDefined ( lock ) ;
126- assert . isFalse ( lock ! . dirtyWhenAcquired ) ;
127- assert . isFalse ( lock ! . isReleased ) ;
128- assert . isTrue ( FileSystem . exists ( pidLockFileName ) ) ;
125+ expect ( lock ) . toBeDefined ( ) ;
126+ expect ( lock ! . dirtyWhenAcquired ) . toEqual ( false ) ;
127+ expect ( lock ! . isReleased ) . toEqual ( false ) ;
128+ expect ( FileSystem . exists ( pidLockFileName ) ) . toEqual ( true ) ;
129129
130130 // Ensure that we can release the "clean" lockfile
131131 lock ! . release ( ) ;
132- assert . isFalse ( FileSystem . exists ( pidLockFileName ) ) ;
133- assert . isTrue ( lock ! . isReleased ) ;
132+ expect ( FileSystem . exists ( pidLockFileName ) ) . toEqual ( false ) ;
133+ expect ( lock ! . isReleased ) . toEqual ( true ) ;
134134
135135 // Ensure we cannot release the lockfile twice
136- assert . throws ( ( ) => {
136+ expect ( ( ) => {
137137 lock ! . release ( ) ;
138- } ) ;
138+ } ) . toThrow ( ) ;
139139 } ) ;
140140
141141 it ( 'cannot acquire a lock if another valid lock exists' , ( ) => {
@@ -166,23 +166,25 @@ describe('LockFile', () => {
166166 const lock : LockFile | undefined = LockFile . tryAcquire ( testFolder , resourceName ) ;
167167
168168 // this lock should be undefined since there is an existing lock
169- assert . isUndefined ( lock ) ;
169+ expect ( lock ) . toBeUndefined ( ) ;
170170 } ) ;
171171 } ) ;
172172 }
173173
174174 if ( process . platform === 'win32' ) {
175175 describe ( 'getLockFilePath()' , ( ) => {
176176 it ( 'returns a resolved path that doesn\'t contain' , ( ) => {
177- assert . equal (
178- path . join ( process . cwd ( ) , `test.lock` ) ,
177+ expect (
178+ path . join ( process . cwd ( ) , `test.lock` )
179+ ) . toEqual (
179180 LockFile . getLockFilePath ( './' , 'test' )
180181 ) ;
181182 } ) ;
182183
183184 it ( 'ignores pid that is passed in' , ( ) => {
184- assert . equal (
185- path . join ( process . cwd ( ) , `test.lock` ) ,
185+ expect (
186+ path . join ( process . cwd ( ) , `test.lock` )
187+ ) . toEqual (
186188 LockFile . getLockFilePath ( './' , 'test' , 99 )
187189 ) ;
188190 } ) ;
@@ -202,7 +204,7 @@ describe('LockFile', () => {
202204 const lock : LockFile | undefined = LockFile . tryAcquire ( testFolder , resourceName ) ;
203205
204206 // this lock should be undefined since there is an existing lock
205- assert . isUndefined ( lock ) ;
207+ expect ( lock ) . toBeUndefined ( ) ;
206208 lockFileHandle . close ( ) ;
207209 } ) ;
208210
@@ -219,15 +221,15 @@ describe('LockFile', () => {
219221
220222 const lock : LockFile | undefined = LockFile . tryAcquire ( testFolder , resourceName ) ;
221223
222- assert . isDefined ( lock ) ;
223- assert . isTrue ( lock ! . dirtyWhenAcquired ) ;
224- assert . isFalse ( lock ! . isReleased ) ;
225- assert . isTrue ( FileSystem . exists ( lockFileName ) ) ;
224+ expect ( lock ) . toBeDefined ( ) ;
225+ expect ( lock ! . dirtyWhenAcquired ) . toEqual ( true ) ;
226+ expect ( lock ! . isReleased ) . toEqual ( false ) ;
227+ expect ( FileSystem . exists ( lockFileName ) ) . toEqual ( true ) ;
226228
227229 // Ensure that we can release the "dirty" lockfile
228230 lock ! . release ( ) ;
229- assert . isFalse ( FileSystem . exists ( lockFileName ) ) ;
230- assert . isTrue ( lock ! . isReleased ) ;
231+ expect ( FileSystem . exists ( lockFileName ) ) . toEqual ( false ) ;
232+ expect ( lock ! . isReleased ) . toEqual ( true ) ;
231233 } ) ;
232234
233235 it ( 'can acquire and close a clean lockfile' , ( ) => {
@@ -241,20 +243,20 @@ describe('LockFile', () => {
241243 const lock : LockFile | undefined = LockFile . tryAcquire ( testFolder , resourceName ) ;
242244
243245 // The lockfile should exist and be in a clean state
244- assert . isDefined ( lock ) ;
245- assert . isFalse ( lock ! . dirtyWhenAcquired ) ;
246- assert . isFalse ( lock ! . isReleased ) ;
247- assert . isTrue ( FileSystem . exists ( lockFileName ) ) ;
246+ expect ( lock ) . toBeDefined ( ) ;
247+ expect ( lock ! . dirtyWhenAcquired ) . toEqual ( false ) ;
248+ expect ( lock ! . isReleased ) . toEqual ( false ) ;
249+ expect ( FileSystem . exists ( lockFileName ) ) . toEqual ( true ) ;
248250
249251 // Ensure that we can release the "clean" lockfile
250252 lock ! . release ( ) ;
251- assert . isFalse ( FileSystem . exists ( lockFileName ) ) ;
252- assert . isTrue ( lock ! . isReleased ) ;
253+ expect ( FileSystem . exists ( lockFileName ) ) . toEqual ( false ) ;
254+ expect ( lock ! . isReleased ) . toEqual ( true ) ;
253255
254256 // Ensure we cannot release the lockfile twice
255- assert . throws ( ( ) => {
257+ expect ( ( ) => {
256258 lock ! . release ( ) ;
257- } ) ;
259+ } ) . toThrow ( ) ;
258260 } ) ;
259261 }
260262} ) ;
0 commit comments