forked from onivim/oni2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FormatOnSaveTest.re
102 lines (89 loc) · 2.55 KB
/
FormatOnSaveTest.re
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
open Oni_Core;
open Oni_Model;
open Oni_IntegrationTestLib;
module TS = TextSynchronization;
let configuration = {|
{
"editor.formatOnSave": true
}
|};
runTest(
~configuration=Some(configuration),
~name="FormatOnSave",
({input, dispatch, wait, key, _}) => {
wait(~timeout=30.0, ~name="Exthost is initialized", (state: State.t) =>
Feature_Exthost.isInitialized(state.exthost)
);
// Wait until the extension is activated
// Give some time for the exthost to start
wait(
~timeout=30.0,
~name="Validate the 'oni-dev' extension gets activated",
(state: State.t) =>
List.exists(
id => id == "oni-dev-extension",
state.extensions |> Feature_Extensions.activatedIds,
)
);
let unformattedFilePath = getAssetPath("test.unformatted.js");
// Create a buffer
dispatch(
Actions.OpenFileByPath(
unformattedFilePath,
SplitDirection.Current,
None,
),
);
wait(
~timeout=30.0,
~name="Validate first line of buffer is unformatted",
(state: State.t) => {
Selectors.getActiveBuffer(state)
|> Option.map(buffer =>
if (Buffer.getNumberOfLines(buffer) > 0) {
let rawLine = Buffer.getLine(0, buffer) |> BufferLine.raw;
String.equal(rawLine, " console.log");
} else {
false;
}
)
|> Option.value(~default=false)
});
// Wait for JS extension, we need it for formatting
wait(
~timeout=30.0,
~name=
"Validate the 'vscode.typescript-language-features' extension gets activated",
(state: State.t) => {
Feature_Extensions.activatedIds(state.extensions)
|> List.iter(id => prerr_endline(id));
List.exists(
id => id == "vscode.typescript-language-features",
state.extensions |> Feature_Extensions.activatedIds,
);
},
);
// Save file
input(":");
input("w");
input("!");
key(EditorInput.Key.Return);
wait(
~timeout=30.0,
~name="Validate first line of buffer gets formatted",
(state: State.t) => {
Selectors.getActiveBuffer(state)
|> Option.map(buffer => {
let rawLine = Buffer.getLine(0, buffer) |> BufferLine.raw;
String.equal(rawLine, "console.log");
})
|> Option.value(~default=false)
});
TS.validateTextIsSynchronized(
~expectedText=Some("console.log|console.warn|console.error"),
~description="after formatting",
dispatch,
wait,
);
},
);