@@ -103,6 +103,27 @@ def test_files_build_development(tmp_path):
103103 assert os .path .exists (filepath ), f"File { filename } does not exist in { folder_path } !"
104104
105105
106+ def test_files_build_jupyterlab_builder (tmp_path ):
107+ extension_folder = tmp_path / "ext"
108+ extension_folder .mkdir ()
109+ helper (str (extension_folder ))
110+
111+ env = os .environ .copy ()
112+ env .update ({"YARN_ENABLE_IMMUTABLE_INSTALLS" : "false" })
113+ run (["jlpm" , "install" ], cwd = extension_folder , check = True , env = env )
114+ # Intentionally do NOT add @jupyter/builder; the template already declares
115+ # @jupyterlab/builder, so this exercises the jupyterlab/builder path.
116+ run (["jlpm" , "run" , "build:lib:prod" ], cwd = extension_folder , check = True )
117+
118+ run (["jupyter-builder" , "build" , str (extension_folder )], cwd = extension_folder , check = True )
119+
120+ folder_path = extension_folder / "myextension/labextension"
121+ expected_files = ["static/style.js" , "package.json" ]
122+ for filename in expected_files :
123+ filepath = os .path .join (folder_path , filename )
124+ assert os .path .exists (filepath ), f"File { filename } does not exist in { folder_path } !"
125+
126+
106127# --------------------------------- WATCH TESTS ---------------------------------------
107128
108129
@@ -186,6 +207,50 @@ def test_watch_functionality(tmp_path):
186207 # watch_process.wait()
187208
188209
210+ def test_watch_functionality_jupyterlab_builder (tmp_path ):
211+ extension_folder = tmp_path / "ext"
212+ extension_folder .mkdir ()
213+ helper (str (extension_folder ))
214+
215+ env = os .environ .copy ()
216+ env .update ({"YARN_ENABLE_IMMUTABLE_INSTALLS" : "false" })
217+ run (["jlpm" , "install" ], cwd = extension_folder , check = True , env = env )
218+ # Intentionally do NOT add @jupyter/builder; exercises the jupyterlab/builder path.
219+ run (["jlpm" , "run" , "build:lib:prod" ], cwd = extension_folder , check = True )
220+
221+ index_ts_path = extension_folder / "src/index.ts"
222+ static_dir = extension_folder / "myextension/labextension/static"
223+ assert index_ts_path .exists (), f"File { index_ts_path } does not exist!"
224+
225+ initial_files = list_files_in_static (static_dir )
226+
227+ is_windows = platform .system () == "Windows"
228+ kwargs = {"creationflags" : subprocess .CREATE_NEW_PROCESS_GROUP } if is_windows else {}
229+
230+ watch_process = Popen (
231+ ["jupyter-builder" , "watch" , str (extension_folder )], cwd = extension_folder , ** kwargs
232+ )
233+
234+ time .sleep (100 )
235+
236+ try :
237+ with index_ts_path .open ("a" ) as f :
238+ f .write ("// Test comment to trigger watch\n " )
239+
240+ time .sleep (100 )
241+
242+ final_files = list_files_in_static (static_dir )
243+ assert initial_files != final_files , (
244+ "No changes detected in the static directory."
245+ " Watch process may not have triggered correctly!"
246+ )
247+ finally :
248+ watch_process .terminate ()
249+ time .sleep (5 )
250+ if watch_process .poll () is None :
251+ watch_process .kill ()
252+
253+
189254def test_builder_version_mismatch (tmp_path ):
190255 extension_folder = tmp_path / "ext"
191256 extension_folder .mkdir ()
0 commit comments