-
Notifications
You must be signed in to change notification settings - Fork 463
/
bqplot.test.ts
132 lines (104 loc) · 3.97 KB
/
bqplot.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
import { expect, IJupyterLabPageFixture, test } from '@jupyterlab/galata';
import * as path from 'path';
const klaw = require('klaw-sync');
const filterUpdateNotebooks = item => {
const basename = path.basename(item.path);
return basename.includes('_update');
}
const testCellOutputs = async (page: IJupyterLabPageFixture, tmpPath: string, theme: 'JupyterLab Light' | 'JupyterLab Dark') => {
const paths = klaw(path.resolve(__dirname, './notebooks'), {filter: item => !filterUpdateNotebooks(item), nodir: true});
const notebooks = paths.map(item => path.basename(item.path));
const contextPrefix = theme == 'JupyterLab Light' ? 'light' : 'dark';
page.theme.setTheme(theme);
for (const notebook of notebooks) {
let results = [];
await page.notebook.openByPath(`${tmpPath}/${notebook}`);
await page.notebook.activate(notebook);
let numCellImages = 0;
const getCaptureImageName = (contextPrefix: string, notebook: string, id: number): string => {
return `${contextPrefix}-${notebook}-cell-${id}.png`;
};
await page.notebook.runCellByCell({
onAfterCellRun: async (cellIndex: number) => {
const cell = await page.notebook.getCellOutput(cellIndex);
if (cell) {
results.push(await cell.screenshot());
numCellImages++;
}
}
});
await page.notebook.save();
for (let c = 0; c < numCellImages; ++c) {
expect(results[c]).toMatchSnapshot(getCaptureImageName(contextPrefix, notebook, c), {threshold: 0.3});
}
await page.notebook.close(true);
}
}
const testPlotUpdates = async (page: IJupyterLabPageFixture, tmpPath: string, theme: 'JupyterLab Light' | 'JupyterLab Dark') => {
const paths = klaw(path.resolve(__dirname, './notebooks'), {filter: item => filterUpdateNotebooks(item), nodir: true});
const notebooks = paths.map(item => path.basename(item.path));
const contextPrefix = theme == 'JupyterLab Light' ? 'light' : 'dark';
page.theme.setTheme(theme);
for (const notebook of notebooks) {
let results = [];
await page.notebook.openByPath(`${tmpPath}/${notebook}`);
await page.notebook.activate(notebook);
const getCaptureImageName = (contextPrefix: string, notebook: string, id: number): string => {
return `${contextPrefix}-${notebook}-cell-${id}.png`;
};
let cellCount = 0;
await page.notebook.runCellByCell({
onAfterCellRun: async (cellIndex: number) => {
// Always get first cell output which must contain the plot
const cell = await page.notebook.getCellOutput(0);
if (cell) {
results.push(await cell.screenshot());
cellCount++;
}
}
});
await page.notebook.save();
for (let i = 0; i < cellCount; i++) {
expect(results[i]).toMatchSnapshot(getCaptureImageName(contextPrefix, notebook, i), {threshold: 0.3});
}
await page.notebook.close(true);
}
};
test.describe('bqplot Visual Regression', () => {
test.beforeEach(async ({ page, tmpPath }) => {
page.on("console", (message) => {
console.log('CONSOLE MSG ---', message.text());
});
await page.contents.uploadDirectory(
path.resolve(__dirname, './notebooks'),
tmpPath
);
await page.filebrowser.openDirectory(tmpPath);
});
test('Light theme: Check bqplot first renders', async ({
page,
tmpPath,
}) => {
await testCellOutputs(page, tmpPath, 'JupyterLab Light');
});
test('Dark theme: Check bqplot first renders', async ({
page,
tmpPath,
}) => {
await testCellOutputs(page, tmpPath, 'JupyterLab Dark');
});
test('Light theme: Check bqplot update plot properties', async ({
page,
tmpPath,
}) => {
await testPlotUpdates(page, tmpPath, 'JupyterLab Light');
});
test('Dark theme: Check bqplot update plot properties', async ({
page,
tmpPath,
}) => {
await testPlotUpdates(page, tmpPath, 'JupyterLab Dark');
});
});