Selaa lähdekoodia

modernize inspector tests

Steven Silvester 5 vuotta sitten
vanhempi
commit
d8edf7d701

+ 0 - 1
dev_mode/package.json

@@ -374,7 +374,6 @@
       "@jupyterlab/test-docregistry": "../tests/test-docregistry",
       "@jupyterlab/test-fileeditor": "../tests/test-fileeditor",
       "@jupyterlab/test-imageviewer": "../tests/test-imageviewer",
-      "@jupyterlab/test-inspector": "../tests/test-inspector",
       "@jupyterlab/test-logconsole": "../tests/test-logconsole",
       "@jupyterlab/test-mainmenu": "../tests/test-mainmenu",
       "@jupyterlab/test-nbformat": "../tests/test-nbformat",

+ 11 - 0
packages/inspector/.vscode/launch.json

@@ -0,0 +1,11 @@
+{
+    "version": "0.2.0",
+    "configurations": [
+        {
+            "type": "node",
+            "request": "attach",
+            "name": "Attach",
+            "port": 9229
+        }
+    ]
+}

+ 0 - 0
tests/test-inspector/babel.config.js → packages/inspector/babel.config.js


+ 2 - 0
packages/inspector/jest.config.js

@@ -0,0 +1,2 @@
+const func = require('@jupyterlab/testutils/lib/jest-config-new');
+module.exports = func(__dirname);

+ 9 - 0
packages/inspector/package.json

@@ -29,9 +29,14 @@
   },
   "scripts": {
     "build": "tsc -b",
+    "build:test": "tsc --build tsconfig.test.json",
     "clean": "rimraf lib",
     "docs": "typedoc src",
     "prepublishOnly": "npm run build",
+    "test": "jest",
+    "test:cov": "jest --collect-coverage",
+    "test:debug": "node --inspect-brk node_modules/.bin/jest --runInBand",
+    "test:debug:watch": "node --inspect-brk node_modules/.bin/jest --runInBand --watch",
     "watch": "tsc -b --watch"
   },
   "dependencies": {
@@ -48,7 +53,11 @@
     "@lumino/widgets": "^1.11.1"
   },
   "devDependencies": {
+    "@jupyterlab/testutils": "^2.1.0",
+    "@types/jest": "^24.0.23",
+    "jest": "^25.2.3",
     "rimraf": "~3.0.0",
+    "ts-jest": "^25.2.1",
     "typedoc": "^0.15.4",
     "typescript": "~3.7.3"
   },

+ 18 - 15
tests/test-inspector/src/inspector.spec.ts → packages/inspector/test/inspector.spec.ts

@@ -1,7 +1,6 @@
 // Copyright (c) Jupyter Development Team.
-// Distributed under the terms of the Modified BSD License.
 
-import { expect } from 'chai';
+import 'jest';
 
 import { Signal } from '@lumino/signaling';
 
@@ -38,48 +37,48 @@ describe('inspector/index', () => {
     describe('#constructor()', () => {
       it('should construct a new inspector widget', () => {
         const widget = new InspectorPanel();
-        expect(widget).to.be.an.instanceof(InspectorPanel);
+        expect(widget).toBeInstanceOf(InspectorPanel);
       });
 
       it('should add the `jp-Inspector` class', () => {
         const widget = new InspectorPanel();
-        expect(widget.hasClass('jp-Inspector')).to.equal(true);
+        expect(widget.hasClass('jp-Inspector')).toBe(true);
       });
     });
 
     describe('#source', () => {
       it('should default to `null`', () => {
         const widget = new InspectorPanel();
-        expect(widget.source).to.be.null;
+        expect(widget.source).toBeNull();
       });
 
       it('should be settable multiple times', () => {
         const widget = new InspectorPanel();
         const source = new TestInspectable();
-        expect(widget.source).to.be.null;
+        expect(widget.source).toBeNull();
         widget.source = source;
-        expect(widget.source).to.equal(source);
+        expect(widget.source).toBe(source);
         widget.source = null;
-        expect(widget.source).to.be.null;
+        expect(widget.source).toBeNull();
         widget.source = new TestInspectable();
-        expect(widget.source).to.be.an.instanceof(TestInspectable);
+        expect(widget.source).toBeInstanceOf(TestInspectable);
       });
     });
 
     describe('#dispose()', () => {
       it('should dispose of the resources used by the inspector', () => {
         const widget = new InspectorPanel();
-        expect(widget.isDisposed).to.equal(false);
+        expect(widget.isDisposed).toBe(false);
         widget.dispose();
-        expect(widget.isDisposed).to.equal(true);
+        expect(widget.isDisposed).toBe(true);
       });
 
       it('should be a no-op if called more than once', () => {
         const widget = new InspectorPanel();
-        expect(widget.isDisposed).to.equal(false);
+        expect(widget.isDisposed).toBe(false);
         widget.dispose();
         widget.dispose();
-        expect(widget.isDisposed).to.equal(true);
+        expect(widget.isDisposed).toBe(true);
       });
     });
 
@@ -87,9 +86,13 @@ describe('inspector/index', () => {
       it('should fire when a source updates', () => {
         const widget = new TestInspectorPanel();
         widget.source = new TestInspectable();
-        expect(widget.methods).to.not.contain('onInspectorUpdate');
+        expect(widget.methods).toEqual(
+          expect.not.arrayContaining(['onInspectorUpdate'])
+        );
         (widget.source.inspected as any).emit({ content: new Widget() });
-        expect(widget.methods).to.contain('onInspectorUpdate');
+        expect(widget.methods).toEqual(
+          expect.arrayContaining(['onInspectorUpdate'])
+        );
       });
     });
   });

