diff --git a/nbgrader/tests/ui-tests/utils/run_jupyter_notebook.py b/nbgrader/tests/ui-tests/utils/run_jupyter_app.py similarity index 65% rename from nbgrader/tests/ui-tests/utils/run_jupyter_notebook.py rename to nbgrader/tests/ui-tests/utils/run_jupyter_app.py index 550d2d1c7..71629f5ef 100644 --- a/nbgrader/tests/ui-tests/utils/run_jupyter_notebook.py +++ b/nbgrader/tests/ui-tests/utils/run_jupyter_app.py @@ -12,16 +12,21 @@ if not os.path.isdir(env["NBGRADER_TEST_DIR"]): raise Exception(f"Test directory {env['NBGRADER_TEST_DIR']} doesn't exists") -shutil.copyfile("./nbgrader/tests/ui-tests/utils/jupyter_server_config_notebook.py", - join(root_dir, "jupyter_server_config_notebook.py")) +subprocess.check_call([sys.executable, "-m", "jupyter", "server", "extension", "enable", "--user", "--py", "nbgrader"], env=env) +subprocess.check_call([sys.executable, "-m", "jupyter", "labextension", "develop", "--overwrite", "."]) shutil.copyfile("./nbgrader/tests/ui-tests/files/nbgrader_config.py", join(root_dir, "nbgrader_config.py")) -subprocess.check_call([sys.executable, "-m", "jupyter", "server", "extension", "enable", "--user", "--py", "nbgrader"], env=env) -subprocess.check_call([sys.executable, "-m", "jupyter", "labextension", "develop", "--overwrite", "."]) +if "NBGRADER_TEST_IS_NOTEBOOK" in env.keys(): + shutil.copyfile("./nbgrader/tests/ui-tests/utils/jupyter_server_config_notebook.py", + join(root_dir, "jupyter_server_config_notebook.py")) + command = ["jupyter", "notebook", "--config", "./jupyter_server_config_notebook.py"] +else: + shutil.copyfile("./nbgrader/tests/ui-tests/utils/jupyter_server_config.py", + join(root_dir, "jupyter_server_config.py")) + command = ["jupyter", "lab", "--config", "./jupyter_server_config.py"] os.chdir(root_dir) -command = ["jupyter", "notebook", "--config", "./jupyter_server_config_notebook.py"] subprocess.run(command) diff --git a/nbgrader/tests/ui-tests/utils/run_jupyter_lab.py b/nbgrader/tests/ui-tests/utils/run_jupyter_lab.py deleted file mode 100644 index dc86b44df..000000000 --- a/nbgrader/tests/ui-tests/utils/run_jupyter_lab.py +++ /dev/null @@ -1,27 +0,0 @@ -import sys -import os -from os.path import join -import shutil -import subprocess - -env = os.environ.copy() -root_dir = env.get("NBGRADER_TEST_DIR", '') - -if not env["NBGRADER_TEST_DIR"]: - raise Exception("Test directory not provided") -if not os.path.isdir(env["NBGRADER_TEST_DIR"]): - raise Exception(f"Test directory {env['NBGRADER_TEST_DIR']} doesn't exists") - -shutil.copyfile("./nbgrader/tests/ui-tests/utils/jupyter_server_config.py", - join(root_dir, "jupyter_server_config.py")) - -shutil.copyfile("./nbgrader/tests/ui-tests/files/nbgrader_config.py", - join(root_dir, "nbgrader_config.py")) - -subprocess.check_call([sys.executable, "-m", "jupyter", "server", "extension", "enable", "--user", "--py", "nbgrader"], env=env) -subprocess.check_call([sys.executable, "-m", "jupyter", "labextension", "develop", "--overwrite", "."]) - -os.chdir(root_dir) - -command = ["jupyter", "lab", "--config", "./jupyter_server_config.py"] -subprocess.run(command) diff --git a/package.json b/package.json index 8a4aac57c..31f45217c 100644 --- a/package.json +++ b/package.json @@ -35,10 +35,9 @@ "clean:labextension": "rimraf nbgrader/labextension", "clean:all": "jlpm clean:lib && jlpm clean:labextension", "install:labextension": "jlpm build", - "start:test": "python ./nbgrader/tests/ui-tests/utils/run_jupyter_lab.py", - "start:test:notebook": "python ./nbgrader/tests/ui-tests/utils/run_jupyter_notebook.py", + "start:test": "python ./nbgrader/tests/ui-tests/utils/run_jupyter_app.py", "test": "jlpm playwright test", - "test:notebook": "jlpm playwright test --config=playwright.notebook.config.ts", + "test:notebook": "NBGRADER_TEST_IS_NOTEBOOK=1 jlpm playwright test --config=playwright.notebook.config.ts", "watch": "run-p watch:src watch:labextension", "watch:src": "tsc -w", "watch:labextension": "jupyter labextension watch ." diff --git a/playwright.notebook.config.ts b/playwright.notebook.config.ts index 15e8d8a85..ba9e2d57f 100644 --- a/playwright.notebook.config.ts +++ b/playwright.notebook.config.ts @@ -13,10 +13,9 @@ module.exports = { appPath: '', }, webServer: { - command: 'jlpm start:test:notebook', + command: 'jlpm start:test', url: 'http://localhost:8888/tree', timeout: 120 * 1000, reuseExistingServer: !process.env.CI, - }, - + } }; diff --git a/tasks.py b/tasks.py index b617b29a2..46906a5d8 100755 --- a/tasks.py +++ b/tasks.py @@ -82,9 +82,6 @@ def _run_ts_test(args, notebook=False): root_dir = mkdtemp(prefix="nbgrader-galata-") os.environ["NBGRADER_TEST_DIR"] = root_dir - if notebook: - os.environ["NBGRADER_TEST_IS_NOTEBOOK"] = "1" - cmd = ['jlpm', f'test{":notebook" if notebook else ""}', '--retries=2'] + args run(" ".join(cmd))