Skip to content

Commit

Permalink
Fix circular dependencies that pollutes version bump (jupyterlab#12495)
Browse files Browse the repository at this point in the history
* Create @jupyterlab/testing

Move tests from codeeditor to codemirror
This is needed to respect package hierarchy

Refactor test to have logical dependencies graph

* Add all test dependencies for coreutils

* Internalize retry setup and server start up

* Remove testutils from new files

* Restore the testutils API as much as possible

* Fix tests

* Fix debugger tests

* Update timeout for flaky test

* Fix setup/teardown

* Advice to use `runInBand` when running locally

* Fix running all tests at once locally

* [skip ci] Update docs/source/extension/extension_migration.rst

Co-authored-by: Jeremy Tuloup <[email protected]>

* Increase timeout for last timed out test

Locally all tests are passing (thanks to the --runInBand option)
Hopefully this one can pass on the CI too.

* Automatic application of license header

* Undo custom timeout setting

* Apply changes to @jupyterlab/metadataform

Co-authored-by: Jeremy Tuloup <[email protected]>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Jan 3, 2023
1 parent 92f5734 commit 1d36ce5
Show file tree
Hide file tree
Showing 295 changed files with 2,779 additions and 2,427 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/linuxjs-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ jobs:
js-lsp,
js-mainmenu,
js-metadataform,
js-metapackage,
js-nbformat,
js-notebook,
js-observables,
Expand All @@ -47,12 +48,12 @@ jobs:
js-settingregistry,
js-statedb,
js-statusbar,
js-testing,
js-terminal,
js-toc,
js-translation,
js-ui-components,
js-vega5-extension,
js-testutils,
]
fail-fast: false
runs-on: ubuntu-20.04
Expand Down
2 changes: 1 addition & 1 deletion buildutils/src/ensure-package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ export async function ensurePackage(
}
const isTest = data.name.indexOf('test') !== -1;
if (isTest) {
const testLibs = ['jest', 'ts-jest', '@jupyterlab/testutils'];
const testLibs = ['jest', 'ts-jest', '@jupyterlab/testing'];
if (testLibs.indexOf(name) !== -1) {
return;
}
Expand Down
29 changes: 19 additions & 10 deletions buildutils/src/ensure-repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const MISSING: Dict<string[]> = {
'@jupyterlab/buildutils': ['path', 'webpack'],
'@jupyterlab/builder': ['path'],
'@jupyterlab/galata': ['fs', 'path'],
'@jupyterlab/testutils': ['fs', 'path'],
'@jupyterlab/testing': ['fs', 'path'],
'@jupyterlab/vega5-extension': ['vega-embed']
};

Expand Down Expand Up @@ -100,7 +100,7 @@ const UNUSED: Dict<string[]> = {
'@jupyterlab/galata': ['node-fetch', 'http-server'],
'@jupyterlab/services': ['node-fetch', 'ws'],
'@jupyterlab/rendermime': ['@jupyterlab/mathjax2'],
'@jupyterlab/testutils': [
'@jupyterlab/testing': [
'@babel/core',
'@babel/preset-env',
'fs-extra',
Expand All @@ -109,6 +109,12 @@ const UNUSED: Dict<string[]> = {
'jest-environment-jsdom',
'jest-junit'
],
'@jupyterlab/testutils': [
'@jupyterlab/application',
'@jupyterlab/apputils',
'@jupyterlab/notebook',
'@jupyterlab/rendermime'
],
'@jupyterlab/test-csvviewer': ['csv-spectrum'],
'@jupyterlab/vega5-extension': ['vega', 'vega-lite']
};
Expand Down Expand Up @@ -244,16 +250,15 @@ const SKIP_CSS: Dict<string[]> = {
'@jupyterlab/vdom-extension',
'@jupyterlab/vega5-extension'
],
'@jupyterlab/notebook': ['@jupyterlab/application'],
'@jupyterlab/rendermime-interfaces': ['@lumino/widgets'],
'@jupyterlab/shortcuts-extension': ['@jupyterlab/application'],
'@jupyterlab/testutils': [
'@jupyterlab/application',
'@jupyterlab/apputils',
'@jupyterlab/codeeditor',
'@jupyterlab/codemirror',
'@jupyterlab/notebook',
'@jupyterlab/rendermime',
'@jupyterlab/docregistry',
'@jupyterlab/cells',
'@jupyterlab/notebook'
'@jupyterlab/testing'
],
'@jupyterlab/theme-light-extension': [
'@jupyterlab/application',
Expand Down Expand Up @@ -388,7 +393,7 @@ function ensureMetaPackage(): string[] {
let valid = true;

// Ensure it is a dependency.
if (!mpData.dependencies[name]) {
if (!mpData.dependencies[name] && name !== '@jupyterlab/testing') {
valid = false;
mpData.dependencies[name] = '^' + data.version;
}
Expand Down Expand Up @@ -561,7 +566,10 @@ function ensureJupyterlab(): string[] {
const corePackage = utils.readJSONFile(corePath);
const corePaths = utils.getCorePaths();

ensureCorePackage(corePackage, corePaths);
ensureCorePackage(
corePackage,
corePaths.filter(p => !/\/packages\/testing$/.test(p))
);
corePackage.jupyterlab.mimeExtensions = {};

const coreData = getCoreData(corePaths);
Expand Down Expand Up @@ -845,7 +853,8 @@ export async function ensureIntegrity(): Promise<boolean> {
const tsConfigDocExclude = [
'application-extension',
'metapackage',
'nbconvert-css'
'nbconvert-css',
'testing'
];
const tsConfigdocPath = path.resolve('.', 'tsconfigdoc.json');
const tsConfigdocData = utils.readJSONFile(tsConfigdocPath);
Expand Down
2 changes: 1 addition & 1 deletion buildutils/template/babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
* Distributed under the terms of the Modified BSD License.
*/

module.exports = require('@jupyterlab/testutils/lib/babel.config');
module.exports = require('@jupyterlab/testing/lib/babel-config');
2 changes: 1 addition & 1 deletion buildutils/template/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
* Distributed under the terms of the Modified BSD License.
*/

const func = require('@jupyterlab/testutils/lib/jest-config');
const func = require('@jupyterlab/testing/lib/jest-config');
module.exports = func(__dirname);
4 changes: 1 addition & 3 deletions buildutils/template/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,9 @@
"watch": "tsc -b --watch"
},
"devDependencies": {
"@jupyterlab/testutils": "^4.0.0-alpha.16",
"@jupyterlab/testing": "^4.0.0-alpha.16",
"@types/jest": "^29.2.0",
"jest": "^29.2.0",
"rimraf": "~3.0.0",
"ts-jest": "^29.0.0",
"typescript": "~4.7.3"
},
"publishConfig": {
Expand Down
2 changes: 1 addition & 1 deletion buildutils/template/tsconfig.test.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"path": "."
},
{
"path": "../../testutils"
"path": "../../packages/testing"
}
]
}
1 change: 1 addition & 0 deletions dev_mode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@
"@jupyterlab/statusbar-extension": "../packages/statusbar-extension",
"@jupyterlab/terminal": "../packages/terminal",
"@jupyterlab/terminal-extension": "../packages/terminal-extension",
"@jupyterlab/testing": "../packages/testing",
"@jupyterlab/theme-dark-extension": "../packages/theme-dark-extension",
"@jupyterlab/theme-light-extension": "../packages/theme-light-extension",
"@jupyterlab/toc": "../packages/toc",
Expand Down
8 changes: 7 additions & 1 deletion docs/source/developer/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,13 @@ appropriate package folder:
cd packages/notebook
jlpm run build:test
jlpm test
jlpm test --runInBand
.. note::

``--runInBand`` option will run all tests serially in the current process.
We advice to use it as some tests are spinning a Jupyter Server that does not
like to be executed in parallel.

We use ``jest`` for all tests, so standard ``jest`` workflows apply.
Tests can be debugged in either VSCode or Chrome. It can help to add an
Expand Down
15 changes: 15 additions & 0 deletions docs/source/extension/extension_migration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,21 @@ bumped their major version (following semver convention). We want to point out p
The ``anchor`` parameter of ``HoverBox.IOptions`` is now a ``DOMRect`` instead of ``ClientRect``.
The ``CodeEditor.ICoordinate`` interface now extends ``DOMRectReadOnly`` instead of ``JSONObject, ClientRect``.

Testing with Jest
^^^^^^^^^^^^^^^^^

Jest has been updated to 29.2.0 (and *ts-jest* to 29.0.0). And therefore the jest configuration provided by
``@jupyterlab/testutils`` is compatible for that version. In particular:

- The unmaintained reporter ``jest-summary-reporter`` has been replaced by the new default ``github-actions`` reporter.
- The helper ``flakyIt`` has been removed. You can use the new `jest.retryTimes <https://jestjs.io/docs/jest-object#jestretrytimesnumretries-options>`_ instead.

With JupyterLab 4, we fixed circular dependencies due to the testutils package. So it is now only a facade to export
helpers from various core packages. The exported helpers are the same as before expect for:

- ``NBTestUtils.DEFAULT_CONTENT``: Removed - you could imported from ``@jupyterlab/notebook/lib/testutils`` but we strongly advice not to and to use your own test data.
- ``NBTestUtils.DEFAULT_CONTENT_45``: Removed

Extension Development Changes
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"build:packages:scope": "lerna run build",
"build:src": "lerna run build --scope \"@jupyterlab/!(test-|example-|application-top)*\" --concurrency 1",
"build:test": "lerna run build:test",
"build:test:scope": "lerna run build --concurrency 1",
"build:test:scope": "lerna run build:test --concurrency 1",
"build:testutils": "cd testutils && npm run build",
"build:utils": "cd buildutils && npm run build",
"bump:js:major": "node buildutils/lib/bump-js-major.js",
Expand Down Expand Up @@ -89,12 +89,12 @@
"stylelint": "jlpm stylelint:check --fix",
"stylelint:check": "stylelint --cache \"{packages/*,galata}/style/**/*.css\" \"{examples/*,docs/**}/*.css\"",
"stylelint:files": "stylelint --fix",
"test": "lerna run test --scope \"@jupyterlab/*\" --concurrency 1 --stream",
"test:all": "lerna run test --scope \"@jupyterlab/*\" --concurrency 1 --stream --no-bail",
"test": "lerna run test --scope \"@jupyterlab/!(galata|template)*\" --concurrency 1 --stream",
"test:all": "lerna run test --scope \"@jupyterlab/!(galata|template)*\" --concurrency 1 --stream --no-bail",
"test:examples": "python examples/test_examples.py",
"test:galata": "lerna run test --scope \"@jupyterlab/galata\" --concurrency 1 --stream",
"test:scope": "lerna run test --concurrency 1 --stream",
"test:summary": "lerna run test --scope \"@jupyterlab/*\" --parallel --no-bail | grep -Ei '.* test.*(failed|passed|total|completed|skipped)' | sort",
"test:summary": "lerna run test --scope \"@jupyterlab/!(galata|template)*\" --parallel --no-bail | grep -Ei '.* test.*(failed|passed|total|completed|skipped)' | sort",
"update:dependency": "node buildutils/lib/update-dependency.js --lerna",
"watch": "python scripts/watch_dev.py",
"watch:main": "npm run watch",
Expand Down
2 changes: 1 addition & 1 deletion packages/application/babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
* Distributed under the terms of the Modified BSD License.
*/

module.exports = require('@jupyterlab/testutils/lib/babel.config');
module.exports = require('@jupyterlab/testing/lib/babel-config');
2 changes: 1 addition & 1 deletion packages/application/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
* Distributed under the terms of the Modified BSD License.
*/

const func = require('@jupyterlab/testutils/lib/jest-config');
const func = require('@jupyterlab/testing/lib/jest-config');
module.exports = func(__dirname);
4 changes: 1 addition & 3 deletions packages/application/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,9 @@
"@lumino/widgets": "^2.0.0-alpha.6"
},
"devDependencies": {
"@jupyterlab/testutils": "^4.0.0-alpha.16",
"@jupyterlab/testing": "^4.0.0-alpha.16",
"@types/jest": "^29.2.0",
"jest": "^29.2.0",
"rimraf": "~3.0.0",
"ts-jest": "^29.0.0",
"typedoc": "~0.22.10",
"typescript": "~4.7.3"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/application/test/router.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Distributed under the terms of the Modified BSD License.

import { Router } from '@jupyterlab/application';
import { signalToPromise } from '@jupyterlab/testutils';
import { signalToPromise } from '@jupyterlab/testing';
import { CommandRegistry } from '@lumino/commands';
import { Token } from '@lumino/coreutils';

Expand Down
2 changes: 1 addition & 1 deletion packages/application/test/shell.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import { LabShell, LayoutRestorer } from '@jupyterlab/application';
import { StateDB } from '@jupyterlab/statedb';
import { framePromise } from '@jupyterlab/testutils';
import { framePromise } from '@jupyterlab/testing';
import { CommandRegistry } from '@lumino/commands';
import { Message } from '@lumino/messaging';
import { DockPanel, Widget } from '@lumino/widgets';
Expand Down
2 changes: 1 addition & 1 deletion packages/application/tsconfig.test.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"path": "."
},
{
"path": "../../testutils"
"path": "../testing"
}
]
}
2 changes: 1 addition & 1 deletion packages/apputils/babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
* Distributed under the terms of the Modified BSD License.
*/

module.exports = require('@jupyterlab/testutils/lib/babel.config');
module.exports = require('@jupyterlab/testing/lib/babel-config');
2 changes: 1 addition & 1 deletion packages/apputils/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
* Distributed under the terms of the Modified BSD License.
*/

const func = require('@jupyterlab/testutils/lib/jest-config');
const func = require('@jupyterlab/testing/lib/jest-config');
module.exports = func(__dirname);
8 changes: 3 additions & 5 deletions packages/apputils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
"build:test": "tsc --build tsconfig.test.json",
"clean": "rimraf lib && rimraf tsconfig.tsbuildinfo",
"docs": "typedoc src",
"test": "jest",
"test:cov": "jest --collect-coverage",
"test": "jest -i",
"test:cov": "jest -i --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"
Expand Down Expand Up @@ -67,12 +67,10 @@
"sanitize-html": "~2.7.3"
},
"devDependencies": {
"@jupyterlab/testutils": "^4.0.0-alpha.16",
"@jupyterlab/testing": "^4.0.0-alpha.16",
"@types/jest": "^29.2.0",
"@types/sanitize-html": "^2.3.1",
"jest": "^29.2.0",
"rimraf": "~3.0.0",
"ts-jest": "^29.0.0",
"typedoc": "~0.22.10",
"typescript": "~4.7.3"
},
Expand Down
49 changes: 49 additions & 0 deletions packages/apputils/src/testutils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (c) Jupyter Development Team.
* Distributed under the terms of the Modified BSD License.
*/

import { ServiceManager } from '@jupyterlab/services';
import { UUID } from '@lumino/coreutils';
import { SessionContext } from './sessioncontext';

/**
* Create a client session object.
*/
export async function createSessionContext(
options: Partial<SessionContext.IOptions> = {}
): Promise<SessionContext> {
const manager = options.sessionManager ?? Private.getManager().sessions;
const specsManager = options.specsManager ?? Private.getManager().kernelspecs;

await Promise.all([manager.ready, specsManager.ready]);
return new SessionContext({
sessionManager: manager,
specsManager,
path: options.path ?? UUID.uuid4(),
name: options.name,
type: options.type,
kernelPreference: options.kernelPreference ?? {
shouldStart: true,
canStart: true,
name: specsManager.specs?.default
}
});
}

/**
* A namespace for private data.
*/
namespace Private {
let manager: ServiceManager;

/**
* Get or create the service manager singleton.
*/
export function getManager(): ServiceManager {
if (!manager) {
manager = new ServiceManager({ standby: 'never' });
}
return manager;
}
}
2 changes: 1 addition & 1 deletion packages/apputils/test/dialog.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
acceptDialog,
dismissDialog,
waitForDialog
} from '@jupyterlab/testutils';
} from '@jupyterlab/testing';
import { Message } from '@lumino/messaging';
import { Widget } from '@lumino/widgets';
import * as React from 'react';
Expand Down
2 changes: 1 addition & 1 deletion packages/apputils/test/inputdialog.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
acceptDialog,
dismissDialog,
waitForDialog
} from '@jupyterlab/testutils';
} from '@jupyterlab/testing';

describe('@jupyterlab/apputils', () => {
describe('InputDialog', () => {
Expand Down
Loading

0 comments on commit 1d36ce5

Please sign in to comment.