Explorar el Código

modernize mainmenu tests

Steven Silvester hace 4 años
padre
commit
b8edd2afc7

+ 0 - 1
dev_mode/package.json

@@ -372,7 +372,6 @@
       "@jupyterlab/test-fileeditor": "../tests/test-fileeditor",
       "@jupyterlab/test-imageviewer": "../tests/test-imageviewer",
       "@jupyterlab/test-logconsole": "../tests/test-logconsole",
-      "@jupyterlab/test-mainmenu": "../tests/test-mainmenu",
       "@jupyterlab/test-notebook": "../tests/test-notebook",
       "@jupyterlab/test-outputarea": "../tests/test-outputarea",
       "@jupyterlab/test-settingregistry": "../tests/test-settingregistry",

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

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

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


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

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

+ 9 - 0
packages/mainmenu/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": {
@@ -45,7 +50,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"
   },

+ 7 - 8
tests/test-mainmenu/src/edit.spec.ts → packages/mainmenu/test/edit.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 { CommandRegistry } from '@lumino/commands';
 
@@ -43,8 +42,8 @@ describe('@jupyterlab/mainmenu', () => {
 
     describe('#constructor()', () => {
       it('should construct a new edit menu', () => {
-        expect(menu).to.be.an.instanceof(EditMenu);
-        expect(menu.menu.title.label).to.equal('Edit');
+        expect(menu).toBeInstanceOf(EditMenu);
+        expect(menu.menu.title.label).toBe('Edit');
       });
     });
 
@@ -63,9 +62,9 @@ describe('@jupyterlab/mainmenu', () => {
         };
         menu.undoers.add(undoer);
         void delegateExecute(wodget, menu.undoers, 'undo');
-        expect(wodget.state).to.equal('undo');
+        expect(wodget.state).toBe('undo');
         void delegateExecute(wodget, menu.undoers, 'redo');
-        expect(wodget.state).to.equal('redo');
+        expect(wodget.state).toBe('redo');
       });
     });
 
@@ -85,9 +84,9 @@ describe('@jupyterlab/mainmenu', () => {
         };
         menu.clearers.add(clearer);
         void delegateExecute(wodget, menu.clearers, 'clearCurrent');
-        expect(wodget.state).to.equal('clearCurrent');
+        expect(wodget.state).toBe('clearCurrent');
         void delegateExecute(wodget, menu.clearers, 'clearAll');
-        expect(wodget.state).to.equal('clearAll');
+        expect(wodget.state).toBe('clearAll');
       });
     });
   });

+ 6 - 7
tests/test-mainmenu/src/file.spec.ts → packages/mainmenu/test/file.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 { CommandRegistry } from '@lumino/commands';
 
@@ -43,14 +42,14 @@ describe('@jupyterlab/mainmenu', () => {
 
     describe('#constructor()', () => {
       it('should construct a new file menu', () => {
-        expect(menu).to.be.an.instanceof(FileMenu);
-        expect(menu.menu.title.label).to.equal('File');
+        expect(menu).toBeInstanceOf(FileMenu);
+        expect(menu.menu.title.label).toBe('File');
       });
     });
 
     describe('#newMenu', () => {
       it('should be a submenu for `New...` commands', () => {
-        expect(menu.newMenu.menu.title.label).to.equal('New');
+        expect(menu.newMenu.menu.title.label).toBe('New');
       });
     });
 
@@ -67,7 +66,7 @@ describe('@jupyterlab/mainmenu', () => {
         };
         menu.closeAndCleaners.add(cleaner);
         void delegateExecute(wodget, menu.closeAndCleaners, 'closeAndCleanup');
-        expect(wodget.state).to.equal('clean');
+        expect(wodget.state).toBe('clean');
       });
     });
 
@@ -83,7 +82,7 @@ describe('@jupyterlab/mainmenu', () => {
         };
         menu.consoleCreators.add(creator);
         void delegateExecute(wodget, menu.consoleCreators, 'createConsole');
-        expect(wodget.state).to.equal('create');
+        expect(wodget.state).toBe('create');
       });
     });
   });

