Skip to content

Commit

Permalink
Add database reset to Cypress test
Browse files Browse the repository at this point in the history
  • Loading branch information
dv297 committed Oct 3, 2022
1 parent b75ad43 commit 48a63cb
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 22 deletions.
Binary file added cypress/downloads/downloads.html
Binary file not shown.
1 change: 1 addition & 0 deletions cypress/e2e/workspace.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import AppPage from '../page/AppPage';

describe('Workspace', () => {
beforeEach(() => {
cy.exec('node scripts/seed-database.js');
// Cypress starts out with a blank slate for each test
// so we must tell it to visit our website with the `cy.visit()` command.
// Since we want to visit the same URL at the start of all our tests,
Expand Down
22 changes: 2 additions & 20 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
/* eslint-disable @typescript-eslint/no-namespace */

import '@testing-library/cypress/add-commands';

Expand All @@ -20,30 +21,11 @@ Cypress.Commands.add('login', () => {
}).should('exist');
});

//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
//

/* eslint-disable @typescript-eslint/no-namespace */

declare global {
namespace Cypress {
interface Chainable {
login(): Chainable<Element>;
databaseReset(): Chainable<Element>;
}
}
}
21 changes: 21 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
"@types/md5": "^2.3.2",
"@types/node": "17.0.14",
"@types/react": "17.0.38",
"@types/shelljs": "^0.8.11",
"@typescript-eslint/eslint-plugin": "^5.36.1",
"@typescript-eslint/parser": "^5.36.1",
"@zeit/next-css": "^1.0.1",
Expand Down
36 changes: 34 additions & 2 deletions scripts/seed-database.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,40 @@ function splitStringByNotQuotedSemicolon(input) {
}

const main = async () => {
shell.exec('npm run db:reset -- --force');
await seedDatabase();
// shell.exec('npm run db:reset -- --force');
const tablesToEmpty = [
'ProjectMapPosition',
'ProjectMapEdgesSet',
'Issue',
'KeyIssue',
'Project',
'TeamWorkspace',
'TeamUsers',
'Team',
'Workspace',
'Account',
'UserPreference',
'User',
];

for (let table of tablesToEmpty) {
try {
console.log(`Deleting table ${table}`);
await prisma[table].deleteMany({ where: {} });
} catch (err) {
console.error(`Error deleting table`);
console.error(err);
}
}
try {
console.log('Seeding database');
await seedDatabase();
} catch (err) {
console.error('Error seeding database');
console.error(err);
}

console.log('Success');
};

main();

1 comment on commit 48a63cb

@vercel
Copy link

@vercel vercel bot commented on 48a63cb Oct 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

planner – ./

planner-git-main-dv297.vercel.app
planner-nine.vercel.app
planner-dv297.vercel.app

Please sign in to comment.