-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1460 from finos/jupyter-tests
Add Jupyterlab tests to CI
- Loading branch information
Showing
21 changed files
with
783 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
24 changes: 24 additions & 0 deletions
24
packages/perspective-jupyterlab/test/config/jupyter/globalSetup.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/****************************************************************************** | ||
* | ||
* Copyright (c) 2019, the Perspective Authors. | ||
* | ||
* This file is part of the Perspective library, distributed under the terms of | ||
* the Apache License 2.0. The full license can be found in the LICENSE file. | ||
* | ||
*/ | ||
const {start_jlab, kill_jlab} = require("./jlab_start"); | ||
|
||
module.exports = async function() { | ||
await start_jlab(); | ||
|
||
// At this point, Jupyterlab has already been started by the main test | ||
// runner, so all we need to do is set up the signal listeners to | ||
// clean up the Jupyter process if we Ctrl-C. | ||
process.on("SIGINT", kill_jlab); | ||
process.on("SIGABRT", kill_jlab); | ||
|
||
// execute the standard globalSetup.js which will set up the | ||
// Puppeteer browser instance. | ||
const setup = require(`@finos/perspective-test/src/js/globalSetup.js`); | ||
await setup(); | ||
}; |
16 changes: 16 additions & 0 deletions
16
packages/perspective-jupyterlab/test/config/jupyter/jest.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/****************************************************************************** | ||
* | ||
* Copyright (c) 2019, the Perspective Authors. | ||
* | ||
* This file is part of the Perspective library, distributed under the terms of | ||
* the Apache License 2.0. The full license can be found in the LICENSE file. | ||
* | ||
*/ | ||
const main_config = require("@finos/perspective-test/jest.config.js"); | ||
|
||
module.exports = Object.assign(main_config, { | ||
globalSetup: "<rootDir>/test/config/jupyter/globalSetup.js", | ||
setupFilesAfterEnv: ["<rootDir>/test/config/jupyter/teardown.js"], | ||
testMatch: ["<rootDir>/test/jupyter/*.spec.js"], | ||
roots: ["test"] | ||
}); |
87 changes: 87 additions & 0 deletions
87
packages/perspective-jupyterlab/test/config/jupyter/jlab_start.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/****************************************************************************** | ||
* | ||
* Copyright (c) 2019, the Perspective Authors. | ||
* | ||
* This file is part of the Perspective library, distributed under the terms of | ||
* the Apache License 2.0. The full license can be found in the LICENSE file. | ||
* | ||
*/ | ||
const path = require("path"); | ||
const {get} = require("http"); | ||
const {spawn} = require("child_process"); | ||
const {execute} = require("../../../../../scripts/script_utils"); | ||
|
||
const PACKAGE_ROOT = path.join(__dirname, "..", "..", ".."); | ||
|
||
/** | ||
* Kill the Jupyterlab process created by the tests. | ||
*/ | ||
const kill_jlab = () => { | ||
console.log("-- Cleaning up Jupyterlab process"); | ||
execute`ps aux | grep -i '[j]upyter-lab --no-browser' | awk '{print $2}' | xargs kill -9 && echo "[perspective-jupyterlab] JupyterLab process terminated"`; | ||
}; | ||
|
||
exports.kill_jlab = kill_jlab; | ||
|
||
/** | ||
* Block until the Jupyterlab server is ready. | ||
*/ | ||
const wait_for_jlab = async function() { | ||
let num_errors = 0; | ||
let loaded = false; | ||
|
||
while (!loaded) { | ||
get(`http://127.0.0.1:${process.env.__JUPYTERLAB_PORT__}/lab?`, res => { | ||
if (res.statusCode !== 200) { | ||
throw new Error(`${res.statusCode} not 200!`); | ||
} | ||
|
||
console.log(`Jupyterlab server has started on ${process.env.__JUPYTERLAB_PORT__}`); | ||
loaded = true; | ||
}).on("error", err => { | ||
if (num_errors > 50) { | ||
kill_jlab(); | ||
throw new Error(`Could not launch Jupyterlab: ${err}`); | ||
} | ||
|
||
num_errors++; | ||
}); | ||
|
||
await new Promise(resolve => setTimeout(resolve, 500)); | ||
} | ||
}; | ||
|
||
exports.start_jlab = function() { | ||
/* | ||
* Spawn the Jupyterlab server. | ||
*/ | ||
try { | ||
// Does not alter the global env, only the env for this process | ||
process.env.JUPYTER_CONFIG_DIR = path.join(PACKAGE_ROOT, "test", "config", "jupyter"); | ||
process.env.JUPYTERLAB_SETTINGS_DIR = path.join(PACKAGE_ROOT, "test", "config", "jupyter", "user_settings"); | ||
|
||
// Start jupyterlab with a root to dist/umd where the notebooks will be. | ||
process.chdir(path.join(PACKAGE_ROOT, "dist", "umd")); | ||
|
||
console.log("Spawning Jupyterlab process"); | ||
|
||
// Jupyterlab is spawned with the default $PYTHONPATH of the shell it | ||
// is running in. For local testing during devlopment you may need to | ||
// run it with the $PYTHONPATH set to ./python/perspective | ||
const proc = spawn("jupyter", ["lab", "--no-browser", `--port=${process.env.__JUPYTERLAB_PORT__}`, `--config=${process.env.JUPYTER_CONFIG_DIR}/jupyter_notebook_config.json`], { | ||
env: { | ||
...process.env | ||
}, | ||
stdio: "inherit" | ||
}); | ||
|
||
// Wait for Jupyterlab to start up | ||
return wait_for_jlab().then(() => { | ||
return proc; | ||
}); | ||
} catch (e) { | ||
console.error(e); | ||
kill_jlab(); | ||
process.exit(1); | ||
} | ||
}; |
Oops, something went wrong.