+ 3 - 4
tests/test-mainmenu/src/help.spec.ts → packages/mainmenu/test/help.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 { CommandRegistry } from '@lumino/commands';
 
@@ -26,8 +25,8 @@ describe('@jupyterlab/mainmenu', () => {
 
     describe('#constructor()', () => {
       it('should construct a new help menu', () => {
-        expect(menu).to.be.an.instanceof(HelpMenu);
-        expect(menu.menu.title.label).to.equal('Help');
+        expect(menu).toBeInstanceOf(HelpMenu);
+        expect(menu.menu.title.label).toBe('Help');
       });
     });
   });

+ 8 - 9
tests/test-mainmenu/src/kernel.spec.ts → packages/mainmenu/test/kernel.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 { CommandRegistry } from '@lumino/commands';
 
@@ -43,8 +42,8 @@ describe('@jupyterlab/mainmenu', () => {
 
     describe('#constructor()', () => {
       it('should construct a new kernel menu', () => {
-        expect(menu).to.be.an.instanceof(KernelMenu);
-        expect(menu.menu.title.label).to.equal('Kernel');
+        expect(menu).toBeInstanceOf(KernelMenu);
+        expect(menu.menu.title.label).toBe('Kernel');
       });
     });
 
@@ -76,15 +75,15 @@ describe('@jupyterlab/mainmenu', () => {
         };
         menu.kernelUsers.add(user);
         void delegateExecute(wodget, menu.kernelUsers, 'interruptKernel');
-        expect(wodget.state).to.equal('interrupt');
+        expect(wodget.state).toBe('interrupt');
         void delegateExecute(wodget, menu.kernelUsers, 'restartKernel');
-        expect(wodget.state).to.equal('restart');
+        expect(wodget.state).toBe('restart');
         void delegateExecute(wodget, menu.kernelUsers, 'restartKernelAndClear');
-        expect(wodget.state).to.equal('restartAndClear');
+        expect(wodget.state).toBe('restartAndClear');
         void delegateExecute(wodget, menu.kernelUsers, 'changeKernel');
-        expect(wodget.state).to.equal('change');
+        expect(wodget.state).toBe('change');
         void delegateExecute(wodget, menu.kernelUsers, 'shutdownKernel');
-        expect(wodget.state).to.equal('shutdown');
+        expect(wodget.state).toBe('shutdown');
       });
     });
   });

+ 14 - 15
tests/test-mainmenu/src/labmenu.spec.ts → packages/mainmenu/test/labmenu.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 { ArrayExt } from '@lumino/algorithm';
 
