Mock server for e2e tests using Prism (#2544)

Co-authored-by: David Marby <david@dmarby.se>
This commit is contained in:
Opender Singh 2020-08-25 10:13:29 +12:00 committed by GitHub
parent deaded4674
commit 3c345d4be1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 2199 additions and 57 deletions

View File

@ -25,11 +25,10 @@
"storybook-start": "npm run storybook --prefix packages/insomnia-components", "storybook-start": "npm run storybook --prefix packages/insomnia-components",
"storybook-legacy-start": "npm run storybook --prefix packages/insomnia-app", "storybook-legacy-start": "npm run storybook --prefix packages/insomnia-app",
"preinstall": "node ./scripts/check-version.js", "preinstall": "node ./scripts/check-version.js",
"app-build:smoke:core": "cross-env SMOKE_TEST=core npm run app-build", "app-build:smoke:core": "cross-env SMOKE_TEST=core npm run app-build",
"app-build:smoke:designer": "cross-env SMOKE_TEST=designer npm run app-build", "app-build:smoke:designer": "cross-env SMOKE_TEST=designer npm run app-build",
"test:smoke:core": "npm run test:build:core --prefix packages/insomnia-smoke-test", "test:smoke:core": "npm run test:core:build --prefix packages/insomnia-smoke-test",
"test:smoke:designer": "npm run test:build:designer --prefix packages/insomnia-smoke-test", "test:smoke:designer": "npm run test:designer:build --prefix packages/insomnia-smoke-test",
"test:smoke:package": "npm run test:package --prefix packages/insomnia-smoke-test" "test:smoke:package": "npm run test:package --prefix packages/insomnia-smoke-test"
}, },
"lint-staged": { "lint-staged": {

View File

@ -0,0 +1,10 @@
# Insomnia Smoke Tests
```sh
npm install
npm run test:core:build
npm run test:designer:build
npm run test:core:package
npm run test:designer:package
```

File diff suppressed because it is too large Load Diff

View File

@ -1,10 +1,23 @@
{ {
"private": true,
"name": "insomnia-smoke-test", "name": "insomnia-smoke-test",
"version": "1.0.0", "version": "1.0.0",
"scripts": { "scripts": {
"test:build:core": "xvfb-maybe jest" "spectron:core:build": "xvfb-maybe jest",
"spectron:designer:build": "xvfb-maybe jest",
"spectron:core:package": "xvfb-maybe jest",
"spectron:designer:package": "xvfb-maybe jest",
"start:prism": "prism mock prism/petstore.oas3.yaml",
"with-mock": "concurrently --names prism,spectron --success first --kill-others \"npm run start:prism\"",
"test:core:build": "npm run with-mock \"npm run spectron:core:build\"",
"test:designer:build": "npm run with-mock \"npm run spectron:designer:build\"",
"test:core:package": "npm run with-mock \"npm run spectron:core:package\"",
"test:designer:package": "npm run with-mock \"npm run spectron:designer:package\""
}, },
"devDependencies": { "devDependencies": {
"@stoplight/prism-cli": "^3.3.6",
"concurrently": "^5.3.0",
"cross-env": "^7.0.2", "cross-env": "^7.0.2",
"jest": "^26.4.2", "jest": "^26.4.2",
"spectron": "^11.1.0", "spectron": "^11.1.0",

View File

@ -0,0 +1,158 @@
openapi: "3.0.0"
info:
version: 1.0.0
title: Swagger Petstore
description: A sample API that uses a petstore as an example to demonstrate features in the OpenAPI 3.0 specification
termsOfService: http://swagger.io/terms/
contact:
name: Swagger API Team
email: apiteam@swagger.io
url: http://swagger.io
license:
name: Apache 2.0
url: https://www.apache.org/licenses/LICENSE-2.0.html
servers:
- url: http://petstore.swagger.io/api
paths:
/pets:
get:
description: |
Returns all pets from the system that the user has access to
Nam sed condimentum est. Maecenas tempor sagittis sapien, nec rhoncus sem sagittis sit amet. Aenean at gravida augue, ac iaculis sem. Curabitur odio lorem, ornare eget elementum nec, cursus id lectus. Duis mi turpis, pulvinar ac eros ac, tincidunt varius justo. In hac habitasse platea dictumst. Integer at adipiscing ante, a sagittis ligula. Aenean pharetra tempor ante molestie imperdiet. Vivamus id aliquam diam. Cras quis velit non tortor eleifend sagittis. Praesent at enim pharetra urna volutpat venenatis eget eget mauris. In eleifend fermentum facilisis. Praesent enim enim, gravida ac sodales sed, placerat id erat. Suspendisse lacus dolor, consectetur non augue vel, vehicula interdum libero. Morbi euismod sagittis libero sed lacinia.
Sed tempus felis lobortis leo pulvinar rutrum. Nam mattis velit nisl, eu condimentum ligula luctus nec. Phasellus semper velit eget aliquet faucibus. In a mattis elit. Phasellus vel urna viverra, condimentum lorem id, rhoncus nibh. Ut pellentesque posuere elementum. Sed a varius odio. Morbi rhoncus ligula libero, vel eleifend nunc tristique vitae. Fusce et sem dui. Aenean nec scelerisque tortor. Fusce malesuada accumsan magna vel tempus. Quisque mollis felis eu dolor tristique, sit amet auctor felis gravida. Sed libero lorem, molestie sed nisl in, accumsan tempor nisi. Fusce sollicitudin massa ut lacinia mattis. Sed vel eleifend lorem. Pellentesque vitae felis pretium, pulvinar elit eu, euismod sapien.
operationId: findPets
parameters:
- name: tags
in: query
description: tags to filter by
required: false
style: form
schema:
type: array
items:
type: string
- name: limit
in: query
description: maximum number of results to return
required: false
schema:
type: integer
format: int32
responses:
'200':
description: pet response
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Pet'
default:
description: unexpected error
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
post:
description: Creates a new pet in the store. Duplicates are allowed
operationId: addPet
requestBody:
description: Pet to add to the store
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/NewPet'
responses:
'200':
description: pet response
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
default:
description: unexpected error
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
/pets/{id}:
get:
description: Returns a user based on a single ID, if the user does not have access to the pet
operationId: find pet by id
parameters:
- name: id
in: path
description: ID of pet to fetch
required: true
schema:
type: integer
format: int64
responses:
'200':
description: pet response
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
default:
description: unexpected error
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
delete:
description: deletes a single pet based on the ID supplied
operationId: deletePet
parameters:
- name: id
in: path
description: ID of pet to delete
required: true
schema:
type: integer
format: int64
responses:
'204':
description: pet deleted
default:
description: unexpected error
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
components:
schemas:
Pet:
allOf:
- $ref: '#/components/schemas/NewPet'
- type: object
required:
- id
properties:
id:
type: integer
format: int64
NewPet:
type: object
required:
- name
properties:
name:
type: string
tag:
type: string
Error:
type: object
required:
- code
- message
properties:
code:
type: integer
format: int32
message:
type: string

View File

@ -49,56 +49,56 @@ describe('Application launch', function() {
await app.client.waitUntilTextExists('.workspace-dropdown', 'Insomnia'); await app.client.waitUntilTextExists('.workspace-dropdown', 'Insomnia');
}); });
// it('create and send a request', async () => { it('creates and sends a request', async () => {
// await app.client.waitUntilTextExists('.workspace-dropdown', 'Insomnia'); await app.client.waitUntilTextExists('.workspace-dropdown', 'Insomnia');
//
// // Create a new request // Create a new request
// await app.client.$('.sidebar .dropdown .fa-plus-circle').then(e => e.click()); await app.client.$('.sidebar .dropdown .fa-plus-circle').then(e => e.click());
//
// await app.client await app.client
// .$('[aria-hidden=false]') .$('[aria-hidden=false]')
// .then(e => e.$('button*=New Request')) .then(e => e.$('button*=New Request'))
// .then(e => e.click()); .then(e => e.click());
//
// // Wait for modal to open // Wait for modal to open
// await app.client.waitUntilTextExists('.modal__header', 'New Request'); await app.client.waitUntilTextExists('.modal__header', 'New Request');
//
// // Set name and create request // Set name and create request
// const input = await app.client.$('.modal input'); const input = await app.client.$('.modal input');
// await app.client.waitUntil(() => input.isFocused()); await app.client.waitUntil(() => input.isFocused());
// const requestName = 'Request from test'; const requestName = 'Request from test';
// await input.keys(requestName); await input.keys(requestName);
//
// await app.client await app.client
// .$('.modal .modal__footer') .$('.modal .modal__footer')
// .then(e => e.$('button=Create')) .then(e => e.$('button=Create'))
// .then(e => e.click()); .then(e => e.click());
//
// // Ensure first item is the one we created and is selected // Ensure first item is the one we created and is selected
// const requests = await app.client.$$('.sidebar__item'); const requests = await app.client.$$('.sidebar__item');
// const firstRequest = requests[0]; const firstRequest = requests[0];
// const firstRequestName = await firstRequest.$('span.editable').then(e => e.getText()); const firstRequestName = await firstRequest.$('span.editable').then(e => e.getText());
// const firstRequestClasses = await firstRequest.getAttribute('class'); const firstRequestClasses = await firstRequest.getAttribute('class');
//
// expect(firstRequestName).toBe(requestName); expect(firstRequestName).toBe(requestName);
// expect(firstRequestClasses).toContain('sidebar__item--active'); expect(firstRequestClasses).toContain('sidebar__item--active');
//
// // Type into url bar // Type into url bar
// const urlEditor = await app.client.$('.urlbar .editor'); const urlEditor = await app.client.$('.urlbar .editor');
// await urlEditor.click(); await urlEditor.click();
// await urlEditor.keys('https://petstore.swagger.io/v2/pet/findByStatus?status=available'); await urlEditor.keys('http://127.0.0.1:4010/pets/1');
//
// // Send request // Send request
// await app.client.$('.urlbar__send-btn').then(e => e.click()); await app.client.$('.urlbar__send-btn').then(e => e.click());
//
// // Expect 200 // Expect 200
// await app.client await app.client
// .$('.response-pane .pane__header .tag.bg-success') .$('.response-pane .pane__header .tag.bg-success')
// .then(e => e.getText()) .then(e => e.getText())
// .then(e => expect(e).toBe('200 OK')); .then(e => expect(e).toBe('200 OK'));
//
// await app.browserWindow.capturePage().then(function(imageBuffer) { // await app.browserWindow.capturePage().then(function(imageBuffer) {
// fs.writeFileSync('page.png', imageBuffer); // fs.writeFileSync('page.png', imageBuffer);
// }); // });
// }); });
}); });