Browse Source

Add test for app example

Steven Silvester 6 years ago
parent
commit
a74a80510c

+ 57 - 0
examples/app/check.py

@@ -0,0 +1,57 @@
+
+# -*- coding: utf-8 -*-
+from concurrent.futures import ThreadPoolExecutor
+import importlib.util
+from os import path as osp
+import os
+import shutil
+import sys
+import subprocess
+
+from tornado.ioloop import IOLoop
+from notebook.notebookapp import flags, aliases, NotebookApp
+from traitlets import Bool, Unicode
+from jupyterlab.labapp import get_app_dir
+
+here = osp.abspath(osp.dirname(__file__))
+
+
+# Import the base class from our sibling file
+mod_path = osp.abspath(osp.join(here, 'main.py'))
+spec = importlib.util.spec_from_file_location("example", mod_path)
+mod = importlib.util.module_from_spec(spec)
+spec.loader.exec_module(mod)
+
+
+class ExampleCheckApp(mod.ExampleApp):
+    open_browser = Bool(False)
+
+    def start(self):
+        pool = ThreadPoolExecutor()
+        future = pool.submit(run_browser, self.display_url)
+        IOLoop.current().add_future(future, self._browser_finished)
+        super().start()
+
+    def _browser_finished(self, future):
+        try:
+            sys.exit(future.result())
+        except Exception as e:
+            self.log.error(str(e))
+            sys.exit(1)
+
+
+def run_browser(url):
+    """Run the browser test and return an exit code.
+    """
+    target = osp.join(get_app_dir(), 'example_test')
+    if not osp.exists(osp.join(target, 'node_modules')):
+        os.makedirs(target)
+        subprocess.call(["jlpm"], cwd=target)
+        subprocess.call(["jlpm", "add", "puppeteer"], cwd=target)
+    src = osp.abspath(osp.join(here, '..', 'chrome-example-test.js'))
+    shutil.copy(src, osp.join(target, 'chrome-example-test.js'))
+    return subprocess.check_call(["node", "chrome-example-test.js", url], cwd=target)
+
+
+if __name__ == '__main__':
+    ExampleCheckApp.launch_instance()

+ 2 - 2
examples/app/main.py

@@ -13,13 +13,13 @@ os.environ["JUPYTER_NO_CONFIG"]="1"
 
 class ExampleApp(LabServerApp):
 