@@ -44,7 +43,7 @@ describe('@jupyterlab/mainmenu', () => {
 
     describe('#constructor()', () => {
       it('should construct a new main menu', () => {
-        expect(menu).to.be.an.instanceof(JupyterLabMenu);
+        expect(menu).toBeInstanceOf(JupyterLabMenu);
       });
 
       it('should accept useSeparators as an option', () => {
@@ -53,8 +52,8 @@ describe('@jupyterlab/mainmenu', () => {
         menu1.addGroup([{ command: 'run1' }, { command: 'run2' }]);
         menu2.addGroup([{ command: 'run1' }, { command: 'run2' }]);
 
-        expect(menu1.menu.items.length).to.equal(2);
-        expect(menu2.menu.items.length).to.equal(4);
+        expect(menu1.menu.items.length).toBe(2);
+        expect(menu2.menu.items.length).toBe(4);
       });
     });
 
@@ -71,9 +70,9 @@ describe('@jupyterlab/mainmenu', () => {
           m => m.command === 'run2'
         );
 
-        expect(idx1 === -1).to.equal(false);
-        expect(idx2 === -1).to.equal(false);
-        expect(idx1 > idx2).to.equal(false);
+        expect(idx1 === -1).toBe(false);
+        expect(idx2 === -1).toBe(false);
+        expect(idx1 > idx2).toBe(false);
       });
 
       it('should take a rank as an option', () => {
@@ -96,9 +95,9 @@ describe('@jupyterlab/mainmenu', () => {
           menu.menu.items,
           m => m.command === 'run4'
         );
-        expect(idx3 < idx4).to.equal(true);
-        expect(idx4 < idx1).to.equal(true);
-        expect(idx1 < idx2).to.equal(true);
+        expect(idx3 < idx4).toBe(true);
+        expect(idx4 < idx1).toBe(true);
+        expect(idx1 < idx2).toBe(true);
       });
 
       it('should return a disposable that can be used to remove the group', () => {
@@ -125,10 +124,10 @@ describe('@jupyterlab/mainmenu', () => {
           m => m.command === 'run4'
         );
 
-        expect(idx1).to.equal(-1);
-        expect(idx2).to.equal(-1);
-        expect(idx3 === -1).to.equal(false);
-        expect(idx4 === -1).to.equal(false);
+        expect(idx1).toBe(-1);
+        expect(idx2).toBe(-1);
+        expect(idx3 === -1).toBe(false);
+        expect(idx4 === -1).toBe(false);
       });
     });
   });

+ 21 - 24
tests/test-mainmenu/src/mainmenu.spec.ts → packages/mainmenu/test/mainmenu.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 { find, ArrayExt } from '@lumino/algorithm';
 
@@ -41,7 +40,7 @@ describe('@jupyterlab/mainmenu', () => {
     describe('#constructor()', () => {
       it('should construct a new main menu', () => {
         const menu = new MainMenu(new CommandRegistry());
-        expect(menu).to.be.an.instanceof(MainMenu);
+        expect(menu).toBeInstanceOf(MainMenu);
       });
     });
 
@@ -49,9 +48,7 @@ describe('@jupyterlab/mainmenu', () => {
       it('should add a new menu', () => {
         const menu = new Menu({ commands });
         mainMenu.addMenu(menu);
-        expect(find(mainMenu.menus, m => menu === m) !== undefined).to.equal(
-          true
-        );
+        expect(find(mainMenu.menus, m => menu === m) !== undefined).toBe(true);
       });
 
       it('should take a rank as an option', () => {
@@ -59,104 +56,104 @@ describe('@jupyterlab/mainmenu', () => {
         const menu2 = new Menu({ commands });
         mainMenu.addMenu(menu1, { rank: 300 });
         mainMenu.addMenu(menu2, { rank: 200 });
-        expect(ArrayExt.firstIndexOf(mainMenu.menus, menu1)).to.equal(6);
-        expect(ArrayExt.firstIndexOf(mainMenu.menus, menu2)).to.equal(5);
+        expect(ArrayExt.firstIndexOf(mainMenu.menus, menu1)).toBe(6);
+        expect(ArrayExt.firstIndexOf(mainMenu.menus, menu2)).toBe(5);
       });
     });
 
     describe('#fileMenu', () => {
       it('should be a FileMenu', () => {
-        expect(mainMenu.fileMenu).to.be.an.instanceof(FileMenu);
+        expect(mainMenu.fileMenu).toBeInstanceOf(FileMenu);
       });
 
       it('should be the first menu', () => {
         expect(
           ArrayExt.firstIndexOf(mainMenu.menus, mainMenu.fileMenu.menu)
-        ).to.equal(0);
+        ).toBe(0);
       });
     });
 
     describe('#editMenu', () => {
       it('should be a EditMenu', () => {
-        expect(mainMenu.editMenu).to.be.an.instanceof(EditMenu);
+        expect(mainMenu.editMenu).toBeInstanceOf(EditMenu);
       });
 
       it('should be the second menu', () => {
         expect(
           ArrayExt.firstIndexOf(mainMenu.menus, mainMenu.editMenu.menu)
-        ).to.equal(1);
+        ).toBe(1);
       });
     });
 
     describe('#viewMenu', () => {
       it('should be a ViewMenu', () => {
-        expect(mainMenu.viewMenu).to.be.an.instanceof(ViewMenu);
+        expect(mainMenu.viewMenu).toBeInstanceOf(ViewMenu);
       });
 
       it('should be the third menu', () => {
         expect(
           ArrayExt.firstIndexOf(mainMenu.menus, mainMenu.viewMenu.menu)
-        ).to.equal(2);
+        ).toBe(2);
       });
     });
 
     describe('#runMenu', () => {
       it('should be a RunMenu', () => {
-        expect(mainMenu.runMenu).to.be.an.instanceof(RunMenu);
+        expect(mainMenu.runMenu).toBeInstanceOf(RunMenu);
       });
 
       it('should be the fourth menu', () => {
         expect(
           ArrayExt.firstIndexOf(mainMenu.menus, mainMenu.runMenu.menu)
-        ).to.equal(3);
+        ).toBe(3);
       });
     });
 
     describe('#kernelMenu', () => {
       it('should be a KernelMenu', () => {
-        expect(mainMenu.kernelMenu).to.be.an.instanceof(KernelMenu);
+        expect(mainMenu.kernelMenu).toBeInstanceOf(KernelMenu);
       });
 
       it('should be the fifth menu', () => {
         expect(
           ArrayExt.firstIndexOf(mainMenu.menus, mainMenu.kernelMenu.menu)
-        ).to.equal(4);
+        ).toBe(4);
       });
     });
 
     describe('#tabsMenu', () => {
       it('should be a TabsMenu', () => {
-        expect(mainMenu.tabsMenu).to.be.an.instanceof(TabsMenu);
+        expect(mainMenu.tabsMenu).toBeInstanceOf(TabsMenu);
       });
 
       it('should be the sixth menu', () => {
         expect(
           ArrayExt.firstIndexOf(mainMenu.menus, mainMenu.tabsMenu.menu)
-        ).to.equal(5);
+        ).toBe(5);
       });
     });
 
     describe('#settingsMenu', () => {
       it('should be a SettingsMenu', () => {
-        expect(mainMenu.settingsMenu).to.be.an.instanceof(SettingsMenu);
+        expect(mainMenu.settingsMenu).toBeInstanceOf(SettingsMenu);
       });
 
       it('should be the seventh menu', () => {
         expect(
           ArrayExt.firstIndexOf(mainMenu.menus, mainMenu.settingsMenu.menu)
-        ).to.equal(6);
+        ).toBe(6);
       });
     });
 
     describe('#helpMenu', () => {
       it('should be a HelpMenu', () => {
-        expect(mainMenu.helpMenu).to.be.an.instanceof(HelpMenu);
+        expect(mainMenu.helpMenu).toBeInstanceOf(HelpMenu);
       });
 
       it('should be the eighth menu', () => {
         expect(
           ArrayExt.firstIndexOf(mainMenu.menus, mainMenu.helpMenu.menu)
-        ).to.equal(7);
+        ).toBe(7);
       });
     });
   });

