diff --git a/packages/insomnia-app/scripts/build.js b/packages/insomnia-app/scripts/build.js index 9905d362396..cd93a1ba1dd 100644 --- a/packages/insomnia-app/scripts/build.js +++ b/packages/insomnia-app/scripts/build.js @@ -270,7 +270,8 @@ function getBuildContext() { } = process.env; const gitCommit = GITHUB_SHA || TRAVIS_COMMIT; - const gitRef = GIT_TAG || GITHUB_REF || TRAVIS_TAG || TRAVIS_CURRENT_BRANCH || ''; + const gitRef = + GIT_TAG || GITHUB_REF || TRAVIS_TAG || TRAVIS_CURRENT_BRANCH || 'designer@2020.4.0-beta.4'; const tagMatch = gitRef.match(/(designer|core)@(\d{4}\.\d+\.\d+(-(alpha|beta)\.\d+)?)$/); const app = tagMatch ? tagMatch[1] : null; diff --git a/packages/insomnia-smoke-test/core/app.test.js b/packages/insomnia-smoke-test/core/app.test.js new file mode 100644 index 00000000000..32e3dc6437e --- /dev/null +++ b/packages/insomnia-smoke-test/core/app.test.js @@ -0,0 +1,94 @@ +const Application = require('spectron').Application; +// const fs = require('fs'); +const electronPath = require('../../insomnia-app/node_modules/electron'); +const path = require('path'); +const debug = require('../modules/debug'); +const client = require('../modules/client'); + +describe('Application launch', function() { + jest.setTimeout(50000); + let app = null; + + beforeEach(async () => { + app = new Application({ + // Run installed app + // path: '/Applications/Insomnia.app/Contents/MacOS/Insomnia', + + // Run after app-package + // path: path.join(__dirname, '../../insomnia-app/dist/com.insomnia.app/mac/Insomnia.app/Contents/MacOS/Insomnia'), + + // Run after app-build + path: electronPath, + args: [path.join(__dirname, '../../insomnia-app/build/com.insomnia.app')], + + // Don't ask why, but don't remove chromeDriverArgs + // https://github.com/electron-userland/spectron/issues/353#issuecomment-522846725 + chromeDriverArgs: ['remote-debugging-port=9222'], + }); + await app.start(); + }); + + afterEach(async () => { + if (app && app.isRunning()) { + await app.stop(); + } + }); + + it('shows an initial window', async () => { + await client.correctlyLaunched(app); + await debug.workspaceDropdownExists(app); + }); + + it('create and send a request', async () => { + await debug.workspaceDropdownExists(app); + + // Create a new request + await app.client.$('.sidebar .dropdown .fa-plus-circle').then(e => e.click()); + + await app.client + .$('[aria-hidden=false]') + .then(e => e.$('button*=New Request')) + .then(e => e.click()); + + // Wait for modal to open + await app.client.waitUntilTextExists('.modal__header', 'New Request'); + + // Set name and create request + const input = await app.client.$('.modal input'); + await input.waitUntil(() => input.isFocused()); + const requestName = 'Request from test'; + await input.keys(requestName); + + await app.client + .$('.modal .modal__footer') + .then(e => e.$('button=Create')) + .then(e => e.click()); + + // Ensure first item is the one we created and is selected + const requests = await app.client.$$('.sidebar__item'); + const firstRequest = requests[0]; + const firstRequestName = await firstRequest.$('span.editable').then(e => e.getText()); + const firstRequestClasses = await firstRequest.getAttribute('class'); + + expect(firstRequestName).toBe(requestName); + expect(firstRequestClasses).toContain('sidebar__item--active'); + + // Type into url bar + const urlEditor = await app.client.$('.urlbar .editor'); + await urlEditor.click(); + await urlEditor.keys('https://petstore.swagger.io/v2/pet/findByStatus?status=available'); + + // Send request + await app.client.$('.urlbar__send-btn').then(e => e.click()); + + // Expect 200 + await app.client + .$('.response-pane .pane__header .tag.bg-success') + .then(e => e.getText()) + .then(e => expect(e).toBe('200 OK')); + + // await app.browserWindow.capturePage().then(function(imageBuffer) { + // fs.writeFileSync('page.png', imageBuffer); + // }); + }); +}); diff --git a/packages/insomnia-smoke-test/designer/app.test.js b/packages/insomnia-smoke-test/designer/app.test.js new file mode 100644 index 00000000000..66a22f8d23b --- /dev/null +++ b/packages/insomnia-smoke-test/designer/app.test.js @@ -0,0 +1,48 @@ +const onboarding = require('../modules/onboarding'); +const client = require('../modules/client'); +const home = require('../modules/home'); + +const Application = require('spectron').Application; +const electronPath = require('../../insomnia-app/node_modules/electron'); +const path = require('path'); + +describe('Application launch', function() { + jest.setTimeout(50000); + let app = null; + + beforeEach(async () => { + app = new Application({ + // Run installed app + // path: '/Applications/Insomnia.app/Contents/MacOS/Insomnia', + + // Run after app-package + // path: path.join(__dirname, '../../insomnia-app/dist/com.insomnia.app/mac/Insomnia.app/Contents/MacOS/Insomnia'), + + // Run after app-build + path: electronPath, + args: [path.join(__dirname, '../../insomnia-app/build/com.insomnia.designer')], + + // Don't ask why, but don't remove chromeDriverArgs + // https://github.com/electron-userland/spectron/issues/353#issuecomment-522846725 + chromeDriverArgs: ['remote-debugging-port=9222'], + }); + await app.start(); + }); + + afterEach(async () => { + if (app && app.isRunning()) { + await app.stop(); + } + }); + + it('can reset to and proceed through onboarding flow', async () => { + await client.correctlyLaunched(app); + await client.resetToOnboarding(app); + + await onboarding.welcomeMessageShown(app); + await onboarding.clickDontShare(app); + await onboarding.clickSkipImport(app); + + await home.documentListingShown(app); + }); +}); diff --git a/packages/insomnia-smoke-test/modules/client.js b/packages/insomnia-smoke-test/modules/client.js new file mode 100644 index 00000000000..06b09f2b19c --- /dev/null +++ b/packages/insomnia-smoke-test/modules/client.js @@ -0,0 +1,16 @@ +const correctlyLaunched = async app => { + await expect(app.browserWindow.isDevToolsOpened()).resolves.toBe(false); + await expect(app.client.getWindowCount()).resolves.toBe(1); + await expect(app.browserWindow.isMinimized()).resolves.toBe(false); + await expect(app.browserWindow.isFocused()).resolves.toBe(true); +}; + +const resetToOnboarding = async app => { + await app.webContents.executeJavaScript("localStorage['insomnia::meta::activity'] = null;"); + await app.browserWindow.reload(); // reload for local storage clearing to take effect +}; + +module.exports = { + correctlyLaunched, + resetToOnboarding, +}; diff --git a/packages/insomnia-smoke-test/modules/debug.js b/packages/insomnia-smoke-test/modules/debug.js new file mode 100644 index 00000000000..23a8e4f4cb7 --- /dev/null +++ b/packages/insomnia-smoke-test/modules/debug.js @@ -0,0 +1,7 @@ +const workspaceDropdownExists = async (app, workspaceName = 'Insomnia') => { + await app.client.waitUntilTextExists('.workspace-dropdown', workspaceName); +}; + +module.exports = { + workspaceDropdownExists, +}; diff --git a/packages/insomnia-smoke-test/modules/home.js b/packages/insomnia-smoke-test/modules/home.js new file mode 100644 index 00000000000..6a2ff7e5512 --- /dev/null +++ b/packages/insomnia-smoke-test/modules/home.js @@ -0,0 +1,8 @@ +const documentListingShown = async app => { + const item = await app.client.$('.document-listing'); + await item.waitForExist(); +}; + +module.exports = { + documentListingShown, +}; diff --git a/packages/insomnia-smoke-test/modules/onboarding.js b/packages/insomnia-smoke-test/modules/onboarding.js new file mode 100644 index 00000000000..07a32651a7d --- /dev/null +++ b/packages/insomnia-smoke-test/modules/onboarding.js @@ -0,0 +1,26 @@ +const welcomeMessageShown = async app => { + await app.client.waitUntilTextExists( + '.onboarding__content__header h1', + 'Welcome to Insomnia Designer', + ); +}; + +const clickDontShare = async app => { + await app.client + .$('.onboarding__content__body') + .then(e => e.$(`button=Don't share usage analytics`)) + .then(e => e.click()); +}; + +const clickSkipImport = async app => { + await app.client + .$('.onboarding__content__body') + .then(e => e.$(`button=Skip`)) + .then(e => e.click()); +}; + +module.exports = { + welcomeMessageShown, + clickDontShare, + clickSkipImport, +}; diff --git a/packages/insomnia-smoke-test/package.json b/packages/insomnia-smoke-test/package.json index 8ec258a9625..4f4b7ae9b54 100644 --- a/packages/insomnia-smoke-test/package.json +++ b/packages/insomnia-smoke-test/package.json @@ -2,7 +2,8 @@ "name": "insomnia-smoke-test", "version": "1.0.0", "scripts": { - "test:build:core": "jest", + "test:build:core": "jest --testPathPattern core", + "test:build:designer": "jest --testPathPattern designer", "test:package:core": "cross-env PACKAGE=Insomnia jest" }, "devDependencies": { diff --git a/packages/insomnia-smoke-test/spec.js b/packages/insomnia-smoke-test/spec.js deleted file mode 100644 index f1675ea5a02..00000000000 --- a/packages/insomnia-smoke-test/spec.js +++ /dev/null @@ -1,95 +0,0 @@ -const Application = require('spectron').Application; -// const fs = require('fs'); -const electronPath = require('../insomnia-app/node_modules/electron'); -const path = require('path'); - -describe('Application launch', function() { - jest.setTimeout(50000); - let app = null; - - beforeEach(async () => { - app = new Application({ - // Run installed app - // path: '/Applications/Insomnia.app/Contents/MacOS/Insomnia', - - // Run after app-package - // path: path.join(__dirname, '../insomnia-app/dist/com.insomnia.app/mac/Insomnia.app/Contents/MacOS/Insomnia'), - - // Run after app-build - path: electronPath, - args: [path.join(__dirname, '../insomnia-app/build/com.insomnia.app')], - - // Don't ask why, but don't remove chromeDriverArgs - // https://github.com/electron-userland/spectron/issues/353#issuecomment-522846725 - chromeDriverArgs: ['remote-debugging-port=9222'], - }); - await app.start(); - }); - - afterEach(async () => { - if (app && app.isRunning()) { - await app.stop(); - } - }); - - it('shows an initial window', async () => { - await expect(app.browserWindow.isDevToolsOpened()).resolves.toBe(false); - await expect(app.client.getWindowCount()).resolves.toBe(1); - await expect(app.browserWindow.isMinimized()).resolves.toBe(false); - await expect(app.browserWindow.isFocused()).resolves.toBe(true); - await app.client.waitUntilTextExists('.workspace-dropdown', 'Insomnia'); - }); - - // it('create and send a request', async () => { - // await app.client.waitUntilTextExists('.workspace-dropdown', 'Insomnia'); - // - // // Create a new request - // await app.client.$('.sidebar .dropdown .fa-plus-circle').then(e => e.click()); - // - // await app.client - // .$('[aria-hidden=false]') - // .then(e => e.$('button*=New Request')) - // .then(e => e.click()); - // - // // Wait for modal to open - // await app.client.waitUntilTextExists('.modal__header', 'New Request'); - // - // // Set name and create request - // const input = await app.client.$('.modal input'); - // await app.client.waitUntil(() => input.isFocused()); - // const requestName = 'Request from test'; - // await input.keys(requestName); - // - // await app.client - // .$('.modal .modal__footer') - // .then(e => e.$('button=Create')) - // .then(e => e.click()); - // - // // Ensure first item is the one we created and is selected - // const requests = await app.client.$$('.sidebar__item'); - // const firstRequest = requests[0]; - // const firstRequestName = await firstRequest.$('span.editable').then(e => e.getText()); - // const firstRequestClasses = await firstRequest.getAttribute('class'); - // - // expect(firstRequestName).toBe(requestName); - // expect(firstRequestClasses).toContain('sidebar__item--active'); - // - // // Type into url bar - // const urlEditor = await app.client.$('.urlbar .editor'); - // await urlEditor.click(); - // await urlEditor.keys('https://petstore.swagger.io/v2/pet/findByStatus?status=available'); - // - // // Send request - // await app.client.$('.urlbar__send-btn').then(e => e.click()); - // - // // Expect 200 - // await app.client - // .$('.response-pane .pane__header .tag.bg-success') - // .then(e => e.getText()) - // .then(e => expect(e).toBe('200 OK')); - // - // await app.browserWindow.capturePage().then(function(imageBuffer) { - // fs.writeFileSync('page.png', imageBuffer); - // }); - // }); -});