-    default_url = Unicode('/exampleapp',
+    default_url = Unicode('/example',
                           help='The default URL to redirect to from `/`')
 
     lab_config = LabConfig(
         app_name = 'JupyterLab Example App',
         app_settings_dir = os.path.join(HERE, 'build', 'application_settings'),
-        page_url = '/exampleapp',
+        page_url = '/example',
         schemas_dir = os.path.join(HERE, 'build', 'schemas'),
         settings_dir = os.path.join(HERE, 'build', 'settings'),
         static_dir = os.path.join(HERE, 'build'),

+ 0 - 4
examples/example_check.py

@@ -32,9 +32,6 @@ class ExampleCheckApp(NotebookApp):
         """initialize tornado webapp and httpserver.
         """
         super().init_webapp()
-        test_name = osp.basename(self.example_dir)
-        self.log.info('*' * 40)
-        self.log.info(f'Starting test of {test_name}')
         mod_path = osp.abspath(osp.join(self.example_dir, 'main.py'))
         spec = importlib.util.spec_from_file_location("example", mod_path)
         mod = importlib.util.module_from_spec(spec)
@@ -49,7 +46,6 @@ class ExampleCheckApp(NotebookApp):
 
     def _browser_finished(self, future):
         try:
-            self.log.info('*' * 40)
             sys.exit(future.result())
         except Exception as e:
             self.log.error(str(e))

+ 19 - 0
examples/test_examples.py

@@ -13,17 +13,36 @@ services_dir = osp.abspath(osp.join(here, '../packages/services/examples'))
 paths += [i for i in glob.glob(f'{services_dir}/*')]
 
 
+def header(path):
+    test_name = osp.basename(path)
+    print('\n')
+    print('*' * 40)
+    print(f'Starting {test_name} test')
+    print('*' * 40)
+
+
+count = 0
 for path in sorted(paths):
     if osp.basename(path) == 'node':
+        header(path)
         runner = osp.join(path, 'main.py')
         subprocess.check_call([sys.executable, runner])
+        count += 1
         continue
 
     if osp.basename(path) in ['app']:
+        header(path)
+        runner = osp.join(path, 'check.py')
+        subprocess.check_call([sys.executable, runner])
+        count += 1
         continue
 
     if not osp.exists(osp.join(path, 'main.py')):
         continue
 
+    count += 1
+    header(path)
     runner = osp.join(here, 'example_check.py')
     subprocess.check_call([sys.executable, runner, '--example-dir', path])
+
+print(f'\n\n{count} tests complete!')

+ 1 - 1
package.json

@@ -49,9 +49,9 @@
     "test": "lerna run test --scope \"@jupyterlab/test-*\" --concurrency 1 --stream",
     "test:chrome": "lerna run test:chrome --scope \"@jupyterlab/test-*\" --concurrency 1 --stream",
     "test:chrome-headless": "lerna run test:chrome-headless --scope \"@jupyterlab/test-*\" --concurrency 1 --stream",
+    "test:examples": "python examples/test_examples.py",
     "test:firefox": "lerna run test:firefox --scope \"@jupyterlab/test-*\" --concurrency 1 --stream",
     "test:ie": "lerna run test:ie --scope \"@jupyterlab/test-*\" --concurrency 1 --stream",
-    "test:examples": "python examples/test_examples.py",
     "tslint": "tslint --fix -c tslint.json --project tsconfigbase.json '**/*{.ts,.tsx}'",
     "tslint:check": "tslint -c tslint.json --project tsconfigbase.json '**/*{.ts,.tsx}'",
     "prettier": "prettier --write '**/*{.ts,.tsx,.js,.jsx,.css,.json,.md}'",

+ 1 - 1
packages/services/examples/browser/package.json

@@ -10,7 +10,7 @@
   "dependencies": {
     "@jupyterlab/services": "^4.0.0-alpha.6",
     "es6-promise": "~4.1.1",
-    "typescript": "^3.4.5"
+    "typescript": "~3.4.3"
   },
   "devDependencies": {
     "rimraf": "~2.6.2",

+ 5 - 10
yarn.lock

@@ -4829,8 +4829,8 @@ file-type@^10.10.0:
 file-uri-to-path@1:
   version "1.0.0"
   resolved "https://registry.yarnpkg.com/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz#553a7b8446ff6f684359c445f1e37a05dacc33dd"
-fileset@^2.0.2, fileset@^2.0.3:
 
+fileset@^2.0.2, fileset@^2.0.3:
   version "2.0.3"
   resolved "https://registry.yarnpkg.com/fileset/-/fileset-2.0.3.tgz#8e7548a96d3cc2327ee5e674168723a333bba2a0"
   dependencies:
@@ -6530,8 +6530,8 @@ jest-jasmine2@^24.7.1:
     jest-util "^24.7.1"
     pretty-format "^24.7.0"
     throat "^4.0.0"
-jest-junit@^6.3.0:
 
+jest-junit@^6.3.0:
   version "6.3.0"
   resolved "https://registry.yarnpkg.com/jest-junit/-/jest-junit-6.3.0.tgz#99e64ebc54eddcb21238f0cc49f5820c89a8c785"
   integrity sha512-3PH9UkpaomX6CUzqjlnk0m4yBCW/eroxV6v61OM6LkCQFO848P3YUhfIzu8ypZSBKB3vvCbB4WaLTKT0BrIf8A==
@@ -8833,8 +8833,8 @@ popper.js@^1.14.1:
 posix-character-classes@^0.1.0:
   version "0.1.1"
   resolved "https://registry.yarnpkg.com/posix-character-classes/-/posix-character-classes-0.1.1.tgz#01eac0fe3b5af71a2a6c02feabb8c1fef7e00eab"
-postcss-modules-extract-imports@^2.0.0:
 
+postcss-modules-extract-imports@^2.0.0:
   version "2.0.0"
   resolved "https://registry.yarnpkg.com/postcss-modules-extract-imports/-/postcss-modules-extract-imports-2.0.0.tgz#818719a1ae1da325f9832446b01136eeb493cd7e"
   integrity sha512-LaYLDNS4SG8Q5WAWqIJgdHPJrDDr/Lv775rMBFUbgjTz6j34lUznACHcdRWroPvXANP2Vj7yNK57vp9eFqzLWQ==
@@ -10712,8 +10712,8 @@ to-arraybuffer@^1.0.0:
 to-fast-properties@^1.0.3:
   version "1.0.3"
   resolved "https://registry.yarnpkg.com/to-fast-properties/-/to-fast-properties-1.0.3.tgz#b83571fa4d8c25b82e231b06e3a3055de4ca1a47"
-to-fast-properties@^2.0.0:
 
+to-fast-properties@^2.0.0:
   version "2.0.0"
   resolved "https://registry.yarnpkg.com/to-fast-properties/-/to-fast-properties-2.0.0.tgz#dc5e698cbd079265bc73e0377681a4e4e83f616e"
   integrity sha1-3F5pjL0HkmW8c+A3doGk5Og/YW4=
@@ -10951,11 +10951,6 @@ typescript@3.2.x:
   version "3.2.4"
   resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.2.4.tgz#c585cb952912263d915b462726ce244ba510ef3d"
 
-typescript@^3.4.5:
-  version "3.4.5"
-  resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.4.5.tgz#2d2618d10bb566572b8d7aad5180d84257d70a99"
-  integrity sha512-YycBxUb49UUhdNMU5aJ7z5Ej2XGmaIBL0x34vZ82fn3hGvD+bgrMrVDpatgz2f7YxUMJxMkbWxJZeAvDxVe7Vw==
-
 typescript@~3.4.3:
   version "3.4.3"
   resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.4.3.tgz#0eb320e4ace9b10eadf5bc6103286b0f8b7c224f"
@@ -10967,8 +10962,8 @@ typestyle@^2.0.1:
   dependencies:
     csstype "^2.4.0"
     free-style "2.5.1"
-ua-parser-js@^0.7.18, ua-parser-js@^0.7.9:
 
+ua-parser-js@^0.7.18, ua-parser-js@^0.7.9:
   version "0.7.19"
   resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.19.tgz#94151be4c0a7fb1d001af7022fdaca4642659e4b"