Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run Python tests on MacOS with Python 12, replace canvas with jest-canvas-mock #16314

Merged
merged 6 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/macostests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ jobs:
matrix:
group: [integrity, python, usage, usage2]
python-version: [3.11]
include:
- group: python
python-version: 3.12
fail-fast: false
timeout-minutes: 45
runs-on: macos-latest
Expand Down
31 changes: 0 additions & 31 deletions docs/source/developer/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -345,24 +345,6 @@ To check which version of Node.js is installed:

node -v

.. _Installing Node.js and jlpm section:

The canvas node package is not properly packaged for macOS with ARM architectures (M1 and M2).
To build JupyterLab on such platforms, you need a few additional packages:

With conda:

.. code:: bash

conda install -c conda-forge pkg-config pango libpng cairo jpeg giflib librsvg glib pixman
export PKG_CONFIG_PATH=$CONDA_PREFIX/lib/pkgconfig

With Homebrew:

.. code:: bash

brew install pkg-config cairo pango libpng jpeg giflib librsvg

.. _automatic_local_dev_env:

Using automation to set up a local development environment
Expand Down Expand Up @@ -478,11 +460,6 @@ Notes:
called something else (such as "python3") then parts of the build
will fail. You may wish to build in a conda environment, or make an
alias.
- If you see an error that says ``Call to 'pkg-config pixman-1 --libs'
returned exit status 127 while in binding.gyp`` while running the
``pip install`` command above, you may be missing packages required
by ``canvas``. Please see the `Installing Node.js and jlpm section`_
of this guide for instructions on how to install these packages.
- The ``jlpm`` command is a JupyterLab-provided, locked version of the
`yarn <https://classic.yarnpkg.com/en/>`__ package manager. If you have
``yarn`` installed already, you can use the ``yarn`` command when
Expand Down Expand Up @@ -564,14 +541,6 @@ appropriate package folder:
We advice to use it as some tests are spinning a Jupyter Server that does not
like to be executed in parallel.

If you see a test run fail with ``Library not loaded: '@rpath/libpixman-1.0.dylib'``
(or a different library, such as ``libcairo.2.dylib`` for Mac computers with Apple
Silicon chips) while running the
``jlpm test`` command above, you may be missing packages required
by ``canvas``. Please see
`Installing Node.js and jlpm section`_
of this guide for instructions on how to install these packages.

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
``it.only`` to a specific test when debugging. All of the ``test*``
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion packages/csvviewer/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
*/

const func = require('@jupyterlab/testing/lib/jest-config');
module.exports = func(__dirname);
const config = func(__dirname);
config['setupFiles'].push('jest-canvas-mock');
module.exports = config;
2 changes: 1 addition & 1 deletion packages/csvviewer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@
"devDependencies": {
"@jupyterlab/testing": "^4.2.0",
"@types/jest": "^29.2.0",
"canvas": "^2.11.2",
"csv-spectrum": "^1.0.0",
"jest": "^29.2.0",
"jest-canvas-mock": "^2.5.2",
"rimraf": "~5.0.5",
"typescript": "~5.1.6"
},
Expand Down
4 changes: 3 additions & 1 deletion packages/debugger/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
*/

const func = require('@jupyterlab/testing/lib/jest-config');
module.exports = func(__dirname);
const config = func(__dirname);
config['setupFiles'].push('jest-canvas-mock');
module.exports = config;
2 changes: 1 addition & 1 deletion packages/debugger/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@
"devDependencies": {
"@jupyterlab/testing": "^4.2.0",
"@types/jest": "^29.2.0",
"canvas": "^2.11.2",
"jest": "^29.2.0",
"jest-canvas-mock": "^2.5.2",
"rimraf": "~5.0.5",
"typescript": "~5.1.6"
},
Expand Down
4 changes: 3 additions & 1 deletion packages/terminal/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
*/

const func = require('@jupyterlab/testing/lib/jest-config');
module.exports = func(__dirname);
const config = func(__dirname);
config['setupFiles'].push('jest-canvas-mock');
module.exports = config;
2 changes: 1 addition & 1 deletion packages/terminal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
"devDependencies": {
"@jupyterlab/testing": "^4.2.0",
"@types/jest": "^29.2.0",
"canvas": "^2.11.2",
"jest": "^29.2.0",
"jest-canvas-mock": "^2.5.2",
"rimraf": "~5.0.5",
"typescript": "~5.1.6"
},
Expand Down
4 changes: 3 additions & 1 deletion packages/vega5-extension/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
*/

const func = require('@jupyterlab/testutils/lib/jest-config');
module.exports = func(__dirname);
const config = func(__dirname);
config['setupFiles'].push('jest-canvas-mock');
module.exports = config;
1 change: 1 addition & 0 deletions packages/vega5-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"@types/jest": "^29.2.0",
"@types/webpack-env": "^1.18.0",
"jest": "^29.2.0",
"jest-canvas-mock": "^2.5.2",
"rimraf": "~5.0.5",
"typescript": "~5.1.6"
},
Expand Down
29 changes: 29 additions & 0 deletions packages/vega5-extension/test/renderer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ describe('@jupyterlab/vega5-extension', () => {

expect(model).toHaveProperty('data.image/png');
expect(model).not.toHaveProperty(SCALE_FACTOR_PROP);
});

// requires `canvas`
it.skip('should keep size of PNG', async () => {
const model = new MimeModel({
data: {
[VEGALITE5_MIME_TYPE]: VEGALITE5_SPEC
}
});
await VEGALITE5_RENDERER.renderModel(model);

const size = getPNGSize(model.data['image/png'] as string);

Expand All @@ -49,6 +59,25 @@ describe('@jupyterlab/vega5-extension', () => {

expect(model).toHaveProperty('data.image/png');
expect(model).toHaveProperty(SCALE_FACTOR_PROP, scaleFactor);
});

// requires `canvas`
it.skip('should resize scaled PNG', async () => {
const scaleFactor = 2;

const model = new MimeModel({
data: {
[VEGALITE5_MIME_TYPE]: VEGALITE5_SPEC
},
metadata: {
[VEGALITE5_MIME_TYPE]: {
embed_options: {
scaleFactor
}
}
}
});
await VEGALITE5_RENDERER.renderModel(model);

const size = getPNGSize(model.data['image/png'] as string);

Expand Down