Skip to content

Commit aa5d6b1

Browse files
mradaviHangLe
authored andcommitted
Delete fixtures between tests
1 parent 6105df4 commit aa5d6b1

File tree

8 files changed

+33
-9
lines changed

8 files changed

+33
-9
lines changed

swift_browser_ui_frontend/cypress.config.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const { defineConfig } = require("cypress");
22
const { cloudPlugin } = require("cypress-cloud/plugin");
33
const { Client } = require("pg");
44
const { spawn } = require("node:child_process");
5+
const { rmdir, existsSync } = require("fs");
56

67
module.exports = defineConfig({
78
fixturesFolder: "../tests/cypress/fixtures",
@@ -61,6 +62,14 @@ module.exports = defineConfig({
6162
});
6263
return null;
6364
},
65+
deleteFolder(folder) {
66+
if (existsSync(folder)) {
67+
rmdir(folder, { recursive: true }, (err) => {
68+
if (err) console.error(err);
69+
});
70+
}
71+
return null;
72+
},
6473
});
6574
return cloudPlugin(on, config);
6675
},
@@ -72,6 +81,7 @@ module.exports = defineConfig({
7281
experimentalStudio: true,
7382
textFileLocation: "../tests/cypress/fixtures/text-files/",
7483
downloadsFolder: "../tests/cypress/fixtures/downloads/",
84+
trashAssetsBeforeRuns: true,
7585
},
7686
env: {
7787
username: "swift",

swift_browser_ui_frontend/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"name": "swift_browser_ui_frontend_npm",
33
"version": "2.0.1",
44
"private": true,
5-
"type": "module",
65
"scripts": {
76
"serve": "./build_wasm.sh && vite serve --mode development",
87
"build": "./build_wasm.sh && vite build --mode production",

tests/cypress/integration/download.cy.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ describe("Downloads file/container, verifies content and checksum", function ()
88
const fileName = Math.random().toString(36).substring(2, 7);
99

1010
beforeEach(() => {
11+
cy.deleteFixtures();
1112
cy.task("resetDB");
1213
cy.deleteDB();
1314
cy.visit(Cypress.config("baseUrl"));

tests/cypress/integration/sharing.cy.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
describe("A folder is shared from project A to project B", function () {
22
beforeEach(() => {
3+
cy.deleteFixtures();
34
cy.task("resetDB");
45
cy.deleteDB();
56
cy.visit(Cypress.config().baseUrl);

tests/cypress/integration/table-sharing.cy.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
describe("User can share folder from container table", function () {
22
beforeEach(() => {
3+
cy.deleteFixtures();
34
cy.task("resetDB");
45
cy.deleteDB();
56
cy.visit(Cypress.config().baseUrl);

tests/cypress/integration/upload.cy.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ describe("Upload a file", function () {
77
const fileLocation = Cypress.config("textFileLocation");
88

99
beforeEach(() => {
10+
cy.deleteFixtures();
1011
cy.task("resetDB");
1112
cy.deleteDB();
1213
cy.visit(Cypress.config("baseUrl"));

tests/cypress/support/commands.js

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,25 @@ Cypress.Commands.add("removeAllTags", () => {
284284
cy.get("[data-testid='save-edit-tags']").click();
285285
});
286286

287+
/* FIXTURES */
288+
289+
Cypress.Commands.add("generateFixture", (name) => {
290+
cy.writeFile(Cypress.config("textFileLocation") + name + ".txt", {
291+
hits: Cypress._.times(10, () => {
292+
return faker.lorem.paragraphs(50);
293+
}),
294+
});
295+
});
296+
297+
Cypress.Commands.add("deleteFixtures", () => {
298+
//add command because config allows assets to be trashed with "cypress run"
299+
//but not "cypress open"
300+
const downloaded = Cypress.config("downloadsFolder");
301+
const generated = Cypress.config("textFileLocation");
302+
cy.task("deleteFolder", downloaded);
303+
cy.task("deleteFolder", generated);
304+
})
305+
287306
/*OTHER */
288307

289308
Cypress.Commands.add("getFileContentFromOPFS", async (fileName) => {
@@ -294,14 +313,6 @@ Cypress.Commands.add("getFileContentFromOPFS", async (fileName) => {
294313
return file.text();
295314
})
296315

297-
Cypress.Commands.add("generateFixture", (name) => {
298-
cy.writeFile(Cypress.config("textFileLocation") + name + ".txt", {
299-
hits: Cypress._.times(10, () => {
300-
return faker.lorem.paragraphs(50);
301-
}),
302-
});
303-
});
304-
305316
Cypress.Commands.add("deleteDB", () => {
306317
indexedDB.deleteDatabase("sd-connect");
307318
});

0 commit comments

Comments
 (0)