@@ -23,15 +23,42 @@ suite('Config Test Suite', () => {
2323 return setConfigValue ( ConfigKey . FOCUSED_PROJECTS , undefined )
2424 } )
2525
26+ const mockDvcMonoRepo = Uri . file ( resolve ( dvcDemoPath ) ) . fsPath
27+ const mockDvcSubRoot1 = Uri . file ( join ( mockDvcMonoRepo , 'data' ) ) . fsPath
28+ const mockDvcSubRoot2 = Uri . file ( join ( mockDvcMonoRepo , '.dvc' ) ) . fsPath
29+
30+ const buildConfig = async ( ) => {
31+ const extensionsChanged = disposable . track ( new EventEmitter < void > ( ) )
32+ const config = disposable . track ( new Config ( extensionsChanged . event ) )
33+ await config . isReady ( )
34+
35+ const mockGetWorkspaceFolders = stub (
36+ WorkspaceFolders ,
37+ 'getWorkspaceFolders'
38+ ) . returns ( [ mockDvcMonoRepo ] )
39+
40+ return { config, extensionsChanged, mockGetWorkspaceFolders }
41+ }
42+
43+ const getConfigUpdatedPromise = ( ) =>
44+ new Promise ( resolve => {
45+ const singleUseListener = workspace . onDidChangeConfiguration ( e => {
46+ if ( e . affectsConfiguration ( ConfigKey . FOCUSED_PROJECTS ) ) {
47+ resolve ( undefined )
48+ disposable . untrack ( singleUseListener )
49+ singleUseListener . dispose ( )
50+ }
51+ } )
52+ disposable . track ( singleUseListener )
53+ } )
54+
2655 describe ( 'Config' , ( ) => {
2756 it ( 'should re-fetch the python extension API (and execution details) if any extensions are enabled/disabled or installed/uninstalled' , async ( ) => {
2857 const mockGetExtensionAPI = stub ( Extensions , 'getExtensionAPI' ) . resolves (
2958 undefined
3059 )
3160
32- const extensionsChanged = disposable . track ( new EventEmitter < void > ( ) )
33-
34- const config = disposable . track ( new Config ( extensionsChanged . event ) )
61+ const { config, extensionsChanged } = await buildConfig ( )
3562 expect ( mockGetExtensionAPI ) . to . be . called
3663 expect ( config . getPythonBinPath ( ) ) . to . be . undefined
3764
@@ -52,113 +79,79 @@ suite('Config Test Suite', () => {
5279 expect ( config . getPythonBinPath ( ) ) . to . equal ( pythonBinPath )
5380 } )
5481
55- it ( 'should fire an event if dvc.focusedProjects is changed' , async ( ) => {
56- const getConfigUpdatedPromise = ( ) =>
57- new Promise ( resolve => {
58- const singleUseListener = workspace . onDidChangeConfiguration ( e => {
59- if ( e . affectsConfiguration ( ConfigKey . FOCUSED_PROJECTS ) ) {
60- resolve ( undefined )
61- disposable . untrack ( singleUseListener )
62- singleUseListener . dispose ( )
63- }
64- } )
65- disposable . track ( singleUseListener )
66- } )
67-
68- const extensionsChanged = disposable . track ( new EventEmitter < void > ( ) )
69- const config = disposable . track ( new Config ( extensionsChanged . event ) )
70- await config . isReady ( )
71-
72- let configUpdated = getConfigUpdatedPromise ( )
73- const mockDvcMonoRepo = Uri . file ( resolve ( dvcDemoPath ) ) . fsPath
74- const mockGetWorkspaceFolders = stub (
75- WorkspaceFolders ,
76- 'getWorkspaceFolders'
77- ) . returns ( [ mockDvcMonoRepo ] )
78- const mockDvcSubRoot1 = Uri . file ( join ( mockDvcMonoRepo , 'data' ) ) . fsPath
79- const mockDvcSubRoot2 = Uri . file ( join ( mockDvcMonoRepo , '.dvc' ) ) . fsPath
82+ it ( 'should be able to focus a project if it is inside of the workspace' , async ( ) => {
83+ const { config } = await buildConfig ( )
84+ const configUpdated = getConfigUpdatedPromise ( )
8085
8186 await setConfigValue ( ConfigKey . FOCUSED_PROJECTS , mockDvcSubRoot1 )
8287 await configUpdated
8388
84- expect (
85- config . getFocusedProjects ( ) ,
86- 'should set the focused project to the root if it is inside of the workspace'
87- ) . to . deep . equal ( [ mockDvcSubRoot1 ] )
88-
89- configUpdated = getConfigUpdatedPromise ( )
90-
91- await setConfigValue ( ConfigKey . FOCUSED_PROJECTS , [ mockDvcSubRoot1 ] )
92- await configUpdated
93-
94- expect (
95- config . getFocusedProjects ( ) ,
96- 'should not call setup if the value(s) inside of the option have not changed'
97- ) . to . deep . equal ( [ mockDvcSubRoot1 ] )
89+ expect ( config . getFocusedProjects ( ) ) . to . deep . equal ( [ mockDvcSubRoot1 ] )
90+ } )
9891
99- configUpdated = getConfigUpdatedPromise ( )
92+ it ( 'should be able to focus multiple sub-projects' , async ( ) => {
93+ const { config } = await buildConfig ( )
94+ const configUpdated = getConfigUpdatedPromise ( )
10095
10196 await setConfigValue ( ConfigKey . FOCUSED_PROJECTS , [
10297 mockDvcSubRoot1 ,
10398 mockDvcSubRoot2
10499 ] )
105100 await configUpdated
106101
107- expect (
108- config . getFocusedProjects ( ) ,
109- 'should be able to focus multiple sub-projects'
110- ) . to . deep . equal ( [ mockDvcSubRoot1 , mockDvcSubRoot2 ] . sort ( ) )
102+ expect ( config . getFocusedProjects ( ) ) . to . deep . equal (
103+ [ mockDvcSubRoot1 , mockDvcSubRoot2 ] . sort ( )
104+ )
105+ } )
106+
107+ it ( 'should be able to focus multiple sub-projects along with the monorepo root' , async ( ) => {
108+ const { config } = await buildConfig ( )
109+ const configUpdated = getConfigUpdatedPromise ( )
111110
112111 await setConfigValue ( ConfigKey . FOCUSED_PROJECTS , [
113112 mockDvcSubRoot2 ,
114- mockDvcSubRoot1
113+ mockDvcSubRoot1 ,
114+ mockDvcMonoRepo
115115 ] )
116116 await configUpdated
117117
118- expect (
119- config . getFocusedProjects ( ) ,
120- 'should not call setup if the value(s) inside of the option have not changed'
121- ) . to . deep . equal ( [ mockDvcSubRoot1 , mockDvcSubRoot2 ] . sort ( ) )
118+ expect ( config . getFocusedProjects ( ) ) . to . deep . equal (
119+ [ mockDvcMonoRepo , mockDvcSubRoot1 , mockDvcSubRoot2 ] . sort ( )
120+ )
121+ } )
122+
123+ it ( 'should be able to unfocus projects' , async ( ) => {
124+ const { config } = await buildConfig ( )
125+ const configSet = getConfigUpdatedPromise ( )
122126
123127 await setConfigValue ( ConfigKey . FOCUSED_PROJECTS , [
124128 mockDvcSubRoot2 ,
125129 mockDvcSubRoot1 ,
126130 mockDvcMonoRepo
127131 ] )
128- await configUpdated
132+ await configSet
129133
130- expect (
131- config . getFocusedProjects ( ) ,
132- 'should be able to focus multiple sub-projects along with the monorepo root'
133- ) . to . deep . equal (
134+ expect ( config . getFocusedProjects ( ) ) . to . deep . equal (
134135 [ mockDvcMonoRepo , mockDvcSubRoot1 , mockDvcSubRoot2 ] . sort ( )
135136 )
136137
137- await setConfigValue ( ConfigKey . FOCUSED_PROJECTS , undefined )
138- await configUpdated
139-
140- expect (
141- config . getFocusedProjects ( ) ,
142- 'should be able to unset the option'
143- ) . to . equal ( undefined )
138+ const configUpdated = getConfigUpdatedPromise ( )
144139
145- await setConfigValue ( ConfigKey . FOCUSED_PROJECTS , null )
140+ await setConfigValue ( ConfigKey . FOCUSED_PROJECTS , undefined )
146141 await configUpdated
147142
148- expect (
149- config . getFocusedProjects ( ) ,
150- 'should be able to set the option to the default value'
151- ) . to . equal ( undefined )
143+ expect ( config . getFocusedProjects ( ) ) . to . equal ( undefined )
144+ } )
152145
146+ it ( 'should not focus projects that are outside of the workspace' , async ( ) => {
147+ const { config, mockGetWorkspaceFolders } = await buildConfig ( )
148+ const configUpdated = getConfigUpdatedPromise ( )
153149 mockGetWorkspaceFolders . restore ( )
154150
155151 await setConfigValue ( ConfigKey . FOCUSED_PROJECTS , [ 'a' , 'b' , 'c' ] )
156152 await configUpdated
157153
158- expect (
159- config . getFocusedProjects ( ) ,
160- 'should exclude projects that are outside of the workspace'
161- ) . to . equal ( undefined )
162- } ) . timeout ( 10000 )
154+ expect ( config . getFocusedProjects ( ) ) . to . equal ( undefined )
155+ } )
163156 } )
164157} )
0 commit comments