Skip to content

Commit

Permalink
better logic for "notebook open/close, notebook ready when cell-docum…
Browse files Browse the repository at this point in the history
…ent open event is fired", #123655
  • Loading branch information
jrieken committed May 18, 2021
1 parent 191ebfa commit 956347c
Showing 1 changed file with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,27 @@ suite('Notebook Document', function () {
test('notebook open/close, notebook ready when cell-document open event is fired', async function () {
const uri = await utils.createRandomFile(undefined, undefined, '.nbdtest');
let didHappen = false;
const p = utils.asPromise(vscode.workspace.onDidOpenTextDocument).then(doc => {
if (doc.uri.scheme !== 'vscode-notebook-cell') {
return;
}
const notebook = vscode.notebook.notebookDocuments.find(notebook => {
const cell = notebook.getCells().find(cell => cell.document === doc);
return Boolean(cell);

const p = new Promise<void>((resolve, reject) => {
const sub = vscode.workspace.onDidOpenTextDocument(doc => {
if (doc.uri.scheme !== 'vscode-notebook-cell') {
// ignore other open events
return;
}
const notebook = vscode.notebook.notebookDocuments.find(notebook => {
const cell = notebook.getCells().find(cell => cell.document === doc);
return Boolean(cell);
});
assert.ok(notebook, `notebook for cell ${doc.uri} NOT found`);
didHappen = true;
sub.dispose();
resolve();
});
assert.ok(notebook, `notebook for cell ${doc.uri} NOT found`);
didHappen = true;

setTimeout(() => {
sub.dispose();
reject(new Error('TIMEOUT'));
}, 15000);
});

await vscode.notebook.openNotebookDocument(uri);
Expand Down

0 comments on commit 956347c

Please sign in to comment.