jupyterlab_code_formatter icon indicating copy to clipboard operation
jupyterlab_code_formatter copied to clipboard

Add labextension tests

Open ryantam626 opened this issue 6 years ago • 3 comments

Recent added server extension test, need to figure out how to test the lab extension itself now..

ryantam626 avatar Dec 01 '19 18:12 ryantam626

Hey @ryantam626 thanks for this great extension.

I saw, you get troubles with testing your extension.

First a quick note FYI on setting up extension handlers, your set up method is good:

https://github.com/ryantam626/jupyterlab_code_formatter/blob/6c1e3c8bb1aaf2599e4d1cefbec0151d668d6e59/serverextension/jupyterlab_code_formatter/tests/test_handlers.py#L55

An alternative approach (closer to user set up) is to set the config of the test server class to activate the server extension. See for example:

https://github.com/hadim/jupyter-archive/blob/0bf34ffe10834d3d202d0b9de0f89436695a0589/jupyter_archive/tests/test_archive_handler.py#L17

About frontend testing, I would advice using Jest. To get it set up is a bit tricky, but you can look at https://github.com/jupyterlab/jupyterlab-git/ for example.

You will need the jest.config.js, the babel.config.js and the testutils folder + add the following dev dep:

    "@babel/core": "^7.5.0",
    "@babel/preset-env": "^7.5.0",
    "@jupyterlab/testutils": "^1.1.0",
    "@types/jest": "^24",
    "identity-obj-proxy": "^3.0.0",
    "jest": "^24",
    "jest-fetch-mock": "^1.6.6",
    "ts-jest": "^24",

Then you will find the tests in the tests folder.

fcollonval avatar Dec 07 '19 13:12 fcollonval

Thanks for the pointers :+1: I will give it a shot some time soon again

I tried replicating the karma setup found in the jupyterlab repo, the whole experience is frustrating to say the least... (it probably didn't help that I don't write TS for a living :sweat: )

ryantam626 avatar Dec 07 '19 15:12 ryantam626

The trend seems to be around jest these days.

We plan to add an example about testing to the jupyterlab-extension-examples repo: https://github.com/jtpio/jupyterlab-extension-examples/issues/45

Hopefully this should help complement the documentation :)

jtpio avatar Dec 16 '19 16:12 jtpio