1
+ /* eslint-disable no-process-env */
1
2
import * as assert from "assert" ;
2
- import * as fs from "fs" ;
3
3
import * as path from "path" ;
4
- import * as os from "os" ;
5
4
6
5
import * as vscode from "vscode" ;
6
+ import sinon from "sinon" ;
7
7
8
8
import { Ruby , ManagerIdentifier } from "../../ruby" ;
9
9
import { WorkspaceChannel } from "../../workspaceChannel" ;
10
10
import { LOG_CHANNEL } from "../../common" ;
11
11
12
12
suite ( "Ruby environment activation" , ( ) => {
13
- let ruby : Ruby ;
13
+ const workspacePath = path . dirname (
14
+ path . dirname ( path . dirname ( path . dirname ( __dirname ) ) ) ,
15
+ ) ;
16
+ const workspaceFolder : vscode . WorkspaceFolder = {
17
+ uri : vscode . Uri . file ( workspacePath ) ,
18
+ name : path . basename ( workspacePath ) ,
19
+ index : 0 ,
20
+ } ;
14
21
15
22
test ( "Activate fetches Ruby information when outside of Ruby LSP" , async ( ) => {
16
- if ( os . platform ( ) !== "win32" ) {
17
- // eslint-disable-next-line no-process-env
18
- process . env . SHELL = "/bin/bash" ;
19
- }
23
+ const manager = process . env . CI
24
+ ? ManagerIdentifier . None
25
+ : ManagerIdentifier . Chruby ;
20
26
21
- const tmpPath = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , "ruby-lsp-test-" ) ) ;
22
- fs . writeFileSync ( path . join ( tmpPath , ".ruby-version" ) , "3.3.0" ) ;
27
+ const configStub = sinon
28
+ . stub ( vscode . workspace , "getConfiguration" )
29
+ . returns ( {
30
+ get : ( name : string ) => {
31
+ if ( name === "rubyVersionManager" ) {
32
+ return manager ;
33
+ } else if ( name === "bundleGemfile" ) {
34
+ return "" ;
35
+ }
36
+
37
+ return undefined ;
38
+ } ,
39
+ } as unknown as vscode . WorkspaceConfiguration ) ;
23
40
24
41
const context = {
25
42
extensionMode : vscode . ExtensionMode . Test ,
26
43
} as vscode . ExtensionContext ;
27
44
const outputChannel = new WorkspaceChannel ( "fake" , LOG_CHANNEL ) ;
28
45
29
- ruby = new Ruby (
30
- context ,
31
- {
32
- uri : vscode . Uri . file ( tmpPath ) ,
33
- } as vscode . WorkspaceFolder ,
34
- outputChannel ,
35
- ) ;
36
- await ruby . activateRuby (
37
- // eslint-disable-next-line no-process-env
38
- process . env . CI ? ManagerIdentifier . None : ManagerIdentifier . Chruby ,
39
- ) ;
46
+ const ruby = new Ruby ( context , workspaceFolder , outputChannel ) ;
47
+ await ruby . activateRuby ( ) ;
40
48
41
49
assert . ok ( ruby . rubyVersion , "Expected Ruby version to be set" ) ;
42
50
assert . notStrictEqual (
@@ -45,6 +53,46 @@ suite("Ruby environment activation", () => {
45
53
"Expected YJIT support to be set to true or false" ,
46
54
) ;
47
55
48
- fs . rmSync ( tmpPath , { recursive : true , force : true } ) ;
56
+ configStub . restore ( ) ;
57
+ } ) . timeout ( 10000 ) ;
58
+
59
+ test ( "Deletes verbose and GC settings from activated environment" , async ( ) => {
60
+ const manager = process . env . CI
61
+ ? ManagerIdentifier . None
62
+ : ManagerIdentifier . Chruby ;
63
+
64
+ const configStub = sinon
65
+ . stub ( vscode . workspace , "getConfiguration" )
66
+ . returns ( {
67
+ get : ( name : string ) => {
68
+ if ( name === "rubyVersionManager" ) {
69
+ return manager ;
70
+ } else if ( name === "bundleGemfile" ) {
71
+ return "" ;
72
+ }
73
+
74
+ return undefined ;
75
+ } ,
76
+ } as unknown as vscode . WorkspaceConfiguration ) ;
77
+
78
+ const context = {
79
+ extensionMode : vscode . ExtensionMode . Test ,
80
+ } as vscode . ExtensionContext ;
81
+ const outputChannel = new WorkspaceChannel ( "fake" , LOG_CHANNEL ) ;
82
+
83
+ const ruby = new Ruby ( context , workspaceFolder , outputChannel ) ;
84
+
85
+ process . env . VERBOSE = "1" ;
86
+ process . env . DEBUG = "WARN" ;
87
+ process . env . RUBY_GC_HEAP_GROWTH_FACTOR = "1.7" ;
88
+ await ruby . activateRuby ( ) ;
89
+
90
+ assert . strictEqual ( ruby . env . VERBOSE , undefined ) ;
91
+ assert . strictEqual ( ruby . env . DEBUG , undefined ) ;
92
+ assert . strictEqual ( ruby . env . RUBY_GC_HEAP_GROWTH_FACTOR , undefined ) ;
93
+ delete process . env . VERBOSE ;
94
+ delete process . env . DEBUG ;
95
+ delete process . env . RUBY_GC_HEAP_GROWTH_FACTOR ;
96
+ configStub . restore ( ) ;
49
97
} ) ;
50
98
} ) ;
0 commit comments