From 7e22796255c7a7ed09c35720e6cfacfb6f474156 Mon Sep 17 00:00:00 2001 From: Alhadis Date: Mon, 26 Jun 2017 22:23:47 +1000 Subject: [PATCH] Accommodate asynchronous editor saving References: file-icons/atom#615 --- test/4.5-hashbang.js | 4 ++-- test/spec-utils.js | 21 +++++++++++---------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/test/4.5-hashbang.js b/test/4.5-hashbang.js index e2110126..45f139eb 100644 --- a/test/4.5-hashbang.js +++ b/test/4.5-hashbang.js @@ -163,8 +163,8 @@ describe("Interpreter directives", () => { afterEach(() => open("crystal").then(ed => { if(editor){ editor.revertToCheckpoint(checkpoint); - editor.save(); - atom.commands.dispatch(ed.editorElement, "core:close"); + (editor.save() || Promise.resolve()).then(() => + atom.commands.dispatch(ed.editorElement, "core:close")); } })); diff --git a/test/spec-utils.js b/test/spec-utils.js index db4bdd81..1836e705 100644 --- a/test/spec-utils.js +++ b/test/spec-utils.js @@ -131,16 +131,17 @@ function open(path){ */ function replaceText(find, replace){ return new Promise(resolve => { + const handler = () => {resolve(); done.dispose()}; const editor = atom.workspace.getActiveTextEditor(); - const done = editor.onDidStopChanging(() => { - resolve(); - done.dispose(); - }); + const done = editor.onDidStopChanging(handler); editor.transact(100, () => { editor.scan(find, args => args.replace(replace)); }); - editor.save(); + const saveResult = editor.save(); + if(saveResult && saveResult instanceof Promise) + saveResult.then(handler); }) + .then(() => wait(100)) .then(() => TreeView.refreshHack()); } @@ -185,14 +186,14 @@ function resolvePath(path){ */ function revert(steps = 1){ return new Promise(resolve => { + const handler = () => {resolve(); done.dispose()}; const editor = atom.workspace.getActiveTextEditor(); - const done = editor.onDidStopChanging(() => { - resolve(); - done.dispose(); - }); + const done = editor.onDidStopChanging(handler); for(let i = 0; i < steps; ++i) editor.undo(); - editor.save(); + const saved = editor.save(); + if(saved && saved instanceof Promise) + handler.call(); }) .then(() => TreeView.refreshHack()); }