+ 6 - 7
tests/test-mainmenu/src/run.spec.ts → packages/mainmenu/test/run.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 { CommandRegistry } from '@lumino/commands';
 
@@ -43,8 +42,8 @@ describe('@jupyterlab/mainmenu', () => {
 
     describe('#constructor()', () => {
       it('should construct a new run menu', () => {
-        expect(menu).to.be.an.instanceof(RunMenu);
-        expect(menu.menu.title.label).to.equal('Run');
+        expect(menu).toBeInstanceOf(RunMenu);
+        expect(menu.menu.title.label).toBe('Run');
       });
     });
 
@@ -68,11 +67,11 @@ describe('@jupyterlab/mainmenu', () => {
         };
         menu.codeRunners.add(runner);
         void delegateExecute(wodget, menu.codeRunners, 'run');
-        expect(wodget.state).to.equal('run');
+        expect(wodget.state).toBe('run');
         void delegateExecute(wodget, menu.codeRunners, 'runAll');
-        expect(wodget.state).to.equal('runAll');
+        expect(wodget.state).toBe('runAll');
         void delegateExecute(wodget, menu.codeRunners, 'restartAndRunAll');
-        expect(wodget.state).to.equal('restartAndRunAll');
+        expect(wodget.state).toBe('restartAndRunAll');
       });
     });
   });

