Skip to content

Commit

Permalink
Fix perspective-cli and add test
Browse files Browse the repository at this point in the history
  • Loading branch information
texodus committed Jan 10, 2023
1 parent 33bedd1 commit f141158
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 13 deletions.
5 changes: 4 additions & 1 deletion packages/perspective-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
"typings": "index.d.ts",
"scripts": {
"build": ":",
"clean": "rimraf build"
"clean": "rimraf build",
"test:run": "jest --rootDir=. --config=../../tools/perspective-test/jest.config.js --color",
"test": "npm-run-all test:build test:run"
},
"repository": {
"type": "git",
Expand All @@ -29,6 +31,7 @@
"@finos/perspective-viewer": "^1.9.0",
"@finos/perspective-viewer-d3fc": "^1.9.0",
"@finos/perspective-viewer-datagrid": "^1.9.0",
"@finos/perspective-workspace": "^1.9.0",
"commander": "^2.19.0",
"puppeteer": "^13.1.3"
}
Expand Down
9 changes: 5 additions & 4 deletions packages/perspective-cli/src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,18 @@ async function host(filename, options) {

const pages = await browser.pages();

// console.log("Fukc");
const page = pages[0];
page.on("close", () => {
browser.close();
process.exit(0);
});
}

return server;
}

module.exports.host = host;

program
.version(
JSON.parse(
Expand Down Expand Up @@ -158,8 +161,6 @@ program
.option("-o, --open", "Open a browser automagically.")
.action(host);

program.parse(process.argv);

if (!process.argv.slice(2).length) {
if (require.main && !process.argv.slice(2).length) {
program.help();
}
4 changes: 4 additions & 0 deletions packages/perspective-cli/test/csv/test.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
x,y
1,2
3,4
5,6
48 changes: 48 additions & 0 deletions packages/perspective-cli/test/js/superstore.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/******************************************************************************
*
* Copyright (c) 2017, 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 puppeteer = require("puppeteer");

const { host } = require("../../src/js/index.js");

jest.setTimeout(30000);

describe("CLI", function () {
it("Tests something", async () => {
const options = { port: 0 };
const server = await host("test/csv/test.csv", options);
const port = server._server.address().port;
console.log(port);

const browser = await puppeteer.launch({ headless: true });
const page = await browser.newPage();
await page.goto(`http://localhost:${port}/`);
await page.waitForSelector(
"perspective-viewer perspective-viewer-datagrid"
);

const json = await page.evaluate(async function () {
const viewer = document.querySelector("perspective-viewer");
const view = await viewer.getView();
return await view.to_json();
});

expect(json).toEqual([
{ x: 1, y: 2 },
{ x: 3, y: 4 },
{ x: 5, y: 6 },
]);

await page.close();
await browser.close();
await new Promise((x) => setTimeout(x));
server.close();
});
});
4 changes: 2 additions & 2 deletions packages/perspective-viewer-d3fc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"require": "./dist/umd/perspective-viewer-d3fc.js",
"import": "./dist/esm/perspective-viewer-d3fc.js"
},
"./src/": "./src/",
"./dist/": "./dist/",
"./src/*": "./src/*",
"./dist/*": "./dist/*",
"./cdn/": "./dist/cdn/",
"./esm/": "./dist/esm/",
"./area": "./dist/esm/area.js",
Expand Down
4 changes: 2 additions & 2 deletions packages/perspective-workspace/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"require": "./dist/umd/perspective-workspace.js"
},
"./esm/": "./dist/esm/",
"./src/": "./src/",
"./dist/": "./dist/",
"./src/*": "./src/*",
"./dist/*": "./dist/*",
"./dist/themes/": "./src/themes/",
"./package.json": "./package.json"
},
Expand Down
5 changes: 3 additions & 2 deletions packages/perspective/src/js/perspective.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ module.exports.sync_module = () => SYNC_SERVER.perspective;
const DEFAULT_ASSETS = [
"@finos/perspective/dist/cdn",
"@finos/perspective-bench/dist",
"@finos/perspective-workspace/dist/cdn",
"@finos/perspective-workspace/dist/css",
"@finos/perspective-viewer/dist/cdn",
"@finos/perspective-viewer/dist/css",
"@finos/perspective-viewer-datagrid/dist/cdn",
"@finos/perspective-viewer-d3fc/dist/cdn",
"@finos/perspective-workspace/dist/cdn",
"@finos/perspective-workspace/dist/css",
"@finos/perspective-jupyterlab/dist/cdn",
];

Expand Down Expand Up @@ -231,6 +231,7 @@ class WebSocketServer extends WebSocketManager {
}

close() {
super.clear();
this._server.close();
}
}
Expand Down
6 changes: 5 additions & 1 deletion packages/perspective/src/js/websocket/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class WebSocketManager extends Server {
this.chunk_size = 50 * 1000 * 1000;

// clear invalid connections
setInterval(() => {
this._timer = setInterval(() => {
Object.entries(this.websockets).forEach(([id, ws]) => {
if (ws.isAlive === false) {
delete this.websockets[id];
Expand All @@ -35,6 +35,10 @@ export class WebSocketManager extends Server {
}, 30000);
}

clear() {
clearInterval(this._timer);
}

/**
* Add a new websocket connection to the manager, and define a handler
* for all incoming messages. If the incoming message has `binary_length`
Expand Down
7 changes: 6 additions & 1 deletion scripts/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ async function focus_package() {
}
},
filter: (answer) => {
if (!answer || answer.length === 8) {
if (!answer || answer.length === 9) {
return "";
} else {
return answer;
Expand Down Expand Up @@ -141,6 +141,11 @@ async function focus_package() {
name: "perspective-workspace",
value: "perspective-workspace",
},
{
key: "l",
name: "perspective-cli",
value: "perspective-cli",
},
],
},
]);
Expand Down

0 comments on commit f141158

Please sign in to comment.