Browse Source

clean up createFileSession and add self to test build target

Steven Silvester 5 years ago
parent
commit
6d6c18f7ac
39 changed files with 148 additions and 57 deletions
  1. 14 11
      buildutils/src/ensure-package.ts
  2. 3 0
      buildutils/template/tsconfig.test.json
  3. 0 1
      package.json
  4. 3 0
      packages/application/tsconfig.test.json
  5. 3 0
      packages/apputils/tsconfig.test.json
  6. 3 0
      packages/cells/tsconfig.test.json
  7. 3 0
      packages/codeeditor/tsconfig.test.json
  8. 3 0
      packages/codemirror/tsconfig.test.json
  9. 3 0
      packages/completer/tsconfig.test.json
  10. 3 0
      packages/console/tsconfig.test.json
  11. 3 0
      packages/coreutils/tsconfig.test.json
  12. 3 0
      packages/csvviewer/tsconfig.test.json
  13. 3 0
      packages/docmanager/tsconfig.test.json
  14. 23 15
      packages/docregistry/test/default.spec.ts
  15. 2 4
      packages/docregistry/test/mimedocument.spec.ts
  16. 3 0
      packages/docregistry/tsconfig.test.json
  17. 3 0
      packages/filebrowser/tsconfig.test.json
  18. 3 0
      packages/fileeditor/tsconfig.test.json
  19. 2 2
      packages/imageviewer/test/widget.spec.ts
  20. 3 0
      packages/imageviewer/tsconfig.test.json
  21. 3 0
      packages/inspector/tsconfig.test.json
  22. 3 0
      packages/logconsole/tsconfig.test.json
  23. 3 0
      packages/mainmenu/tsconfig.test.json
  24. 3 0
      packages/nbformat/tsconfig.test.json
  25. 3 0
      packages/notebook/tsconfig.test.json
  26. 3 0
      packages/observables/tsconfig.test.json
  27. 3 0
      packages/outputarea/tsconfig.test.json
  28. 1 7
      packages/rendermime/test/registry.spec.ts
  29. 3 0
      packages/rendermime/tsconfig.test.json
  30. 3 0
      packages/services/tsconfig.test.json
  31. 3 0
      packages/settingregistry/tsconfig.test.json
  32. 3 0
      packages/statedb/tsconfig.test.json
  33. 3 0
      packages/statusbar/tsconfig.test.json
  34. 3 0
      packages/terminal/tsconfig.test.json
  35. 3 0
      packages/ui-components/tsconfig.test.json
  36. 5 12
      scripts/ci_script.sh
  37. 1 1
      testutils/package.json
  38. 10 4
      testutils/src/mock.ts
  39. 3 0
      testutils/tsconfig.test.json

+ 14 - 11
buildutils/src/ensure-package.ts

