Skip to content

Commit 13604bd

Browse files
Add tests for notebook cell call stack and thoroughly test
1 parent 82d9e5e commit 13604bd

11 files changed

Lines changed: 305 additions & 0 deletions

apps/client-e2e/src/tests/notebooks/_notebook-runner.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import { Logger } from '@idl/logger';
22

33
import { Runner } from '../runner.class';
44
import { NewNotebook } from './new-notebook';
5+
import { NotebookCallStackDecorationsNoDecorations } from './notebook-call-stack-decorations-no-decorations';
6+
import { NotebookCallStackDecorationsOnExecutionHalted1 } from './notebook-call-stack-decorations-on-execution-halted';
7+
import { NotebookCallStackDecorationsOnStop } from './notebook-call-stack-decorations-on-stop';
58
import { NotebookDecorationsBehaveRight } from './notebook-decorations-behave-right';
69
import { NotebookFormats_1_0_0 } from './notebook-formats-1.0.0';
710
import { NotebookFormats_2_0_0 } from './notebook-formats-2.0.0';
@@ -156,6 +159,21 @@ NOTEBOOK_RUNNER.addTest({
156159
],
157160
});
158161

162+
NOTEBOOK_RUNNER.addTest({
163+
name: 'Stack trace decorations on execution halted 1',
164+
fn: NotebookCallStackDecorationsOnExecutionHalted1,
165+
});
166+
167+
NOTEBOOK_RUNNER.addTest({
168+
name: 'Stack trace decorations on stop',
169+
fn: NotebookCallStackDecorationsOnStop,
170+
});
171+
172+
NOTEBOOK_RUNNER.addTest({
173+
name: 'Stack trace decorations dont show for normal execution',
174+
fn: NotebookCallStackDecorationsNoDecorations,
175+
});
176+
159177
// reset goes first
160178
NOTEBOOK_RUNNER.addTest({
161179
name: 'Reset does the right thing',
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import { NOTEBOOK_FOLDER } from '@idl/notebooks/shared';
2+
import { Sleep } from '@idl/shared';
3+
import {
4+
IDLDecorationsManager,
5+
IStackTraceLookup,
6+
} from '@idl/vscode/decorations';
7+
import { IDLNotebookController } from '@idl/vscode/notebooks';
8+
import { OpenNotebookInVSCode, VSCODE_COMMANDS } from '@idl/vscode/shared';
9+
import expect from 'expect';
10+
import { existsSync, rmSync } from 'fs';
11+
import * as vscode from 'vscode';
12+
13+
import { DEFAULT_RUNNER_NOTEBOOK_TIMEOUT } from './notebook-timeout.interface';
14+
15+
/**
16+
* helper function to:
17+
*
18+
* 1. Open notebook
19+
* 2. Clear existing outputs
20+
* 3. Run notebook
21+
* 4. Check call stack against what we expect
22+
* 5. Clear outputs
23+
* 6. Close
24+
*/
25+
export async function RunNotebookAndCheckCallStackDecorations(
26+
file: string,
27+
stack: IStackTraceLookup,
28+
controller: IDLNotebookController,
29+
decorations: IDLDecorationsManager,
30+
clear = true
31+
) {
32+
// nuke .idl folder if it exists
33+
if (existsSync(NOTEBOOK_FOLDER)) {
34+
rmSync(NOTEBOOK_FOLDER, { recursive: true, force: true });
35+
}
36+
37+
// alert user
38+
console.log(` Running notebook: ${file}`);
39+
40+
/**
41+
* Open the notebook
42+
*/
43+
const nb = await OpenNotebookInVSCode(file);
44+
45+
// clear any existing outputs
46+
await vscode.commands.executeCommand(VSCODE_COMMANDS.NOTEBOOK_CLEAR_OUTPUTS);
47+
48+
// save to disk
49+
await nb.save();
50+
51+
// run all cells
52+
await vscode.commands.executeCommand(VSCODE_COMMANDS.NOTEBOOK_RUN_ALL);
53+
54+
// make sure launched
55+
expect(controller.isStarted()).toBeTruthy();
56+
57+
// short pause based on the number of cells we have
58+
// sometimes the rendering takes too long to register (like complex maps)
59+
// so we need an extra pause
60+
await Sleep(DEFAULT_RUNNER_NOTEBOOK_TIMEOUT);
61+
62+
// get current decorations
63+
const current = decorations.decorations.stack;
64+
65+
// compare the stack
66+
expect(current).toEqual(stack);
67+
68+
if (clear) {
69+
// clear outputs
70+
await vscode.commands.executeCommand(
71+
VSCODE_COMMANDS.NOTEBOOK_CLEAR_OUTPUTS
72+
);
73+
}
74+
75+
// save again
76+
await nb.save();
77+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { GetExtensionPath } from '@idl/shared';
2+
3+
import { RunnerFunction } from '../runner.interface';
4+
import { RunNotebookAndCheckCallStackDecorations } from './helpers/run-notebook-and-check-call-stack-decorations';
5+
6+
/**
7+
* Function that verifies decorations do the right things for notebooks
8+
*/
9+
export const NotebookCallStackDecorationsNoDecorations: RunnerFunction = async (
10+
init
11+
) => {
12+
// make sure the call stack is correct
13+
await RunNotebookAndCheckCallStackDecorations(
14+
GetExtensionPath(
15+
'idl/test/client-e2e/notebooks/decorations/no-decorations.1.idlnb'
16+
),
17+
{},
18+
init.notebooks.controller,
19+
init.decorations
20+
);
21+
22+
// make sure the call stack is correct
23+
await RunNotebookAndCheckCallStackDecorations(
24+
GetExtensionPath(
25+
'idl/test/client-e2e/notebooks/decorations/no-decorations.2.idlnb'
26+
),
27+
{},
28+
init.notebooks.controller,
29+
init.decorations
30+
);
31+
32+
// make sure the call stack is correct
33+
await RunNotebookAndCheckCallStackDecorations(
34+
GetExtensionPath(
35+
'idl/test/client-e2e/notebooks/decorations/no-decorations.3.idlnb'
36+
),
37+
{},
38+
init.notebooks.controller,
39+
init.decorations
40+
);
41+
42+
// make sure the call stack is correct
43+
await RunNotebookAndCheckCallStackDecorations(
44+
GetExtensionPath(
45+
'idl/test/client-e2e/notebooks/decorations/no-decorations.4.idlnb'
46+
),
47+
{},
48+
init.notebooks.controller,
49+
init.decorations
50+
);
51+
};
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { GetExtensionPath } from '@idl/shared';
2+
import { IStackTraceLookup } from '@idl/vscode/decorations';
3+
import { OpenNotebookInVSCode } from '@idl/vscode/shared';
4+
5+
import { RunnerFunction } from '../runner.interface';
6+
import { RunNotebookAndCheckCallStackDecorations } from './helpers/run-notebook-and-check-call-stack-decorations';
7+
8+
/**
9+
* Function that verifies decorations do the right things for notebooks
10+
*/
11+
export const NotebookCallStackDecorationsOnExecutionHalted1: RunnerFunction =
12+
async (init) => {
13+
const nbFile = GetExtensionPath(
14+
'idl/test/client-e2e/notebooks/decorations/on-execution-halted.1.idlnb'
15+
);
16+
17+
// open our notebook
18+
const nb = await OpenNotebookInVSCode(nbFile, true);
19+
20+
const stack: IStackTraceLookup = {};
21+
stack[nb.getCells()[0].document.uri.toString()] = [0];
22+
23+
// make sure the call stack is correct
24+
await RunNotebookAndCheckCallStackDecorations(
25+
nbFile,
26+
stack,
27+
init.notebooks.controller,
28+
init.decorations
29+
);
30+
};
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { GetExtensionPath } from '@idl/shared';
2+
import { IStackTraceLookup } from '@idl/vscode/decorations';
3+
import { OpenNotebookInVSCode } from '@idl/vscode/shared';
4+
5+
import { RunnerFunction } from '../runner.interface';
6+
import { RunNotebookAndCheckCallStackDecorations } from './helpers/run-notebook-and-check-call-stack-decorations';
7+
8+
/**
9+
* Function that verifies decorations do the right things for notebooks
10+
*/
11+
export const NotebookCallStackDecorationsOnStop: RunnerFunction = async (
12+
init
13+
) => {
14+
const nbFile = GetExtensionPath(
15+
'idl/test/client-e2e/notebooks/decorations/on-stop.idlnb'
16+
);
17+
18+
// open our notebook
19+
const nb = await OpenNotebookInVSCode(nbFile, true);
20+
21+
const stack: IStackTraceLookup = {};
22+
stack[nb.getCells()[1].document.uri.toString()] = [0];
23+
24+
// make sure the call stack is correct
25+
await RunNotebookAndCheckCallStackDecorations(
26+
nbFile,
27+
stack,
28+
init.notebooks.controller,
29+
init.decorations
30+
);
31+
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"version": "2.0.0",
3+
"cells": [
4+
{
5+
"type": "code",
6+
"content": [
7+
"print, 'Hello world! IDL Notebooks are awesome.'"
8+
],
9+
"metadata": {},
10+
"outputs": []
11+
}
12+
]
13+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"version": "2.0.0",
3+
"cells": [
4+
{
5+
"type": "code",
6+
"content": [
7+
"; print out each folder on IDL's search path",
8+
"print, strsplit(!path, path_sep(/search_path), /extract), /implied_print"
9+
],
10+
"metadata": {},
11+
"outputs": []
12+
}
13+
]
14+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"version": "2.0.0",
3+
"cells": [
4+
{
5+
"type": "code",
6+
"content": [
7+
"pro test_no_decorations_3",
8+
" compile_opt idl2",
9+
"",
10+
" print, 42",
11+
"end"
12+
],
13+
"metadata": {},
14+
"outputs": []
15+
}
16+
]
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"version": "2.0.0",
3+
"cells": [
4+
{
5+
"type": "code",
6+
"content": [
7+
"pro test_syntax_error_no_decorations_4",
8+
" compile_opt idl2",
9+
"",
10+
" a = ; error",
11+
"end"
12+
],
13+
"metadata": {},
14+
"outputs": []
15+
}
16+
]
17+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"version": "2.0.0",
3+
"cells": [
4+
{
5+
"type": "code",
6+
"content": [
7+
"a = 42 + fourtytwo"
8+
],
9+
"metadata": {},
10+
"outputs": []
11+
}
12+
]
13+
}

0 commit comments

Comments
 (0)