better logic for "notebook open/close, notebook ready when cell-document open event is fired", https://github.com/microsoft/vscode/issues/123655

This commit is contained in:
Johannes Rieken
2021-05-18 09:40:31 +02:00
parent 191ebfabe6
commit 956347c4ed

View File

@@ -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);