+ 2 - 0
tests/test-mainmenu/src/util.ts → packages/mainmenu/test/util.ts

@@ -1,4 +1,6 @@
 // Copyright (c) Jupyter Development Team.
+
+import 'jest';
 // Distributed under the terms of the Modified BSD License.
 
 import { IMenuExtender } from '@jupyterlab/mainmenu';

+ 9 - 10
tests/test-mainmenu/src/view.spec.ts → packages/mainmenu/test/view.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 { CommandRegistry } from '@lumino/commands';
 
@@ -45,8 +44,8 @@ describe('@jupyterlab/mainmenu', () => {
 
     describe('#constructor()', () => {
       it('should construct a new view menu', () => {
-        expect(menu).to.be.an.instanceof(ViewMenu);
-        expect(menu.menu.title.label).to.equal('View');
+        expect(menu).toBeInstanceOf(ViewMenu);
+        expect(menu.menu.title.label).toBe('View');
       });
     });
 
@@ -74,13 +73,13 @@ describe('@jupyterlab/mainmenu', () => {
 
         expect(
           delegateToggled(wodget, menu.editorViewers, 'matchBracketsToggled')
-        ).to.equal(false);
+        ).toBe(false);
         expect(
           delegateToggled(wodget, menu.editorViewers, 'wordWrapToggled')
-        ).to.equal(false);
+        ).toBe(false);
         expect(
           delegateToggled(wodget, menu.editorViewers, 'lineNumbersToggled')
-        ).to.equal(false);
+        ).toBe(false);
 
         void delegateExecute(wodget, menu.editorViewers, 'toggleLineNumbers');
         void delegateExecute(wodget, menu.editorViewers, 'toggleMatchBrackets');
@@ -88,13 +87,13 @@ describe('@jupyterlab/mainmenu', () => {
 
         expect(
           delegateToggled(wodget, menu.editorViewers, 'matchBracketsToggled')
-        ).to.equal(true);
+        ).toBe(true);
         expect(
           delegateToggled(wodget, menu.editorViewers, 'wordWrapToggled')
-        ).to.equal(true);
+        ).toBe(true);
         expect(
           delegateToggled(wodget, menu.editorViewers, 'lineNumbersToggled')
-        ).to.equal(true);
+        ).toBe(true);
       });
     });
   });

+ 27 - 0
packages/mainmenu/tsconfig.test.json

@@ -0,0 +1,27 @@
+{
+  "extends": "../../tsconfigbase.test",
+  "include": ["src/*", "test/*"],
+  "references": [
+    {
+      "path": "../apputils"
+    },
+    {
+      "path": "../services"
+    },
+    {
+      "path": "../ui-components"
+    },
+    {
+      "path": "../../testutils"
+    },
+    {
+      "path": "../apputils"
+    },
+    {
+      "path": "../services"
+    },
+    {
+      "path": "../ui-components"
+    }
+  ]
+}

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

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

+ 0 - 32
tests/test-mainmenu/package.json

@@ -1,32 +0,0 @@
-{
-  "name": "@jupyterlab/test-mainmenu",
-  "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/apputils": "^2.1.0",
-    "@jupyterlab/mainmenu": "^2.1.0",
-    "@jupyterlab/testutils": "^2.1.0",
-    "@lumino/algorithm": "^1.2.3",
-    "@lumino/commands": "^1.10.1",
-    "@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-mainmenu/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 - 21
tests/test-mainmenu/tsconfig.json

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