Skip to content

Commit

Permalink
run e2e tests specific to an application
Browse files Browse the repository at this point in the history
  • Loading branch information
develohpanda committed Aug 24, 2020
1 parent c3678d6 commit f0c4aa1
Show file tree
Hide file tree
Showing 9 changed files with 203 additions and 97 deletions.
3 changes: 2 additions & 1 deletion packages/insomnia-app/scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
94 changes: 94 additions & 0 deletions packages/insomnia-smoke-test/core/app.test.js
Original file line number Diff line number Diff line change
@@ -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);
// });
});
});
48 changes: 48 additions & 0 deletions packages/insomnia-smoke-test/designer/app.test.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
16 changes: 16 additions & 0 deletions packages/insomnia-smoke-test/modules/client.js
Original file line number Diff line number Diff line change
@@ -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,
};
7 changes: 7 additions & 0 deletions packages/insomnia-smoke-test/modules/debug.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const workspaceDropdownExists = async (app, workspaceName = 'Insomnia') => {
await app.client.waitUntilTextExists('.workspace-dropdown', workspaceName);
};

module.exports = {
workspaceDropdownExists,
};
8 changes: 8 additions & 0 deletions packages/insomnia-smoke-test/modules/home.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const documentListingShown = async app => {
const item = await app.client.$('.document-listing');
await item.waitForExist();
};

module.exports = {
documentListingShown,
};
26 changes: 26 additions & 0 deletions packages/insomnia-smoke-test/modules/onboarding.js
Original file line number Diff line number Diff line change
@@ -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,
};
3 changes: 2 additions & 1 deletion packages/insomnia-smoke-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
95 changes: 0 additions & 95 deletions packages/insomnia-smoke-test/spec.js

This file was deleted.

0 comments on commit f0c4aa1

Please sign in to comment.