@@ -271,6 +271,10 @@ export async function ensurePackage(
   const tsConfigTestPath = path.join(pkgPath, 'tsconfig.test.json');
   if (fs.existsSync(tsConfigTestPath)) {
     const testReferences: { [key: string]: string } = { ...references };
+
+    // Add a reference to self to build the local package as well.
+    testReferences['.'] = '.';
+
     Object.keys(devDeps).forEach(name => {
       if (!(name in locals)) {
         return;
@@ -282,17 +286,16 @@ export async function ensurePackage(
       const ref = path.relative(pkgPath, locals[name]);
       testReferences[name] = ref.split(path.sep).join('/');
     });
-    if (Object.keys(testReferences).length > 0) {
-      const tsConfigTestData = utils.readJSONFile(tsConfigTestPath);
-      tsConfigTestData.references = [];
-      Object.keys(testReferences).forEach(name => {
-        tsConfigTestData.references.push({ path: testReferences[name] });
-      });
-      Object.keys(references).forEach(name => {
-        tsConfigTestData.references.push({ path: testReferences[name] });
-      });
-      utils.writeJSONFile(tsConfigTestPath, tsConfigTestData);
-    }
+
+    const tsConfigTestData = utils.readJSONFile(tsConfigTestPath);
+    tsConfigTestData.references = [];
+    Object.keys(testReferences).forEach(name => {
+      tsConfigTestData.references.push({ path: testReferences[name] });
+    });
+    Object.keys(references).forEach(name => {
+      tsConfigTestData.references.push({ path: testReferences[name] });
+    });
+    utils.writeJSONFile(tsConfigTestPath, tsConfigTestData);
   }
 
   // Get a list of all the published files.

+ 3 - 0
buildutils/template/tsconfig.test.json

@@ -2,6 +2,9 @@
   "extends": "../../tsconfigbase.test",
   "include": ["src/*", "test/*"],
   "references": [
+    {
+      "path": "."
+    },
     {
       "path": "../../testutils"
     }

+ 0 - 1
package.json

@@ -31,7 +31,6 @@
     "build:packages:scope": "lerna run build",
     "build:src": "lerna run build --scope \"@jupyterlab/!(test-|example-|application-top)*\" --concurrency 1",
     "build:storybook": "lerna run build:storybook --concurrency 1",
-    "build:test": "lerna run build --scope \"@jupyterlab/test-*\" --concurrency 1",
     "build:test:scope": "lerna run build --concurrency 1",
     "build:testutils": "cd testutils && jlpm run build",
     "build:utils": "cd buildutils && jlpm run build",

+ 3 - 0
packages/application/tsconfig.test.json

@@ -26,6 +26,9 @@
     {
       "path": "../ui-components"
     },
+    {
+      "path": "."
+    },
     {
       "path": "../../testutils"
     },

+ 3 - 0
packages/apputils/tsconfig.test.json

@@ -17,6 +17,9 @@
     {
       "path": "../ui-components"
     },
+    {
+      "path": "."
+    },
     {
       "path": "../../testutils"
     },

+ 3 - 0
packages/cells/tsconfig.test.json

@@ -38,6 +38,9 @@
     {
       "path": "../ui-components"
     },
+    {
+      "path": "."
+    },
     {
       "path": "../../testutils"
     },

+ 3 - 0
packages/codeeditor/tsconfig.test.json

@@ -14,6 +14,9 @@
     {
       "path": "../ui-components"
     },
+    {
+      "path": "."
+    },
     {
       "path": "../../testutils"
     },

+ 3 - 0
packages/codemirror/tsconfig.test.json

@@ -20,6 +20,9 @@
     {
       "path": "../statusbar"
     },
+    {
+      "path": "."
+    },
     {
       "path": "../../testutils"
     },

+ 3 - 0
packages/completer/tsconfig.test.json

@@ -20,6 +20,9 @@
     {
       "path": "../ui-components"
     },
+    {
+      "path": "."
+    },
     {
       "path": "../../testutils"
     },

+ 3 - 0
packages/console/tsconfig.test.json

@@ -29,6 +29,9 @@
     {
       "path": "../ui-components"
     },
+    {
+      "path": "."
+    },
     {
       "path": "../../testutils"
     },

+ 3 - 0
packages/coreutils/tsconfig.test.json

@@ -2,6 +2,9 @@
   "extends": "../../tsconfigbase.test",
   "include": ["src/*", "test/*"],
   "references": [
+    {
+      "path": "."
+    },
     {
       "path": "../../testutils"
     }

+ 3 - 0
packages/csvviewer/tsconfig.test.json

@@ -11,6 +11,9 @@
     {
       "path": "../docregistry"
     },
+    {
+      "path": "."
+    },
     {
       "path": "../../testutils"
     },

+ 3 - 0
packages/docmanager/tsconfig.test.json

@@ -17,6 +17,9 @@
     {
       "path": "../statusbar"
     },
+    {
+      "path": "."
+    },
     {
       "path": "../../testutils"
     },

+ 23 - 15
packages/docregistry/test/default.spec.ts

@@ -22,7 +22,7 @@ import {
 
 import { ServiceManager } from '@jupyterlab/services';
 
-import { createFileContext, sleep } from '@jupyterlab/testutils';
+import { sleep } from '@jupyterlab/testutils';
 
 import * as Mock from '@jupyterlab/testutils/lib/mock';
 
@@ -179,7 +179,7 @@ describe('docregistry/default', () => {
         expect(factory.canStartKernel).toBe(true);
       });
 
-      it('should have toolbar items', () => {
+      it('should have toolbar items', async () => {
         const factory = new WidgetFactory({
           name: 'test',
           fileTypes: ['text'],
@@ -194,7 +194,7 @@ describe('docregistry/default', () => {
             }
           ]
         });
-        const context = createFileContext();
+        const context = await Mock.createFileContext();
         const widget = factory.createNew(context);
         const widget2 = factory.createNew(context);
         expect(toArray(widget.toolbar.names())).toEqual(['foo', 'bar']);
@@ -229,16 +229,16 @@ describe('docregistry/default', () => {
     });
 
     describe('#createNew()', () => {
-      it('should create a new widget given a document model and a context', () => {
+      it('should create a new widget given a document model and a context', async () => {
         const factory = createFactory();
-        const context = createFileContext();
+        const context = await Mock.createFileContext();
         const widget = factory.createNew(context);
         expect(widget).toBeInstanceOf(Widget);
       });
 
-      it('should take an optional source widget for cloning', () => {
+      it('should take an optional source widget for cloning', async () => {
         const factory = createFactory();
-        const context = createFileContext();
+        const context = await Mock.createFileContext();
         const widget = factory.createNew(context);
         const clonedWidget: IDocumentWidget = factory.createNew(
           context,
@@ -552,8 +552,8 @@ describe('docregistry/default', () => {
     let content: Widget;
     let widget: DocumentWidget;
 
-    const setup = () => {
-      context = createFileContext(undefined, manager);
+    const setup = async () => {
+      context = await Mock.createFileContext(false, manager);
       content = new Widget();
       widget = new DocumentWidget({ context, content });
     };
@@ -572,14 +572,11 @@ describe('docregistry/default', () => {
 
       it('should update the title when the path changes', async () => {
         const path = UUID.uuid4() + '.jl';
-        await context.initialize(true);
         await manager.contents.rename(context.path, path);
         expect(widget.title.label).toBe(path);
       });
 
       it('should add the dirty class when the model is dirty', async () => {
-        await context.initialize(true);
-        await context.ready;
         context.model.fromString('bar');
         expect(widget.title.className).toContain('jp-mod-dirty');
       });
@@ -593,22 +590,33 @@ describe('docregistry/default', () => {
       beforeEach(setup);
 
       it('should resolve after the reveal and context ready promises', async () => {
+        const thisContext = new Context({
+          manager,
+          factory: new TextModelFactory(),
+          path: UUID.uuid4()
+        });
         const x = Object.create(null);
         const reveal = sleep(300, x);
-        const contextReady = Promise.all([context.ready, x]);
-        const widget = new DocumentWidget({ context, content, reveal });
+        const contextReady = Promise.all([thisContext.ready, x]);
+        const widget = new DocumentWidget({
+          context: thisContext,
+          content,
+          reveal
+        });
         expect(widget.isRevealed).toBe(false);
 
         // Our promise should resolve before the widget reveal promise.
         expect(await Promise.race([widget.revealed, reveal])).toBe(x);
         // The context ready promise should also resolve first.
-        void context.initialize(true);
+        void thisContext.initialize(true);
         expect(await Promise.race([widget.revealed, contextReady])).toEqual([
           undefined,
           x
         ]);
         // The widget.revealed promise should finally resolve.
         expect(await widget.revealed).toBeUndefined();
+
+        thisContext.dispose();
       });
     });
   });

+ 2 - 4
packages/docregistry/test/mimedocument.spec.ts

@@ -53,8 +53,8 @@ const fooFactory: IRenderMime.IRendererFactory = {
 describe('docregistry/mimedocument', () => {
   let dContext: Context<DocumentRegistry.IModel>;
 
-  beforeEach(() => {
-    dContext = Mock.createFileContext();
+  beforeEach(async () => {
+    dContext = await Mock.createFileContext();
   });
 
   afterEach(() => {
@@ -100,7 +100,6 @@ describe('docregistry/mimedocument', () => {
           renderTimeout: 1000,
           dataType: 'string'
         });
-        void dContext.initialize(true);
         await widget.ready;
         const layout = widget.layout as BoxLayout;
         expect(layout.widgets.length).toBe(1);
@@ -110,7 +109,6 @@ describe('docregistry/mimedocument', () => {
     describe('contents changed', () => {
       it('should change the document contents', async () => {
         RENDERMIME.addFactory(fooFactory);
-        await dContext.initialize(true);
         const emission = testEmission(dContext.model.contentChanged, {
           test: () => {
             expect(dContext.model.toString()).toBe('bar');

+ 3 - 0
packages/docregistry/tsconfig.test.json

@@ -29,6 +29,9 @@
     {
       "path": "../ui-components"
     },
+    {
+      "path": "."
+    },
     {
       "path": "../../testutils"
     },

+ 3 - 0
packages/filebrowser/tsconfig.test.json

@@ -26,6 +26,9 @@
     {
       "path": "../ui-components"
     },
+    {
+      "path": "."
+    },
     {
       "path": "../../testutils"
     },

+ 3 - 0
packages/fileeditor/tsconfig.test.json

@@ -17,6 +17,9 @@
     {
       "path": "../ui-components"
     },
+    {
+      "path": "."
+    },
     {
       "path": "../../testutils"
     },

+ 2 - 2
packages/imageviewer/test/widget.spec.ts

@@ -161,14 +161,14 @@ describe('ImageViewer', () => {
 
 describe('ImageViewerFactory', () => {
   describe('#createNewWidget', () => {
-    it('should create an image document widget', () => {
+    it('should create an image document widget', async () => {
       const factory = new ImageViewerFactory({
         name: 'Image',
         modelName: 'base64',
         fileTypes: ['png'],
         defaultFor: ['png']
       });
-      const context = createFileContext(
+      const context = await createFileContext(
         IMAGE.path,
         new Mock.ServiceManagerMock()
       );

+ 3 - 0
packages/imageviewer/tsconfig.test.json

@@ -11,6 +11,9 @@
     {
       "path": "../docregistry"
     },
+    {
+      "path": "."
+    },
     {
       "path": "../../testutils"
     },

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

@@ -20,6 +20,9 @@
     {
       "path": "../statedb"
     },
+    {
+      "path": "."
+    },
     {
       "path": "../../testutils"
     },

+ 3 - 0
packages/logconsole/tsconfig.test.json

@@ -20,6 +20,9 @@
     {
       "path": "../services"
     },
+    {
+      "path": "."
+    },
     {
       "path": "../../testutils"
     },

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

@@ -11,6 +11,9 @@
     {
       "path": "../ui-components"
     },
+    {
+      "path": "."
+    },
     {
       "path": "../../testutils"
     },

+ 3 - 0
packages/nbformat/tsconfig.test.json

@@ -2,6 +2,9 @@
   "extends": "../../tsconfigbase.test",
   "include": ["src/*", "test/*"],
   "references": [
+    {
+      "path": "."
+    },
     {
       "path": "../../testutils"
     }

+ 3 - 0
packages/notebook/tsconfig.test.json

@@ -35,6 +35,9 @@
     {
       "path": "../ui-components"
     },
+    {
+      "path": "."
+    },
     {
       "path": "../../testutils"
     },

+ 3 - 0
packages/observables/tsconfig.test.json

@@ -2,6 +2,9 @@
   "extends": "../../tsconfigbase.test",
   "include": ["src/*", "test/*"],
   "references": [
+    {
+      "path": "."
+    },
     {
       "path": "../../testutils"
     }

+ 3 - 0
packages/outputarea/tsconfig.test.json

@@ -20,6 +20,9 @@
     {
       "path": "../services"
     },
+    {
+      "path": "."
+    },
     {
       "path": "../../testutils"
     },

+ 1 - 7
packages/rendermime/test/registry.spec.ts

@@ -69,13 +69,7 @@ describe('rendermime/registry', () => {
   let RESOLVER: IRenderMime.IResolver;
 
   beforeAll(async () => {
-    const fileContext = Mock.createFileContext(true);
-    await fileContext.initialize(true);
-
-    // The context initialization kicks off a sessionContext initialization,
-    // but does not wait for it. We need to wait for it so our url resolver
-    // has access to the session.
-    await fileContext.sessionContext.initialize();
+    const fileContext = await Mock.createFileContext(true);
     RESOLVER = fileContext.urlResolver;
   });
 

+ 3 - 0
packages/rendermime/tsconfig.test.json

@@ -23,6 +23,9 @@
     {
       "path": "../services"
     },
+    {
+      "path": "."
+    },
     {
       "path": "../mathjax2"
     },

+ 3 - 0
packages/services/tsconfig.test.json

@@ -17,6 +17,9 @@
     {
       "path": "../statedb"
     },
+    {
+      "path": "."
+    },
     {
       "path": "../../testutils"
     },

+ 3 - 0
packages/settingregistry/tsconfig.test.json

@@ -5,6 +5,9 @@
     {
       "path": "../statedb"
     },
+    {
+      "path": "."
+    },
     {
       "path": "../../testutils"
     },

+ 3 - 0
packages/statedb/tsconfig.test.json

@@ -2,6 +2,9 @@
   "extends": "../../tsconfigbase.test",
   "include": ["src/*", "test/*"],
   "references": [
+    {
+      "path": "."
+    },
     {
       "path": "../../testutils"
     }

+ 3 - 0
packages/statusbar/tsconfig.test.json

@@ -17,6 +17,9 @@
     {
       "path": "../ui-components"
     },
+    {
+      "path": "."
+    },
     {
       "path": "../../testutils"
     },

+ 3 - 0
packages/terminal/tsconfig.test.json

@@ -8,6 +8,9 @@
     {
       "path": "../services"
     },
+    {
+      "path": "."
+    },
     {
       "path": "../../testutils"
     },

+ 3 - 0
packages/ui-components/tsconfig.test.json

@@ -5,6 +5,9 @@
     {
       "path": "../coreutils"
     },
+    {
+      "path": "."
+    },
     {
       "path": "../../testutils"
     },

+ 5 - 12
scripts/ci_script.sh

@@ -19,20 +19,13 @@ fi
 
 if [[ $GROUP == js* ]]; then
 
-    if [[ $GROUP == js-* ]]; then
-        # extract the group name
-        export PKG="${GROUP#*-}"
-        pushd packages/${PKG}
-        jlpm run build; true
-        jlpm run build:test; true
-        CMD="jlpm run test:cov"
-    else
-        jlpm build:packages
-        jlpm build:test
-        CMD="jlpm test:cov --loglevel success"
-    fi
+    # extract the group name
+    export PKG="${GROUP#*-}"
+    pushd packages/${PKG}
+    jlpm run build:test; true
 
     export FORCE_COLOR=1
+    CMD="jlpm run test:cov"
     $CMD || $CMD || $CMD
     jlpm run clean
 fi

+ 1 - 1
testutils/package.json

@@ -26,7 +26,7 @@
   },
   "scripts": {
     "build": "tsc -b",
-    "build:test": "tsc -b && tsc --build tsconfig.test.json",
+    "build:test": "tsc --build tsconfig.test.json",
     "clean": "rimraf lib && rimraf tsconfig.tsbuildinfo",
     "prepublishOnly": "npm run build",
     "test": "jest",

+ 10 - 4
testutils/src/mock.ts

@@ -679,13 +679,16 @@ export const MockShellFuture = jest.fn<
 /**
  * Create a context for a file.
  */
-export function createFileContext(startKernel = false): Context {
+export async function createFileContext(
+  startKernel = false,
+  manager?: ServiceManager.IManager
+): Promise<Context> {
   const path = UUID.uuid4() + '.txt';
-  const manager = new ServiceManagerMock();
+  manager = manager || new ServiceManagerMock();
   const factory = new TextModelFactory();
 
-  return new Context({
-    manager,
+  const context = new Context({
+    manager: manager || new ServiceManagerMock(),
     factory,
     path,
     kernelPreference: {
@@ -694,6 +697,9 @@ export function createFileContext(startKernel = false): Context {
       autoStartDefault: startKernel
     }
   });
+  await context.initialize(true);
+  await context.sessionContext.initialize();
+  return context;
 }
 
 /**

+ 3 - 0
testutils/tsconfig.test.json

@@ -32,6 +32,9 @@
     {
       "path": "../packages/services"
     },
+    {
+      "path": "."
+    },
     {
       "path": "../packages/apputils"
     },