@@ -4,9 +4,7 @@ import CodeFormatManager, { SAVE_TIMEOUT } from "../src/CodeFormatManager"
4
4
import UniversalDisposable from "@atom-ide-community/nuclide-commons/UniversalDisposable"
5
5
import temp from "temp"
6
6
import * as config from "../src/config"
7
- import { waitsFor } from "waitsfor"
8
-
9
- const sleep = ( n ) => new Promise ( ( r ) => setTimeout ( r , n ) )
7
+ import { waitFor , sleep } from "./utils"
10
8
11
9
jasmine . DEFAULT_TIMEOUT_INTERVAL = SAVE_TIMEOUT + 100
12
10
describe ( "CodeFormatManager" , ( ) => {
@@ -39,9 +37,7 @@ describe("CodeFormatManager", () => {
39
37
} )
40
38
textEditor . setText ( "abc" )
41
39
atom . commands . dispatch ( atom . views . getView ( textEditor ) , "code-format:format-code" )
42
- await waitsFor ( ( ) => textEditor . getText ( ) === "def" , {
43
- timeout : SAVE_TIMEOUT ,
44
- } )
40
+ await waitFor ( ( ) => textEditor . getText ( ) === "def" )
45
41
} )
46
42
it ( "format an editor using formatEntireFile" , async ( ) => {
47
43
manager . addFileProvider ( {
@@ -54,9 +50,7 @@ describe("CodeFormatManager", () => {
54
50
} )
55
51
textEditor . setText ( "abc" )
56
52
atom . commands . dispatch ( atom . views . getView ( textEditor ) , "code-format:format-code" )
57
- await waitsFor ( ( ) => textEditor . getText ( ) === "ghi" , {
58
- timeout : SAVE_TIMEOUT ,
59
- } )
53
+ await waitFor ( ( ) => textEditor . getText ( ) === "ghi" )
60
54
} )
61
55
it ( "formats an editor on type" , async ( ) => {
62
56
spyOn ( config , "getFormatOnType" ) . and . returnValue ( true )
@@ -79,11 +73,9 @@ describe("CodeFormatManager", () => {
79
73
textEditor . setCursorBufferPosition ( [ 0 , 1 ] )
80
74
textEditor . insertText ( "b" )
81
75
textEditor . insertText ( "c" )
82
- await waitsFor ( ( ) => textEditor . getText ( ) === "def" , {
83
- timeout : SAVE_TIMEOUT ,
84
- } )
76
+ await waitFor ( ( ) => textEditor . getText ( ) === "def" )
85
77
// Debouncing should ensure only one format call.
86
- expect ( spy . mock . calls . length ) . toBe ( 1 )
78
+ expect ( spy . calls . count ( ) ) . toBe ( 1 )
87
79
} )
88
80
it ( "formats an editor on save" , async ( ) => {
89
81
spyOn ( config , "getFormatOnSave" ) . and . returnValue ( true )
@@ -117,9 +109,7 @@ describe("CodeFormatManager", () => {
117
109
textEditor . save ( )
118
110
// Wait until the buffer has been saved and verify it has been saved exactly
119
111
// once.
120
- await waitsFor ( ( ) => spy . mock . calls . length > 0 , {
121
- timeout : SAVE_TIMEOUT ,
122
- } )
123
- expect ( spy . mock . calls . length ) . toBe ( 1 )
112
+ await waitFor ( ( ) => spy . calls . count ( ) > 0 )
113
+ expect ( spy . calls . count ( ) ) . toBe ( 1 )
124
114
} )
125
115
} )
0 commit comments