diff --git a/src/index.html b/src/index.html index 136ec1f45..a804594e2 100644 --- a/src/index.html +++ b/src/index.html @@ -173,8 +173,10 @@ // this means that we are loaded in an iframe in the specrunner. Electron doesnt expose APIs // in its iframes, so we directly use the top most windows electron api objects for tests to run properly. console.warn("Phoenix is loaded in iframe, attempting to use electron APIs from window.top"); + window.__ELECTRON__ = true; window.electronAppAPI = window.top.window.electronAppAPI; window.electronFSAPI = window.top.window.electronFSAPI; + window.electronAPI = window.top.window.electronAPI; } if(window.__TAURI__ || window.__ELECTRON__) { window.__IS_NATIVE_SHELL__ = true; diff --git a/test/SpecRunner.html b/test/SpecRunner.html index 9d910e9be..1665f48c2 100644 --- a/test/SpecRunner.html +++ b/test/SpecRunner.html @@ -207,6 +207,17 @@ }); } setupElectronBootVars(); + // F12 to toggle dev tools in Electron + document.addEventListener('keydown', function(e) { + if (e.key === 'F12') { + e.preventDefault(); + window.electronAPI.toggleDevTools(); + } + if (e.key === 'F5') { + e.preventDefault(); + location.reload(); + } + }); } diff --git a/test/UnitTestReporter.js b/test/UnitTestReporter.js index 995b62306..9894b543d 100644 --- a/test/UnitTestReporter.js +++ b/test/UnitTestReporter.js @@ -65,18 +65,38 @@ define(function (require, exports, module) { return ''; } + function hasCliFlag(args, flagName, shortFlag) { + return args.some(arg => + arg === `--${flagName}` || + arg.startsWith(`--${flagName}=`) || + (shortFlag && arg === `-${shortFlag}`) + ); + } + function quitIfNeeded(exitStatus) { - if(!window.__TAURI__){ + const isTauri = !!window.__TAURI__; + const isElectron = !!window.electronAppAPI?.isElectron; + + if (!isTauri && !isElectron) { return; } + const WAIT_TIME_TO_COMPLETE_TEST_LOGGING_SEC = 10; console.log("Scheduled Quit in Seconds: ", WAIT_TIME_TO_COMPLETE_TEST_LOGGING_SEC); - setTimeout(()=>{ - window.__TAURI__.cli.getMatches().then(matches=>{ - if(matches && matches.args["quit-when-done"] && matches.args["quit-when-done"].occurrences) { - window.__TAURI__.process.exit(exitStatus); - } - }); + setTimeout(() => { + if (isTauri) { + window.__TAURI__.cli.getMatches().then(matches => { + if (matches && matches.args["quit-when-done"] && matches.args["quit-when-done"].occurrences) { + window.__TAURI__.process.exit(exitStatus); + } + }); + } else if (isElectron) { + window.electronAppAPI.getCliArgs().then(args => { + if (hasCliFlag(args, 'quit-when-done', 'q')) { + window.electronAppAPI.quitApp(exitStatus); + } + }); + } }, WAIT_TIME_TO_COMPLETE_TEST_LOGGING_SEC * 1000); } diff --git a/test/index-dist-test.html b/test/index-dist-test.html index b0390820b..63dbe9ba7 100644 --- a/test/index-dist-test.html +++ b/test/index-dist-test.html @@ -4,20 +4,48 @@ Starting tests... diff --git a/test/spec/ExtensionInstallation-test.js b/test/spec/ExtensionInstallation-test.js index 8c91e42ca..b8d2120ba 100644 --- a/test/spec/ExtensionInstallation-test.js +++ b/test/spec/ExtensionInstallation-test.js @@ -31,7 +31,8 @@ define(function (require, exports, module) { const testFilePath = SpecRunnerUtils.getTestPath("/spec/extension-test-files"); - const tempDirectory = window.__TAURI__ ? Phoenix.VFS.getTauriAssetServeDir() + "tests": SpecRunnerUtils.getTempDirectory(); + const tempDirectory = Phoenix.isNativeApp ? + Phoenix.VFS.getTauriAssetServeDir() + "tests": SpecRunnerUtils.getTempDirectory(); const extensionsRoot = tempDirectory + "/extensions"; const basicValidSrc = testFilePath + "/basic-valid-extension.zip", @@ -79,7 +80,7 @@ define(function (require, exports, module) { beforeAll(async function () { await SpecRunnerUtils.ensureExistsDirAsync(tempDirectory); - if(window.__TAURI__){ + if(Phoenix.isNativeApp){ basicValid = tempDirectory + "/basic-valid-extension.zip"; missingNameVersion = tempDirectory + "/missing-name-version.zip"; missingNameVersion = tempDirectory + "/missing-name-version.zip"; diff --git a/test/spec/ExtensionLoader-test.js b/test/spec/ExtensionLoader-test.js index 0b06581e3..291b3efed 100644 --- a/test/spec/ExtensionLoader-test.js +++ b/test/spec/ExtensionLoader-test.js @@ -32,7 +32,7 @@ define(function (require, exports, module) { SpecRunnerUtils = require("spec/SpecRunnerUtils"); const testPathSrc = SpecRunnerUtils.getTestPath("/spec/ExtensionLoader-test-files"); - const testPath = window.__TAURI__ ? Phoenix.VFS.getTauriAssetServeDir() + "tests": SpecRunnerUtils.getTempDirectory(); + const testPath = Phoenix.isNativeApp ? Phoenix.VFS.getTauriAssetServeDir() + "tests": SpecRunnerUtils.getTempDirectory(); describe("ExtensionLoader", function () { diff --git a/test/spec/ExtensionManager-test.js b/test/spec/ExtensionManager-test.js index 722982895..2571c3328 100644 --- a/test/spec/ExtensionManager-test.js +++ b/test/spec/ExtensionManager-test.js @@ -49,7 +49,7 @@ define(function (require, exports, module) { mockExtensionList = require("text!spec/ExtensionManager-test-files/mockExtensionList.json"), mockRegistry; - const testPath = window.__TAURI__ ? + const testPath = Phoenix.isNativeApp ? Phoenix.VFS.getTauriAssetServeDir() + "tests" : SpecRunnerUtils.getTempDirectory(); const testSrc = SpecRunnerUtils.getTestPath("/spec/ExtensionManager-test-files"); @@ -808,6 +808,12 @@ define(function (require, exports, module) { }); }); + afterEach(function () { + // Clean up any lingering dialogs + Dialogs.cancelModalDialogIfOpen("install-extension-dialog"); + $(".modal-wrapper").remove(); + }); + it("should set flag to keep local files for new installs", async function () { var filename = "/path/to/downloaded/file.zip", file = FileSystem.getFileForPath(filename), diff --git a/test/spec/LowLevelFileIO-test.js b/test/spec/LowLevelFileIO-test.js index 5fe7063fd..3ec05e1cf 100644 --- a/test/spec/LowLevelFileIO-test.js +++ b/test/spec/LowLevelFileIO-test.js @@ -797,7 +797,7 @@ define(function (require, exports, module) { describe("specialDirectories", function () { it("should have an application support directory", async function () { // these tests are here as these are absolute unchanging dir convention used by phoenix. - if(window.__TAURI__){ + if(Phoenix.isNativeApp){ const appSupportDIR = window.fs.getTauriVirtualPath(window._tauriBootVars.appLocalDir); expect(brackets.app.getApplicationSupportDirectory().startsWith("/tauri/")).toBeTrue(); expect(brackets.app.getApplicationSupportDirectory()).toBe(appSupportDIR); @@ -807,7 +807,7 @@ define(function (require, exports, module) { }); it("should have a user documents directory", function () { // these tests are here as these are absolute unchanging dir convention used by phoenix. - if(window.__TAURI__){ + if(Phoenix.isNativeApp){ const documentsDIR = window.fs.getTauriVirtualPath(window._tauriBootVars.documentDir); expect(brackets.app.getUserDocumentsDirectory().startsWith("/tauri/")).toBeTrue(); expect(brackets.app.getUserDocumentsDirectory()).toBe(documentsDIR); @@ -817,7 +817,7 @@ define(function (require, exports, module) { }); it("should have a user projects directory", function () { // these tests are here as these are absolute unchanging dir convention used by phoenix. - if(window.__TAURI__){ + if(Phoenix.isNativeApp){ const documentsDIR = window.fs.getTauriVirtualPath(window._tauriBootVars.documentDir); const appName = window._tauriBootVars.appname; const userProjectsDir = `${documentsDIR}${appName}/`; @@ -829,7 +829,7 @@ define(function (require, exports, module) { }); it("should have a temp directory", function () { // these tests are here as these are absolute unchanging dir convention used by phoenix. - if(window.__TAURI__){ + if(Phoenix.isNativeApp){ let tempDIR = window.fs.getTauriVirtualPath(window._tauriBootVars.tempDir); if(!tempDIR.endsWith("/")){ tempDIR = `${tempDIR}/`; @@ -844,7 +844,7 @@ define(function (require, exports, module) { }); it("should have extensions directory", function () { // these tests are here as these are absolute unchanging dir convention used by phoenix. - if(window.__TAURI__){ + if(Phoenix.isNativeApp){ const appSupportDIR = window.fs.getTauriVirtualPath(window._tauriBootVars.appLocalDir); const extensionsDir = `${appSupportDIR}assets/extensions/`; expect(brackets.app.getExtensionsDirectory().startsWith("/tauri/")).toBeTrue(); @@ -855,7 +855,7 @@ define(function (require, exports, module) { }); it("should get virtual serving directory from virtual serving URL in browser", async function () { - if(window.__TAURI__){ + if(Phoenix.isNativeApp){ return; } expect(brackets.VFS.getPathForVirtualServingURL(`${window.fsServerUrl}blinker`)).toBe("/blinker"); @@ -866,7 +866,7 @@ define(function (require, exports, module) { }); it("should not get virtual serving directory from virtual serving URL in tauri", async function () { - if(!window.__TAURI__){ + if(!Phoenix.isNativeApp){ return; } expect(window.fsServerUrl).not.toBeDefined();