Skip to content

Commit 10c32eb

Browse files
Steve SilvesterGitHub Enterprise
Steve Silvester
authored and
GitHub Enterprise
committed
Add Jest Tests (jupyter-server#56)
* add jest test infra * get a basic test running * make build quieter and increase timeout * allow root * try this * try local dir * another attempt at config * try json file * fix manifest * wip test suite * try with this
1 parent 63e2840 commit 10c32eb

12 files changed

+8495
-593
lines changed

.eslintignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ coverage
44
**/*.d.ts
55
tests
66
style/index.js
7-
.eslintrc.js
7+
*.js

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,6 @@ cython_debug/
143143
node_modules/
144144
data_studio_jupyter_extensions/labextension/
145145
tsconfig.tsbuildinfo
146+
tsconfig.test.tsbuildinfo
146147
Untitled*.ipynb
148+
junit.xml

MANIFEST.in

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ include *.txt
66
include *.yml
77
include condarc
88
recursive-include jupyter-config *.json
9+
include *.js
10+
recursive-include test *.ts
911

1012
include package.json
1113
include install.json

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
.PHONY: install build watch run-remote run-local test
44

55
install:
6-
pip install pre-commit --index-url https://pypi.apple.com/simple
7-
pip install -e ".[test]" --index-url https://pypi.apple.com/simple
6+
pip install -q pre-commit --index-url https://pypi.apple.com/simple
7+
pip install -q -e ".[test]" --index-url https://pypi.apple.com/simple
88
jupyter server extension enable data_studio_jupyter_extensions
99
jupyter labextension develop . --overwrite
1010
pre-commit install

babel.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('@jupyterlab/testutils/lib/babel.config');

build.sh

+9-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,14 @@ which python
3838
python -V
3939
which pip
4040
pip config --user set global.progress_bar off
41-
pip install check-manifest pre-commit
41+
pip install -q check-manifest pre-commit
42+
43+
# Set up Jupyter Config
44+
CONFIG_DIR=/workspace/miniconda/envs/data_studio_jupyter_extensions/etc/jupyter
45+
mkdir -p ${CONFIG_DIR}
46+
cat <<EOF >> ${CONFIG_DIR}/jupyter_server_config.json
47+
{ "ServerApp": { "allow_root": true } }
48+
EOF
4249

4350
echo "+++++++++++++++++++++++++PYTHON++++++++++++++++++++++++++++++"
4451
make install
@@ -47,7 +54,7 @@ make test
4754
echo "++++++++++++++++++++NPM+++++++++++++++++++++++++++++++++++"
4855
yarn
4956
yarn build
50-
yarn test
57+
yarn test:cov
5158

5259
echo "+++++++++++++++++++++++++INTEGRITY++++++++++++++++++++++++++++++"
5360
check-manifest -v

jest.config.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const func = require('@jupyterlab/testutils/lib/jest-config');
2+
var config = func(__dirname);
3+
config.transform = {
4+
'\\.svg$': 'jest-raw-loader',
5+
'^.+\\.md?$': 'markdown-loader-jest',
6+
'\\.[j]sx?$': 'babel-jest'
7+
};
8+
config.transformIgnorePatterns = [];
9+
config.coverageThreshold = {
10+
global: {
11+
functions: 70,
12+
lines: 70,
13+
statements: -10
14+
}
15+
};
16+
17+
module.exports = config;

package.json

+10-1
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,18 @@
3434
"build:labextension": "jupyter labextension build .",
3535
"build:labextension:dev": "jupyter labextension build --development True .",
3636
"build:lib": "tsc",
37+
"build:test": "tsc --build tsconfig.test.json",
3738
"clean": "jlpm run clean:lib",
3839
"clean:lib": "rimraf lib tsconfig.tsbuildinfo",
3940
"clean:labextension": "rimraf studio/labextension",
4041
"clean:all": "jlpm run clean:lib && jlpm run clean:labextension",
4142
"eslint": "eslint . --ext .ts,.tsx --fix",
4243
"eslint:check": "eslint . --ext .ts,.tsx",
4344
"install:extension": "jlpm run build",
44-
"test": "echo 'No Test'",
45+
"test": "jest",
46+
"test:cov": "jest --collect-coverage",
47+
"test:debug": "node --inspect-brk node_modules/.bin/jest --runInBand",
48+
"test:debug:watch": "node --inspect-brk node_modules/.bin/jest --runInBand --watch",
4549
"watch": "run-p watch:src watch:labextension",
4650
"watch:src": "tsc -w",
4751
"watch:labextension": "jupyter labextension watch ."
@@ -55,16 +59,21 @@
5559
"@jupyterlab/settingregistry": "^3.0.0"
5660
},
5761
"devDependencies": {
62+
"@babel/preset-env": "^7.15.0",
5863
"@jupyterlab/builder": "^3.0.0",
64+
"@jupyterlab/testutils": "^3.1.3",
65+
"@types/jest": "^26.0.10",
5966
"@typescript-eslint/eslint-plugin": "^4.8.1",
6067
"@typescript-eslint/parser": "^4.8.1",
6168
"eslint": "^7.14.0",
6269
"eslint-config-prettier": "^6.15.0",
6370
"eslint-plugin-prettier": "^3.1.4",
71+
"jest": "^26.4.2",
6472
"mkdirp": "^1.0.3",
6573
"npm-run-all": "^4.1.5",
6674
"prettier": "^2.1.1",
6775
"rimraf": "^3.0.2",
76+
"ts-jest": "^26.3.0",
6877
"typescript": "~4.1.3"
6978
},
7079
"sideEffects": [

src/index.ts

+1-18
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
} from '@jupyterlab/application';
55

66
import { PageConfig, URLExt } from '@jupyterlab/coreutils';
7-
import { ISettingRegistry } from '@jupyterlab/settingregistry';
87
import { ILoggerRegistry } from '@jupyterlab/logconsole';
98
import { INotebookTracker, NotebookPanel } from '@jupyterlab/notebook';
109

@@ -15,29 +14,13 @@ const plugin: JupyterFrontEndPlugin<void> = {
1514
id: 'data_studio:plugin',
1615
autoStart: true,
1716
requires: [ILoggerRegistry, INotebookTracker],
18-
optional: [ISettingRegistry],
1917
activate: (
2018
app: JupyterFrontEnd,
2119
loggerRegistry: ILoggerRegistry,
22-
notebookTracker: INotebookTracker,
23-
settingRegistry: ISettingRegistry | null
20+
notebookTracker: INotebookTracker
2421
) => {
2522
console.log('JupyterLab extension studio is activated!');
2623

27-
if (settingRegistry) {
28-
settingRegistry
29-
.load(plugin.id)
30-
.then(settings => {
31-
console.log(
32-
'data studio studio settings loaded:',
33-
settings.composite
34-
);
35-
})
36-
.catch(reason => {
37-
console.error('Failed to load settings for data studio.', reason);
38-
});
39-
}
40-
4124
let path = '';
4225
const url = URLExt.join(PageConfig.getWsUrl(), 'subscribe');
4326
const ws = new WebSocket(url);

test/status.spec.ts

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { flakyIt as it } from '@jupyterlab/testutils';
2+
3+
import { JupyterLab } from '@jupyterlab/application';
4+
5+
import { INotebookModel, NotebookTracker } from '@jupyterlab/notebook';
6+
7+
import { Context } from '@jupyterlab/docregistry';
8+
import {
9+
initNotebookContext,
10+
JupyterServer,
11+
NBTestUtils
12+
} from '@jupyterlab/testutils';
13+
14+
import { LoggerRegistry } from '@jupyterlab/logconsole';
15+
16+
import plugin from '../src/index';
17+
18+
const server = new JupyterServer();
19+
20+
beforeAll(async () => {
21+
jest.setTimeout(20000);
22+
await server.start();
23+
});
24+
25+
afterAll(async () => {
26+
await server.shutdown();
27+
});
28+
29+
const app = new JupyterLab();
30+
const defaultRendermime = NBTestUtils.defaultRenderMime();
31+
const loggerRegistry = new LoggerRegistry({ defaultRendermime, maxLength: 10 });
32+
const notebookTracker = new NotebookTracker({ namespace: 'test' });
33+
34+
describe('status', () => {
35+
let context: Context<INotebookModel>;
36+
37+
beforeEach(async () => {
38+
context = await initNotebookContext();
39+
});
40+
41+
it('should create the plugin', () => {
42+
const notebookPanel = NBTestUtils.createNotebookPanel(context);
43+
plugin.activate(app, loggerRegistry, notebookTracker);
44+
notebookTracker.add(notebookPanel);
45+
});
46+
});

tsconfig.test.json

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"compilerOptions": {
3+
"allowSyntheticDefaultImports": true,
4+
"composite": true,
5+
"declaration": true,
6+
"esModuleInterop": true,
7+
"incremental": true,
8+
"jsx": "react",
9+
"module": "esnext",
10+
"moduleResolution": "node",
11+
"noEmitOnError": true,
12+
"noImplicitAny": true,
13+
"noUnusedLocals": true,
14+
"preserveWatchOutput": true,
15+
"resolveJsonModule": true,
16+
"rootDir": ".",
17+
"outDir": "lib",
18+
"strict": true,
19+
"strictNullChecks": true,
20+
"target": "es2017",
21+
"types": []
22+
},
23+
"include": ["src/*", "test/*"]
24+
}

0 commit comments

Comments
 (0)