@@ -7,21 +7,22 @@ var beforeEach = require('mocha').beforeEach;
7
7
var afterEach = require ( 'mocha' ) . afterEach ;
8
8
var expect = require ( 'chai' ) . expect ;
9
9
var mockFs = require ( 'mock-fs' ) ;
10
- var CancellationToken = require ( '../../lib/CancellationToken' ) . CancellationToken ;
10
+ var CancellationToken = require ( '../../lib/CancellationToken' )
11
+ . CancellationToken ;
11
12
12
- describe ( '[UNIT] CancellationToken' , function ( ) {
13
- beforeEach ( function ( ) {
13
+ describe ( '[UNIT] CancellationToken' , function ( ) {
14
+ beforeEach ( function ( ) {
14
15
var fsTree = { } ;
15
16
fsTree [ os . tmpdir ( ) ] = mockFs . directory ( ) ;
16
17
17
18
mockFs ( fsTree ) ;
18
19
} ) ;
19
20
20
- afterEach ( function ( ) {
21
+ afterEach ( function ( ) {
21
22
mockFs . restore ( ) ;
22
23
} ) ;
23
24
24
- it ( 'should create valid cancellation token' , function ( ) {
25
+ it ( 'should create valid cancellation token' , function ( ) {
25
26
var tokenA = new CancellationToken ( ) ;
26
27
expect ( tokenA . isCancellationRequested ( ) ) . to . be . false ;
27
28
@@ -35,42 +36,54 @@ describe('[UNIT] CancellationToken', function () {
35
36
expect ( tokenD . isCancellationRequested ( ) ) . to . be . true ;
36
37
} ) ;
37
38
38
- it ( 'should serialize to JSON' , function ( ) {
39
+ it ( 'should serialize to JSON' , function ( ) {
39
40
var tokenA = new CancellationToken ( ) ;
40
41
var json = JSON . stringify ( tokenA ) ;
41
42
42
43
expect ( json ) . to . be . a ( 'string' ) ;
43
- expect ( function ( ) { JSON . parse ( json ) ; } ) . to . not . throw ( Error ) ;
44
+ expect ( function ( ) {
45
+ JSON . parse ( json ) ;
46
+ } ) . to . not . throw ( Error ) ;
44
47
expect ( JSON . parse ( json ) ) . to . be . a ( 'object' ) ;
45
48
46
49
var tokenB = CancellationToken . createFromJSON ( JSON . parse ( json ) ) ;
47
- expect ( tokenA . getCancellationFilePath ( ) ) . to . be . equal ( tokenB . getCancellationFilePath ( ) ) ;
48
- expect ( tokenA . isCancellationRequested ( ) ) . to . be . equal ( tokenB . isCancellationRequested ( ) ) ;
50
+ expect ( tokenA . getCancellationFilePath ( ) ) . to . be . equal (
51
+ tokenB . getCancellationFilePath ( )
52
+ ) ;
53
+ expect ( tokenA . isCancellationRequested ( ) ) . to . be . equal (
54
+ tokenB . isCancellationRequested ( )
55
+ ) ;
49
56
} ) ;
50
57
51
- it ( 'should generate path in os.tmpdir() directory' , function ( ) {
58
+ it ( 'should generate path in os.tmpdir() directory' , function ( ) {
52
59
var tokenA = new CancellationToken ( ) ;
53
60
54
- expect ( tokenA . getCancellationFilePath ( ) . indexOf ( os . tmpdir ( ) ) ) . to . be . equal ( 0 ) ;
61
+ expect ( tokenA . getCancellationFilePath ( ) . indexOf ( os . tmpdir ( ) ) ) . to . be . equal (
62
+ 0
63
+ ) ;
55
64
} ) ;
56
65
57
- it ( 'should throw ts.OperationCanceledException error on cancelled' , function ( ) {
66
+ it ( 'should throw ts.OperationCanceledException error on cancelled' , function ( ) {
58
67
var tokenA = new CancellationToken ( ) ;
59
- expect ( function ( ) { tokenA . throwIfCancellationRequested ( ) ; } ) . to . not . throw ( ) ;
68
+ expect ( function ( ) {
69
+ tokenA . throwIfCancellationRequested ( ) ;
70
+ } ) . to . not . throw ( ) ;
60
71
61
72
var tokenB = new CancellationToken ( 'rgeer#R23r$#T$3t#$t43' , true ) ;
62
- expect ( function ( ) { tokenB . throwIfCancellationRequested ( ) ; } ) . to . throw ( ts . OperationCanceledException ) ;
73
+ expect ( function ( ) {
74
+ tokenB . throwIfCancellationRequested ( ) ;
75
+ } ) . to . throw ( ts . OperationCanceledException ) ;
63
76
} ) ;
64
77
65
- it ( 'should write file in filesystem on requestCancellation' , function ( ) {
78
+ it ( 'should write file in filesystem on requestCancellation' , function ( ) {
66
79
var tokenA = new CancellationToken ( ) ;
67
80
tokenA . requestCancellation ( ) ;
68
81
69
82
expect ( tokenA . isCancellationRequested ( ) ) . to . be . true ;
70
83
expect ( fs . existsSync ( tokenA . getCancellationFilePath ( ) ) ) . to . be . true ;
71
84
} ) ;
72
85
73
- it ( 'should cleanup file on cleanupCancellation' , function ( ) {
86
+ it ( 'should cleanup file on cleanupCancellation' , function ( ) {
74
87
var tokenA = new CancellationToken ( ) ;
75
88
tokenA . requestCancellation ( ) ;
76
89
tokenA . cleanupCancellation ( ) ;
@@ -79,18 +92,24 @@ describe('[UNIT] CancellationToken', function () {
79
92
expect ( fs . existsSync ( tokenA . getCancellationFilePath ( ) ) ) . to . be . false ;
80
93
81
94
// make sure we can call it as many times as we want to
82
- expect ( function ( ) { tokenA . cleanupCancellation ( ) ; } ) . to . not . throw ( Error ) ;
95
+ expect ( function ( ) {
96
+ tokenA . cleanupCancellation ( ) ;
97
+ } ) . to . not . throw ( Error ) ;
83
98
expect ( tokenA . isCancellationRequested ( ) ) . to . be . false ;
84
99
} ) ;
85
100
86
- it ( 'should not throw error on cleanupCancellation with no file exists' , function ( ) {
101
+ it ( 'should not throw error on cleanupCancellation with no file exists' , function ( ) {
87
102
var tokenA = new CancellationToken ( 'some_file_that_doesnt_exists' , true ) ;
88
103
89
- expect ( function ( ) { tokenA . cleanupCancellation ( ) ; } ) . to . not . throw ( ) ;
90
- expect ( function ( ) { tokenA . cleanupCancellation ( ) ; } ) . to . not . throw ( ) ;
104
+ expect ( function ( ) {
105
+ tokenA . cleanupCancellation ( ) ;
106
+ } ) . to . not . throw ( ) ;
107
+ expect ( function ( ) {
108
+ tokenA . cleanupCancellation ( ) ;
109
+ } ) . to . not . throw ( ) ;
91
110
} ) ;
92
111
93
- it ( 'should throttle check for 10ms' , function ( done ) {
112
+ it ( 'should throttle check for 10ms' , function ( done ) {
94
113
var tokenA = new CancellationToken ( ) ;
95
114
var tokenB = CancellationToken . createFromJSON ( tokenA . toJSON ( ) ) ;
96
115
var start = Date . now ( ) ;
@@ -107,7 +126,7 @@ describe('[UNIT] CancellationToken', function () {
107
126
expect ( tokenB . isCancellationRequested ( ) ) . to . be . false ;
108
127
}
109
128
110
- setTimeout ( function ( ) {
129
+ setTimeout ( function ( ) {
111
130
expect ( tokenB . isCancellationRequested ( ) ) . to . be . true ;
112
131
done ( ) ;
113
132
} , 11 ) ;
0 commit comments