1
1
import * as assert from "assert" ;
2
2
import * as fs from "fs" ;
3
3
import * as path from "path" ;
4
+ import * as os from "os" ;
4
5
5
6
// You can import and use all API from the 'vscode' module
6
7
// as well as import your extension to test it
@@ -9,20 +10,25 @@ import * as myExtension from "../../extension.js";
9
10
import * as uninstall from "../../commands/uninstall.js" ;
10
11
import * as sinon from "sinon" ;
11
12
13
+ let binName : string ;
14
+
15
+ if ( os . platform ( ) === "win32" ) {
16
+ binName = "nextls.exe" ;
17
+ } else {
18
+ binName = "nextls" ;
19
+ }
20
+
12
21
// TODO: should extract the tests to the directory of the file under test
13
22
suite ( "Extension Test Suite" , ( ) => {
14
23
vscode . window . showInformationMessage ( "Start all tests." ) ;
15
24
let showInformationMessage ;
16
25
17
26
setup ( function ( ) {
18
27
fs . rmSync ( "./test-bin" , { recursive : true , force : true } ) ;
19
- showInformationMessage = sinon
20
- . stub ( vscode . window , "showInformationMessage" )
21
- . returns (
22
- new Promise ( ( resolve ) => {
23
- return resolve ( { title : "Yes" } ) ;
24
- } )
25
- ) ;
28
+ showInformationMessage = sinon . stub (
29
+ vscode . window ,
30
+ "showInformationMessage"
31
+ ) ;
26
32
} ) ;
27
33
28
34
teardown ( function ( ) {
@@ -34,18 +40,18 @@ suite("Extension Test Suite", () => {
34
40
fs . mkdirSync ( "./test-bin" , { recursive : true } ) ;
35
41
36
42
let result = await myExtension . ensureNextLSDownloaded ( "test-bin" ) ;
37
- assert . equal ( path . normalize ( result ) , path . normalize ( " test-bin/nextls" ) ) ;
43
+ assert . equal ( path . normalize ( result ) , path . normalize ( ` test-bin/${ binName } ` ) ) ;
38
44
} ) ;
39
45
40
46
test ( "uninstalls Next LS" , async function ( ) {
41
47
fs . mkdirSync ( "./test-bin" , { recursive : true } ) ;
42
- fs . writeFileSync ( " ./test-bin/nextls" , "hello word" ) ;
48
+ fs . writeFileSync ( ` ./test-bin/${ binName } ` , "hello word" ) ;
43
49
44
50
await uninstall . run ( "./test-bin" ) ;
45
51
46
52
assert . equal (
47
53
showInformationMessage . getCall ( 0 ) . args [ 0 ] ,
48
- `Uninstalled Next LS from ${ path . normalize ( " test-bin/nextls" ) } `
54
+ `Uninstalled Next LS from ${ path . normalize ( ` test-bin/${ binName } ` ) } `
49
55
) ;
50
56
} ) ;
51
57
@@ -62,4 +68,30 @@ suite("Extension Test Suite", () => {
62
68
/ d u e t o E r r o r : E N O E N T : n o s u c h f i l e o r d i r e c t o r y , l s t a t /
63
69
) ;
64
70
} ) ;
71
+
72
+ if ( os . platform ( ) !== "win32" ) {
73
+ // TODO: make a test for the opposite case. As of right now, I'm not entirely
74
+ // sure how to set globalState inside a test before the extension activates.
75
+ test ( "forces a download if the special key is not set" , async function ( ) {
76
+ let fixpath = path . join ( __dirname , "../../../src/test/fixtures/basic" ) ;
77
+ let binpath = path . join ( fixpath , "test-bin" ) ;
78
+ fs . mkdirSync ( path . normalize ( binpath ) , { recursive : true } ) ;
79
+ fs . writeFileSync (
80
+ path . normalize ( path . join ( binpath , binName ) ) ,
81
+ "hello world"
82
+ ) ;
83
+ let ext = vscode . extensions . getExtension ( "elixir-tools.elixir-tools" ) ;
84
+
85
+ await ext . activate ( ) ;
86
+
87
+ const doc = await vscode . workspace . openTextDocument (
88
+ path . join ( fixpath , "mix.exs" )
89
+ ) ;
90
+ await vscode . window . showTextDocument ( doc ) ;
91
+ await new Promise ( ( resolve ) => setTimeout ( resolve , 1000 ) ) ;
92
+
93
+ let nextls = fs . readFileSync ( path . normalize ( path . join ( binpath , binName ) ) ) ;
94
+ assert . notEqual ( "hello world" , nextls ) ;
95
+ } ) . timeout ( 5000 ) ;
96
+ }
65
97
} ) ;
0 commit comments