2020-09-24 19:23:23 +00:00
|
|
|
import { Application } from 'spectron';
|
|
|
|
import electronPath from '../../insomnia-app/node_modules/electron';
|
|
|
|
import path from 'path';
|
|
|
|
import * as debug from '../modules/debug';
|
|
|
|
import * as client from '../modules/client';
|
2020-08-20 20:08:47 +00:00
|
|
|
|
|
|
|
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',
|
|
|
|
|
2020-08-24 20:40:40 +00:00
|
|
|
// Run after app-package - mac
|
2020-08-22 05:59:56 +00:00
|
|
|
// path: path.join(__dirname, '../insomnia-app/dist/com.insomnia.app/mac/Insomnia.app/Contents/MacOS/Insomnia'),
|
2020-08-20 20:08:47 +00:00
|
|
|
|
2020-08-24 20:40:40 +00:00
|
|
|
// Run after app-package - Windows
|
|
|
|
// path: path.join(__dirname, '../insomnia-app/dist/com.insomnia.app/win-unpacked/Insomnia.exe'),
|
|
|
|
|
|
|
|
// Run after app-build - mac, Windows, Linux
|
2020-08-20 20:08:47 +00:00
|
|
|
path: electronPath,
|
2020-08-24 22:49:29 +00:00
|
|
|
args: [path.join(__dirname, '../../insomnia-app/build/com.insomnia.app')],
|
2020-08-20 20:08:47 +00:00
|
|
|
|
|
|
|
// Don't ask why, but don't remove chromeDriverArgs
|
|
|
|
// https://github.com/electron-userland/spectron/issues/353#issuecomment-522846725
|
|
|
|
chromeDriverArgs: ['remote-debugging-port=9222'],
|
|
|
|
});
|
2020-08-24 20:40:40 +00:00
|
|
|
await app.start().then(async () => {
|
|
|
|
// Windows spawns two terminal windows when running spectron, and the only workaround
|
|
|
|
// is to focus the window on start.
|
|
|
|
// https://github.com/electron-userland/spectron/issues/60
|
|
|
|
await app.browserWindow.focus();
|
|
|
|
await app.browserWindow.setAlwaysOnTop(true);
|
|
|
|
});
|
2020-08-20 20:08:47 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(async () => {
|
|
|
|
if (app && app.isRunning()) {
|
|
|
|
await app.stop();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows an initial window', async () => {
|
2020-08-24 22:49:29 +00:00
|
|
|
await client.correctlyLaunched(app);
|
|
|
|
await debug.workspaceDropdownExists(app);
|
2020-08-20 20:08:47 +00:00
|
|
|
});
|
|
|
|
|
2020-09-23 22:49:25 +00:00
|
|
|
it('sends JSON request', async () => {
|
|
|
|
const url = 'http://127.0.0.1:4010/pets/1';
|
2020-08-24 22:13:29 +00:00
|
|
|
|
2020-09-23 22:49:25 +00:00
|
|
|
await debug.workspaceDropdownExists(app);
|
|
|
|
await debug.createNewRequest(app, 'json');
|
|
|
|
await debug.typeInUrlBar(app, url);
|
2020-09-17 18:05:53 +00:00
|
|
|
await debug.clickSendRequest(app);
|
2020-08-24 22:13:29 +00:00
|
|
|
|
2020-09-17 18:05:53 +00:00
|
|
|
await debug.expect200(app);
|
|
|
|
});
|
2020-08-24 22:13:29 +00:00
|
|
|
|
2020-09-17 18:05:53 +00:00
|
|
|
it('sends CSV request and shows rich response', async () => {
|
2020-09-23 22:49:25 +00:00
|
|
|
const url = 'http://127.0.0.1:4010/csv';
|
|
|
|
|
2020-09-17 18:05:53 +00:00
|
|
|
await debug.workspaceDropdownExists(app);
|
2020-09-23 22:49:25 +00:00
|
|
|
await debug.createNewRequest(app, 'csv');
|
|
|
|
await debug.typeInUrlBar(app, url);
|
2020-09-17 18:05:53 +00:00
|
|
|
await debug.clickSendRequest(app);
|
2020-08-24 22:13:29 +00:00
|
|
|
|
2020-09-17 18:05:53 +00:00
|
|
|
await debug.expect200(app);
|
|
|
|
const csvViewer = await debug.getCsvViewer(app);
|
|
|
|
await expect(csvViewer.getText()).resolves.toBe('a b c\n1 2 3');
|
2020-08-24 22:13:29 +00:00
|
|
|
});
|
2020-09-21 08:45:36 +00:00
|
|
|
|
|
|
|
it('sends PDF request and shows rich response', async () => {
|
|
|
|
// Cannot mock the pdf response using Prism because it is not yet supported
|
|
|
|
// https://github.com/stoplightio/prism/issues/1248#issuecomment-646056440
|
2020-09-23 22:49:25 +00:00
|
|
|
const url = 'https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf';
|
|
|
|
|
2020-09-21 08:45:36 +00:00
|
|
|
await debug.workspaceDropdownExists(app);
|
2020-09-23 22:49:25 +00:00
|
|
|
await debug.createNewRequest(app, 'pdf');
|
|
|
|
await debug.typeInUrlBar(app, url);
|
2020-09-21 08:45:36 +00:00
|
|
|
await debug.clickSendRequest(app);
|
|
|
|
|
|
|
|
await debug.expect200(app);
|
|
|
|
const pdfCanvas = await debug.getPdfCanvas(app);
|
|
|
|
// Investigate how we can extract text from the canvas, or compare images
|
|
|
|
await expect(pdfCanvas.isExisting()).resolves.toBe(true);
|
|
|
|
});
|
2020-08-20 20:08:47 +00:00
|
|
|
});
|