+ 45 - 0
packages/inspector/tsconfig.test.json

@@ -0,0 +1,45 @@
+{
+  "extends": "../../tsconfigbase.test",
+  "include": ["src/*", "test/*"],
+  "references": [
+    {
+      "path": "../apputils"
+    },
+    {
+      "path": "../codeeditor"
+    },
+    {
+      "path": "../coreutils"
+    },
+    {
+      "path": "../rendermime"
+    },
+    {
+      "path": "../services"
+    },
+    {
+      "path": "../statedb"
+    },
+    {
+      "path": "../../testutils"
+    },
+    {
+      "path": "../apputils"
+    },
+    {
+      "path": "../codeeditor"
+    },
+    {
+      "path": "../coreutils"
+    },
+    {
+      "path": "../rendermime"
+    },
+    {
+      "path": "../services"
+    },
+    {
+      "path": "../statedb"
+    }
+  ]
+}

+ 0 - 2
tests/test-inspector/jest.config.js

@@ -1,2 +0,0 @@
-const func = require('@jupyterlab/testutils/lib/jest-config');
-module.exports = func('inspector', __dirname);

+ 0 - 30
tests/test-inspector/package.json

@@ -1,30 +0,0 @@
-{
-  "name": "@jupyterlab/test-inspector",
-  "version": "2.1.0",
-  "private": true,
-  "scripts": {
-    "build": "tsc -b",
-    "clean": "rimraf build && rimraf coverage",
-    "coverage": "python run.py --coverage",
-    "test": "python run.py",
-    "watch": "python run.py --debug",
-    "watch:all": "python run.py --debug --watchAll",
-    "watch:src": "tsc -b --watch"
-  },
-  "dependencies": {
-    "@jupyterlab/inspector": "^2.1.0",
-    "@jupyterlab/testutils": "^2.1.0",
-    "@lumino/signaling": "^1.3.5",
-    "@lumino/widgets": "^1.11.1",
-    "chai": "^4.2.0",
-    "jest": "^25.2.3",
-    "jest-junit": "^10.0.0",
-    "ts-jest": "^25.2.1"
-  },
-  "devDependencies": {
-    "@types/chai": "^4.2.7",
-    "@types/jest": "^24.0.23",
-    "rimraf": "~3.0.0",
-    "typescript": "~3.7.3"
-  }
-}

+ 0 - 8
tests/test-inspector/run.py

@@ -1,8 +0,0 @@
-# Copyright (c) Jupyter Development Team.
-# Distributed under the terms of the Modified BSD License.
-
-import os.path as osp
-from jupyterlab.tests.test_app import run_jest
-
-if __name__ == '__main__':
-    run_jest(osp.dirname(osp.realpath(__file__)))

+ 0 - 18
tests/test-inspector/tsconfig.json

@@ -1,18 +0,0 @@
-{
-  "extends": "../../tsconfigbase",
-  "compilerOptions": {
-    "outDir": "build",
-    "types": ["jest"],
-    "composite": false,
-    "rootDir": "src"
-  },
-  "include": ["src/*"],
-  "references": [
-    {
-      "path": "../../packages/inspector"
-    },
-    {
-      "path": "../../testutils"
-    }
-  ]
-}