From 6989391bae145867da508688f45e7bf1c5fa0db8 Mon Sep 17 00:00:00 2001 From: Andrew Dupont Date: Fri, 27 Dec 2024 11:45:54 -0800 Subject: [PATCH] Fix `Workspace` specs --- spec/workspace-spec.js | 184 +++++++++++++++++++---------------------- 1 file changed, 84 insertions(+), 100 deletions(-) diff --git a/spec/workspace-spec.js b/spec/workspace-spec.js index c8e0c451ec..ba026b7880 100644 --- a/spec/workspace-spec.js +++ b/spec/workspace-spec.js @@ -38,118 +38,106 @@ describe('Workspace', () => { } }); - function simulateReload() { - waitsForPromise(() => { - const workspaceState = workspace.serialize(); - const projectState = atom.project.serialize({ isUnloading: true }); - workspace.destroy(); - atom.project.destroy(); - atom.project = new Project({ - notificationManager: atom.notifications, + async function simulateReload() { + const workspaceState = workspace.serialize(); + const projectState = atom.project.serialize({ isUnloading: true }); + workspace.destroy(); + atom.project.destroy(); + atom.project = new Project({ + notificationManager: atom.notifications, + packageManager: atom.packages, + confirm: atom.confirm.bind(atom), + applicationDelegate: atom.applicationDelegate, + grammarRegistry: atom.grammars + }); + + return atom.project.deserialize(projectState).then(() => { + workspace = atom.workspace = new Workspace({ + config: atom.config, + project: atom.project, packageManager: atom.packages, - confirm: atom.confirm.bind(atom), + grammarRegistry: atom.grammars, + styleManager: atom.styles, + deserializerManager: atom.deserializers, + notificationManager: atom.notifications, applicationDelegate: atom.applicationDelegate, - grammarRegistry: atom.grammars - }); - return atom.project.deserialize(projectState).then(() => { - workspace = atom.workspace = new Workspace({ - config: atom.config, - project: atom.project, - packageManager: atom.packages, - grammarRegistry: atom.grammars, - styleManager: atom.styles, - deserializerManager: atom.deserializers, - notificationManager: atom.notifications, - applicationDelegate: atom.applicationDelegate, - viewRegistry: atom.views, - assert: atom.assert.bind(atom), - textEditorRegistry: atom.textEditors - }); - workspace.deserialize(workspaceState, atom.deserializers); + viewRegistry: atom.views, + assert: atom.assert.bind(atom), + textEditorRegistry: atom.textEditors }); + workspace.deserialize(workspaceState, atom.deserializers); }); } describe('serialization', () => { describe('when the workspace contains text editors', () => { - it('constructs the view with the same panes', () => { + it('constructs the view with the same panes', async () => { + jasmine.useRealClock(); const pane1 = atom.workspace.getActivePane(); const pane2 = pane1.splitRight({ copyActiveItem: true }); const pane3 = pane2.splitRight({ copyActiveItem: true }); let pane4 = null; - waitsForPromise(() => - atom.workspace - .open(null) - .then(editor => editor.setText('An untitled editor.')) - ); + await atom.workspace + .open(null) + .then(editor => editor.setText('An untitled editor.')); - waitsForPromise(() => - atom.workspace - .open('b') - .then(editor => pane2.activateItem(editor.copy())) - ); + await atom.workspace + .open('b') + .then(editor => pane2.activateItem(editor.copy())); - waitsForPromise(() => - atom.workspace - .open('../sample.js') - .then(editor => pane3.activateItem(editor)) - ); + await atom.workspace + .open('../sample.js') + .then(editor => pane3.activateItem(editor)); - runs(() => { - pane3.activeItem.setCursorScreenPosition([2, 4]); - pane4 = pane2.splitDown(); - }); - waitsForPromise(() => - atom.workspace - .open('../sample.txt') - .then(editor => pane4.activateItem(editor)) - ); + pane3.activeItem.setCursorScreenPosition([2, 4]); + pane4 = pane2.splitDown(); - runs(() => { - pane4.getActiveItem().setCursorScreenPosition([0, 2]); - pane2.activate(); - }); + await atom.workspace + .open('../sample.txt') + .then(editor => pane4.activateItem(editor)); - simulateReload(); - runs(() => { - expect(atom.workspace.getTextEditors().length).toBe(5); - const [ - editor1, - editor2, - untitledEditor, - editor3, - editor4 - ] = atom.workspace.getTextEditors(); - const firstDirectory = atom.project.getDirectories()[0]; - expect(firstDirectory).toBeDefined(); - expect(editor1.getPath()).toBe(firstDirectory.resolve('b')); - expect(editor2.getPath()).toBe( - firstDirectory.resolve('../sample.txt') - ); - expect(editor2.getCursorScreenPosition()).toEqual([0, 2]); - expect(editor3.getPath()).toBe(firstDirectory.resolve('b')); - expect(editor4.getPath()).toBe( - firstDirectory.resolve('../sample.js') - ); - expect(editor4.getCursorScreenPosition()).toEqual([2, 4]); - expect(untitledEditor.getPath()).toBeUndefined(); - expect(untitledEditor.getText()).toBe('An untitled editor.'); + pane4.getActiveItem().setCursorScreenPosition([0, 2]); + pane2.activate(); - expect(atom.workspace.getActiveTextEditor().getPath()).toBe( - editor3.getPath() - ); - const pathEscaped = fs.tildify( - escapeStringRegex(atom.project.getPaths()[0]) - ); - expect(document.title).toMatch( - new RegExp( - `^${path.basename(editor3.getLongTitle())} \\u2014 ${pathEscaped}` - ) - ); - }); + await simulateReload(); + + expect(atom.workspace.getTextEditors().length).toBe(5); + const [ + editor1, + editor2, + untitledEditor, + editor3, + editor4 + ] = atom.workspace.getTextEditors(); + const firstDirectory = atom.project.getDirectories()[0]; + expect(firstDirectory).toBeDefined(); + expect(editor1.getPath()).toBe(firstDirectory.resolve('b')); + expect(editor2.getPath()).toBe( + firstDirectory.resolve('../sample.txt') + ); + expect(editor2.getCursorScreenPosition()).toEqual([0, 2]); + expect(editor3.getPath()).toBe(firstDirectory.resolve('b')); + expect(editor4.getPath()).toBe( + firstDirectory.resolve('../sample.js') + ); + expect(editor4.getCursorScreenPosition()).toEqual([2, 4]); + expect(untitledEditor.getPath()).toBeUndefined(); + expect(untitledEditor.getText()).toBe('An untitled editor.'); + + expect(atom.workspace.getActiveTextEditor().getPath()).toBe( + editor3.getPath() + ); + const pathEscaped = fs.tildify( + escapeStringRegex(atom.project.getPaths()[0]) + ); + expect(document.title).toMatch( + new RegExp( + `^${path.basename(editor3.getLongTitle())} \\u2014 ${pathEscaped}` + ) + ); }); }); @@ -1948,13 +1936,12 @@ describe('Workspace', () => { it('invokes the observer when closing the one and only text editor after deserialization', async () => { pane.activateItem(new TextEditor()); - simulateReload(); + await simulateReload(); + + workspace.onDidChangeActiveTextEditor(editor => observed.push(editor)); + workspace.closeActivePaneItemOrEmptyPaneOrWindow(); + expect(observed).toEqual([undefined]); - runs(() => { - workspace.onDidChangeActiveTextEditor(editor => observed.push(editor)); - workspace.closeActivePaneItemOrEmptyPaneOrWindow(); - expect(observed).toEqual([undefined]); - }); }); }); @@ -2027,14 +2014,11 @@ describe('Workspace', () => { 'source.coffee', 'source.js', // Tree-sitter grammars also load 'source.js', - 'source.js', - 'source.js.regexp', 'source.js.regexp', 'source.js.regexp', 'source.js.regexp.replacement', 'source.jsdoc', 'source.jsdoc', - 'source.jsdoc', 'source.litcoffee', 'text.plain.null-grammar', 'text.todo',