feat: Make use of db:reset in all test suites (no-changelog) (#4739)

* feat: Make use of db:reset in all test suites

* refactor: Rename task to no longer use db: prefix

* feat: wrap cypress tasks into commands

* refactor: rename resetDatabase to resetAll

* fix: update test:e2e:all to use --headless
This commit is contained in:
Alex Grozav 2022-11-28 19:11:33 +02:00 committed by GitHub
parent aac207a947
commit 622118f983
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 71 additions and 35 deletions

View file

@ -11,10 +11,10 @@ module.exports = defineConfig({
experimentalSessionAndOrigin: true,
experimentalInteractiveRunEvents: true,
setupNodeEvents(on) {
setupNodeEvents(on, config) {
on('task', {
'db:reset': () => fetch(BASE_URL + '/e2e/db/reset', { method: 'POST' }),
'db:setup-owner': (payload) =>
'reset': () => fetch(BASE_URL + '/e2e/db/reset', { method: 'POST' }),
'setup-owner': (payload) =>
fetch(BASE_URL + '/e2e/db/setup-owner', {
method: 'POST',
body: JSON.stringify(payload),

View file

@ -8,21 +8,21 @@ const lastName = randLastName();
describe('Authentication', () => {
beforeEach(() => {
cy.task('db:reset');
cy.resetAll();
});
it('should setup owner', () => {
cy.signup(email, firstName, lastName, password);
cy.setup({ email, firstName, lastName, password });
});
it('should sign user in', () => {
cy.task('db:setup-owner', { email, password, firstName, lastName });
cy.setupOwner({ email, password, firstName, lastName });
cy.on('uncaught:exception', (err, runnable) => {
expect(err.message).to.include('Not logged in');
return false;
});
cy.signin(email, password);
cy.signin({ email, password });
});
});

View file

@ -4,7 +4,7 @@ import { WorkflowsPage as WorkflowsPageClass } from '../pages/workflows';
import { WorkflowPage as WorkflowPageClass } from '../pages/workflow';
import { v4 as uuid } from 'uuid';
const username = DEFAULT_USER_EMAIL;
const email = DEFAULT_USER_EMAIL;
const password = DEFAULT_USER_PASSWORD;
const firstName = randFirstName();
const lastName = randLastName();
@ -12,16 +12,19 @@ const WorkflowsPage = new WorkflowsPageClass();
const WorkflowPage = new WorkflowPageClass();
describe('Workflows', () => {
beforeEach(() => {
cy.signup(username, firstName, lastName, password);
before(() => {
cy.resetAll();
cy.setup({ email, firstName, lastName, password });
});
beforeEach(() => {
cy.on('uncaught:exception', (err, runnable) => {
expect(err.message).to.include('Not logged in');
return false;
})
cy.signin(username, password);
cy.signin({ email, password });
cy.visit(WorkflowsPage.url);
});

View file

@ -2,7 +2,7 @@ import { DEFAULT_USER_EMAIL, DEFAULT_USER_PASSWORD } from "../constants";
import { randFirstName, randLastName } from "@ngneat/falso";
import { CredentialsPage, CredentialsModal } from '../pages';
const username = DEFAULT_USER_EMAIL;
const email = DEFAULT_USER_EMAIL;
const password = DEFAULT_USER_PASSWORD;
const firstName = randFirstName();
const lastName = randLastName();
@ -11,20 +11,18 @@ const credentialsModal = new CredentialsModal();
describe('Credentials', () => {
before(() => {
cy.task('db:reset');
Cypress.session.clearAllSavedSessions();
cy.resetAll();
cy.setup({ email, firstName, lastName, password });
});
beforeEach(() => {
cy.signup(username, firstName, lastName, password);
cy.on('uncaught:exception', (err, runnable) => {
expect(err.message).to.include('Not logged in');
return false;
})
cy.signin(username, password);
cy.signin({ email, password });
cy.visit(credentialsPage.url);
});

View file

@ -18,7 +18,7 @@ const settingsUsersPage = new SettingsUsersPage();
const messageBox = new MessageBox();
const username = DEFAULT_USER_EMAIL;
const email = DEFAULT_USER_EMAIL;
const password = DEFAULT_USER_PASSWORD;
const firstName = randFirstName();
const lastName = randLastName();
@ -27,7 +27,7 @@ describe('Default owner', () => {
// todo test should redirect to setup if have not skipped
beforeEach(() => {
cy.task('db:reset');
cy.resetAll();
});
it('should be able to use n8n without user management and setup UM', () => {
@ -83,7 +83,7 @@ describe('Default owner', () => {
});
describe('should be able to setup instance and migrate workflows and credentials', () => {
cy.signup(username, firstName, lastName, password);
cy.setup({ email, firstName, lastName, password });
messageBox.getters.content().should('contain.text', '1 existing workflow and 1 credential')

View file

@ -5,8 +5,8 @@ const WorkflowsPage = new WorkflowsPageClass();
const WorkflowPage = new WorkflowPageClass();
describe('HTTP Request node', () => {
beforeEach(() => {
cy.task('db:reset');
before(() => {
cy.resetAll();
cy.skipSetup();
});

View file

@ -1,15 +1,24 @@
import { NodeCreator } from '../pages/features/node-creator';
import { INodeTypeDescription } from '../../packages/workflow';
import CustomNodeFixture from '../fixtures/Custom_node.json';
import {DEFAULT_USER_EMAIL, DEFAULT_USER_PASSWORD} from "../constants";
import {randFirstName, randLastName} from "@ngneat/falso";
const email = DEFAULT_USER_EMAIL;
const password = DEFAULT_USER_PASSWORD;
const firstName = randFirstName();
const lastName = randLastName();
const nodeCreatorFeature = new NodeCreator();
describe('Node Creator', () => {
before(() => {
cy.task('db:reset');
})
cy.resetAll();
cy.setup({ email, firstName, lastName, password });
});
beforeEach(() => {
cy.signin({ email, password });
cy.intercept('GET', '/types/nodes.json', (req) => {
// Delete caching headers so that we can intercept the request
['etag', 'if-none-match', 'if-modified-since'].forEach(header => {delete req.headers[header]});
@ -21,7 +30,8 @@ describe('Node Creator', () => {
nodes.push(CustomNodeFixture as INodeTypeDescription);
res.send(nodes)
})
}).as('nodesIntercept')
}).as('nodesIntercept');
cy.visit(nodeCreatorFeature.url);
});

View file

@ -6,22 +6,26 @@ const NEW_WORKFLOW_NAME = 'Something else';
const MANUAL_TRIGGER_NODE_NAME = 'Manual Trigger';
const SCHEDULE_TRIGGER_NODE_NAME = 'Schedule Trigger';
const username = DEFAULT_USER_EMAIL;
const email = DEFAULT_USER_EMAIL;
const password = DEFAULT_USER_PASSWORD;
const firstName = randFirstName();
const lastName = randLastName();
const WorkflowPage = new WorkflowPageClass();
describe('Workflow Actions', () => {
before(() => {
cy.resetAll();
cy.setup({ email, firstName, lastName, password });
});
beforeEach(() => {
cy.signup(username, firstName, lastName, password);
cy.on('uncaught:exception', (err, runnable) => {
expect(err.message).to.include('Not logged in');
return false;
})
cy.signin(username, password);
cy.signin({ email, password });
WorkflowPage.actions.visit();
});

View file

@ -52,7 +52,7 @@ Cypress.Commands.add('findChildByTestId', { prevSubject: true }, (subject: Cypre
Cypress.Commands.add(
'signin',
(email, password) => {
({ email, password }) => {
const signinPage = new SigninPage();
const workflowsPage = new WorkflowsPage();
@ -75,8 +75,7 @@ Cypress.Commands.add(
});
});
// todo rename to setup
Cypress.Commands.add('signup', (email, firstName, lastName, password) => {
Cypress.Commands.add('setup', ({ email, firstName, lastName, password }) => {
const signupPage = new SignupPage();
cy.visit(signupPage.url);
@ -120,3 +119,12 @@ Cypress.Commands.add('skipSetup', () => {
});
});
})
Cypress.Commands.add('resetAll', () => {
cy.task('reset');
Cypress.session.clearAllSavedSessions();
});
Cypress.Commands.add('setupOwner', (payload) => {
cy.task('setup-owner', payload);
});

View file

@ -1,16 +1,29 @@
// Load type definitions that come with Cypress module
/// <reference types="cypress" />
interface SigninPayload {
email: string;
password: string;
}
interface SetupPayload {
email: string;
password: string;
firstName: string;
lastName: string;
}
declare global {
namespace Cypress {
interface Chainable {
getByTestId(selector: string, ...args: (Partial<Loggable & Timeoutable & Withinable & Shadow> | undefined)[]): Chainable<JQuery<HTMLElement>>
findChildByTestId(childTestId: string): Chainable<JQuery<HTMLElement>>
createFixtureWorkflow(fixtureKey: string, workflowName: string): void;
signin(email: string, password: string): void;
// todo: rename to setup
signup(email: string, firstName: string, lastName: string, password: string): void;
signin(payload: SigninPayload): void;
setup(payload: SetupPayload): void;
setupOwner(payload: SetupPayload): void;
skipSetup(): void;
resetAll(): void;
}
}
}

View file

@ -30,7 +30,7 @@
"test:e2e:ui": "cross-env E2E_TESTS=true start-server-and-test start http://localhost:5678/favicon.ico 'cypress open'",
"test:e2e:dev": "cross-env E2E_TESTS=true CYPRESS_BASE_URL=http://localhost:8080 start-server-and-test dev http://localhost:8080/favicon.ico 'cypress open'",
"test:e2e:smoke": "cross-env E2E_TESTS=true start-server-and-test start http://localhost:5678/favicon.ico 'cypress run --headless --spec \"cypress/e2e/0-smoke.cy.ts\"'",
"test:e2e:all": "cross-env E2E_TESTS=true start-server-and-test start http://localhost:5678/favicon.ico 'cypress run'"
"test:e2e:all": "cross-env E2E_TESTS=true start-server-and-test start http://localhost:5678/favicon.ico 'cypress run --headless'"
},
"dependencies": {
"n8n": "*"