Skip to content

Commit 537d9b6

Browse files
committed
rebase
1 parent 39371f7 commit 537d9b6

3 files changed

Lines changed: 141 additions & 9 deletions

File tree

playwright/support/helpers.js

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,28 @@
88
*/
99

1010
const { spawn, spawnSync } = require('child_process');
11+
const path = require('path');
12+
const fs = require('fs');
13+
14+
function getPythonExecutable() {
15+
const isWin = process.platform === 'win32';
16+
const pyRelativePath = isWin ? ['Scripts', 'python.exe'] : ['bin', 'python'];
17+
const fallback = isWin ? 'python' : 'python3';
18+
19+
if (process.env.VIRTUAL_ENV) {
20+
return path.join(process.env.VIRTUAL_ENV, ...pyRelativePath);
21+
}
22+
const rootDir = path.join(__dirname, '..', '..');
23+
const localVenv = path.join(rootDir, '.venv', ...pyRelativePath);
24+
if (fs.existsSync(localVenv)) {
25+
return localVenv;
26+
}
27+
const localVenvAlt = path.join(rootDir, 'venv', ...pyRelativePath);
28+
if (fs.existsSync(localVenvAlt)) {
29+
return localVenvAlt;
30+
}
31+
return fallback;
32+
}
1133

1234
async function runDemo(page, name, opts = {}) {
1335
const saveto = opts.env || `${name}_${Math.floor(Math.random() * 1e6)}`;
@@ -26,19 +48,27 @@ async function runDemo(page, name, opts = {}) {
2648
spawnArgs.push('-seed', String(opts.seed));
2749
}
2850
if (opts.args && opts.args.length > 0) {
29-
spawnArgs.push('-arg', ...opts.args.map(String));
51+
spawnArgs.push('-args', ...opts.args.map(String));
3052
}
3153

54+
const pythonBin = getPythonExecutable();
55+
3256
if (opts.asyncrun) {
33-
const child = spawn('python', spawnArgs, {
57+
const child = spawn(pythonBin, spawnArgs, {
3458
stdio: 'ignore',
3559
detached: true,
3660
});
3761
child.unref();
3862
} else {
39-
spawnSync('python', spawnArgs, {
40-
stdio: 'ignore',
63+
const result = spawnSync(pythonBin, spawnArgs, {
64+
stdio: 'pipe',
65+
encoding: 'utf-8',
4166
});
67+
if (result.status !== 0) {
68+
throw new Error(
69+
`Failed to run demo '${name}'. Exit code: ${result.status}.\nStderr: ${result.stderr}\nStdout: ${result.stdout}`
70+
);
71+
}
4272
}
4373

4474
if (opts.open === undefined || opts.open) {
@@ -60,12 +90,12 @@ async function closeEnvs(page) {
6090
async function expandAllEnvGroups(page) {
6191
const closedGroups = page.locator('.rc-tree-select-tree-switcher_close');
6292
let count = await closedGroups.count();
63-
while (count > 0) {
64-
for (let i = 0; i < count; i++) {
65-
await closedGroups.nth(i).click({ force: true });
66-
await page.waitForTimeout(150);
67-
}
93+
let attempts = 0;
94+
while (count > 0 && attempts < 50) {
95+
await closedGroups.first().click({ force: true });
96+
await page.waitForTimeout(150);
6897
count = await closedGroups.count();
98+
attempts++;
6999
}
70100
}
71101

playwright/tests/misc.spec.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Copyright 2017-present, The Visdom Authors
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*
8+
*/
9+
10+
const { test, expect } = require('@playwright/test');
11+
const { runDemo } = require('../support/helpers');
12+
13+
test.describe('Misc Tests', () => {
14+
test.beforeEach(async ({ page }) => {
15+
await page.goto('/');
16+
});
17+
18+
test('plot_special_graph', async ({ page }) => {
19+
await runDemo(page, 'plot_special_graph');
20+
21+
await expect(page.locator('svg line')).toHaveCount(6);
22+
await expect(page.locator('svg path')).toHaveCount(6);
23+
await expect(page.locator('svg text')).toHaveCount(12);
24+
await expect(page.locator('svg g')).toHaveCount(6);
25+
});
26+
});

playwright/tests/text.spec.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/**
2+
* Copyright 2017-present, The Visdom Authors
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*
8+
*/
9+
10+
const { test, expect } = require('@playwright/test');
11+
const { runDemo } = require('../support/helpers');
12+
13+
test.describe('Text Pane', () => {
14+
test.beforeEach(async ({ page }) => {
15+
await page.goto('/');
16+
});
17+
18+
test('text_basic', async ({ page }) => {
19+
await runDemo(page, 'text_basic');
20+
const pane = page.locator('.layout .react-grid-item').first();
21+
await expect(pane).toContainText('Hello World!');
22+
});
23+
24+
test('text_update', async ({ page }) => {
25+
await runDemo(page, 'text_update');
26+
const pane = page.locator('.layout .react-grid-item').first();
27+
await expect(pane).toContainText('Hello World! More text should be here');
28+
await expect(pane).toContainText('And here it is');
29+
});
30+
31+
test('check download button', async ({ page }) => {
32+
await runDemo(page, 'text_update');
33+
const pane = page.locator('.layout .react-grid-item').first();
34+
const saveBtn = pane.locator('button[title="save"]').first();
35+
36+
const [download] = await Promise.all([
37+
page.waitForEvent('download'),
38+
saveBtn.click(),
39+
]);
40+
41+
expect(download.suggestedFilename()).toBe('visdom_text.txt');
42+
});
43+
44+
test('text_callbacks', async ({ page }) => {
45+
await runDemo(page, 'text_callbacks', { asyncrun: true });
46+
47+
const content = page.locator('.window .content').first();
48+
await content.waitFor({ state: 'visible' });
49+
50+
const bar = page.locator('.bar').first();
51+
await bar.click();
52+
53+
const layoutWrapper = page.locator('.no-focus');
54+
55+
const text = 'checking callback :(';
56+
for (let char of text) {
57+
await layoutWrapper.focus();
58+
await page.keyboard.type(char);
59+
await page.waitForTimeout(50);
60+
}
61+
62+
await layoutWrapper.focus();
63+
await page.keyboard.press('Backspace');
64+
await page.waitForTimeout(50);
65+
66+
await layoutWrapper.focus();
67+
await page.keyboard.type(')');
68+
69+
await expect(content).toContainText('checking callback :)');
70+
});
71+
72+
test('text_close', async ({ page }) => {
73+
await runDemo(page, 'text_close');
74+
await expect(page.locator('.layout .window')).toHaveCount(0);
75+
});
76+
});

0 commit comments

Comments
 (0)