Browse Source

convert completer

Steven Silvester 6 years ago
parent
commit
45d910f3a6

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

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

+ 0 - 1
tests/test-completer/karma-cov.conf.js

@@ -1 +0,0 @@
-module.exports = require('../karma-cov.conf');

+ 0 - 1
tests/test-completer/karma.conf.js

@@ -1 +0,0 @@
-module.exports = require('../karma.conf');

+ 9 - 13
tests/test-completer/package.json

@@ -5,15 +5,11 @@
   "scripts": {
     "build": "tsc -b",
     "clean": "rimraf build && rimraf coverage",
-    "coverage": "python run-test.py --browsers=ChromeHeadless karma-cov.conf.js",
-    "test": "jlpm run test:firefox",
-    "test:chrome": "python run-test.py --browsers=Chrome karma.conf.js",
-    "test:chrome-headless": "python run-test.py --browsers=ChromeHeadless karma.conf.js",
-    "test:debug": "python run-test.py  --browsers=Chrome --singleRun=false --debug=true --browserNoActivityTimeout=10000000 karma.conf.js",
-    "test:firefox": "python run-test.py --browsers=Firefox karma.conf.js",
-    "test:ie": "python run-test.py  --browsers=IE karma.conf.js",
-    "watch": "tsc -b --watch",
-    "watch:src": "tsp -p src --watch"
+    "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/apputils": "^0.19.1-alpha.0",
@@ -26,13 +22,13 @@
     "@phosphor/messaging": "^1.2.2",
     "@phosphor/widgets": "^1.6.0",
     "chai": "~4.1.2",
-    "simulate-event": "~1.4.0"
+    "simulate-event": "~1.4.0",
+    "jest": "^23.5.0",
+    "ts-jest": "^23.1.4"
   },
   "devDependencies": {
     "@types/chai": "~4.0.10",
-    "karma": "~2.0.4",
-    "karma-chrome-launcher": "~2.2.0",
-    "puppeteer": "^1.5.0",
+    "@types/jest": "^23.3.1",
     "rimraf": "~2.6.2",
     "typescript": "~3.1.1"
   }

+ 3 - 5
tests/test-completer/run-test.py → tests/test-completer/run.py

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

+ 3 - 3
tests/test-completer/src/handler.spec.ts

@@ -14,7 +14,7 @@ import {
   CompletionHandler,
   CompleterModel,
   KernelConnector
-} from '@jupyterlab/completer';
+} from '@jupyterlab/completer/src';
 
 import { createClientSession } from '@jupyterlab/testutils';
 
@@ -58,13 +58,13 @@ describe('@jupyterlab/completer', () => {
   let connector: KernelConnector;
   let session: IClientSession;
 
-  before(async () => {
+  beforeAll(async () => {
     session = await createClientSession();
     await (session as ClientSession).initialize();
     connector = new KernelConnector({ session });
   });
 
-  after(() => session.shutdown());
+  afterAll(() => session.shutdown());
 
   describe('CompletionHandler', () => {
     describe('#constructor()', () => {

+ 1 - 1
tests/test-completer/src/model.spec.ts

@@ -9,7 +9,7 @@ import { JSONExt } from '@phosphor/coreutils';
 
 import { CodeEditor } from '@jupyterlab/codeeditor';
 
-import { CompleterModel, Completer } from '@jupyterlab/completer';
+import { CompleterModel, Completer } from '@jupyterlab/completer/src';
 
 function makeState(text: string): Completer.ITextState {
   return {

+ 5 - 4
tests/test-completer/src/widget.spec.ts

@@ -15,7 +15,7 @@ import { CodeEditor, CodeEditorWrapper } from '@jupyterlab/codeeditor';
 
 import { CodeMirrorEditor } from '@jupyterlab/codemirror';
 
-import { Completer, CompleterModel } from '@jupyterlab/completer';
+import { Completer, CompleterModel } from '@jupyterlab/completer/src';
 
 import { framePromise, sleep } from '@jupyterlab/testutils';
 const TEST_ITEM_CLASS = 'jp-TestItem';
@@ -284,7 +284,7 @@ describe('completer/widget', () => {
         anchor.dispose();
       });
 
-      context('keydown', () => {
+      describe('keydown', () => {
         it('should reset if keydown is outside anchor', () => {
           let model = new CompleterModel();
           let anchor = createEditorWidget();
@@ -438,7 +438,7 @@ describe('completer/widget', () => {
         });
       });
 
-      context('mousedown', () => {
+      describe('mousedown', () => {
         it('should trigger a selected signal on mouse down', () => {
           let anchor = createEditorWidget();
           let model = new CompleterModel();
@@ -551,7 +551,7 @@ describe('completer/widget', () => {
         });
       });
 
-      context('scroll', () => {
+      describe('scroll', () => {
         it('should position itself according to the anchor', async () => {
           let panel = new Panel();
           let code = createEditorWidget();
@@ -605,6 +605,7 @@ describe('completer/widget', () => {
           await sleep(500);
           let top = parseInt(window.getComputedStyle(widget.node).top, 10);
           let bottom = Math.floor(coords.bottom);
+          debugger;
           expect(top + panel.node.scrollTop).to.equal(bottom);
           widget.dispose();
           code.dispose();

+ 1 - 1
tests/test-completer/tsconfig.json

@@ -2,7 +2,7 @@
   "extends": "../../tsconfigbase",
   "compilerOptions": {
     "outDir": "build",
-    "types": ["mocha"],
+    "types": ["jest"],
     "composite": false,
     "rootDir": "src"
   },

+ 3 - 0
testutils/src/jest-shim.ts

@@ -29,6 +29,9 @@ window.focus = () => {};
   };
 };
 
+(window as any).document.elementFromPoint = (left: number, top: number) =>
+  document.body;
+
 process.on('unhandledRejection', (error, promise) => {
   console.error('Unhandled promise rejection somewhere in tests');
   console.error(error);