diff --git a/cypress.config.js b/cypress.config.js index 7ebe9ef4..8b8edd92 100644 --- a/cypress.config.js +++ b/cypress.config.js @@ -1,6 +1,6 @@ import { defineConfig } from 'cypress'; import fs from 'fs'; -import { isFileExist, findFiles } from 'cy-verify-downloads'; +import path from 'path'; export default defineConfig({ projectId: '2ckppp', viewportWidth: 1440, @@ -15,17 +15,19 @@ export default defineConfig({ e2e: { setupNodeEvents(on, config) { on('task', { - isFileExist, - findFiles, - deleteFile(path) { - fs.rmSync(path); - return null; - }, - readFileMaybe(filename) { - if (fs.existsSync(filename)) { - return fs.readFileSync(filename, 'utf8'); + readAndDeleteFile({ fileNamePattern, folder, mode }) { + const fileNameRegex = new RegExp(fileNamePattern); + const files = fs.readdirSync(folder); + const filename = files.find((file) => file.match(fileNameRegex)); + const filePath = path.join(folder, filename); + try { + if (mode === 'size') { + return fs.statSync(filePath).size; + } + return fs.readFileSync(filePath, 'utf8'); + } finally { + fs.rmSync(filePath); } - return null; } }); }, diff --git a/cypress/e2e/actions.spec.ts b/cypress/e2e/actions.spec.ts index 4206f022..24d8d1b1 100644 --- a/cypress/e2e/actions.spec.ts +++ b/cypress/e2e/actions.spec.ts @@ -26,8 +26,6 @@ describe('Check actions', () => { }); it('should download png and svg', () => { - cy.clock(new Date(2022, 0, 1).getTime()); - cy.get(`#downloadPNG`).click(); verifyFileSizeGreaterThan('diagram', 'png', 34_000); @@ -43,7 +41,5 @@ describe('Check actions', () => { cy.get(`#downloadSVG`).click(); verifyFileSizeGreaterThan('diagram', 'svg', 11_000); - - cy.clock().invoke('restore'); }); }); diff --git a/cypress/e2e/diagramUpdate.spec.ts b/cypress/e2e/diagramUpdate.spec.ts index d2ca433c..b8326bc3 100644 --- a/cypress/e2e/diagramUpdate.spec.ts +++ b/cypress/e2e/diagramUpdate.spec.ts @@ -50,6 +50,24 @@ describe('Auto sync tests', () => { cy.getLocalStorage('codeStore').snapshot(); }); + it('should automatically defer rendering when complex diagrams are edited', () => { + cy.get('#view').should('not.have.class', 'outOfSync'); + typeInEditor(` +A & B & C & D & E --> F & G & K & Z & i +A & B & C & D & E --> F & G & K & Z & i +A & B & C & D & E --> F & G & K & Z & i +A & B & C & D & E --> F & G & K & Z & i +A & B & C & D & E --> F & G & K & Z & i +A & B & C & D & E --> F & G & K & Z & i +A & B & C & D & E --> F & G & K & Z & i +A & B & C & D & E --> F & G & K & Z & i +A & B & C & D & E --> F & G & K & Z & i`); + cy.get('#view').should('have.class', 'outOfSync'); + cy.get('#errorContainer').should('contain.text', 'It will be updated automatically.'); + // The class should be removed automatically after 1 second. + cy.get('#view').should('not.have.class', 'outOfSync'); + }); + it('supports commenting code out/in', () => { cy.get('#editor').contains('Car').click(); cy.get('#editor').get('textarea').type(`${cmd}/`, { force: true }); diff --git a/cypress/e2e/util.ts b/cypress/e2e/util.ts index 456ae585..2f76f625 100644 --- a/cypress/e2e/util.ts +++ b/cypress/e2e/util.ts @@ -29,17 +29,15 @@ export const verifyFileSizeGreaterThan = ( extension: string, size: number ) => { - const fileName = `mermaid-${fileType}-2022-01-01-000000.${extension}`; - const filePath = `${downloadsFolder}/${fileName}`; - // eslint-disable-next-line @typescript-eslint/no-unsafe-call - cy.verifyDownload(fileName); - cy.readFile(filePath, null, { - log: false - }).then((buffer: ArrayBuffer) => { - expect(buffer.byteLength).to.be.gt(size); - expect(buffer.byteLength).to.be.lt(size * 1.3); + cy.get('#view').should('not.have.class', 'outOfSync'); + cy.task('readAndDeleteFile', { + folder: downloadsFolder, + fileNamePattern: `^mermaid-${fileType}-.*.${extension}$`, + mode: 'size' + }).then((fileSize: number) => { + expect(fileSize).to.be.gt(size); + expect(fileSize).to.be.lt(size * 1.3); }); - cy.task('deleteFile', filePath); }; export const verifyFileSnapshot = ( @@ -47,14 +45,11 @@ export const verifyFileSnapshot = ( extension: string, content: string ) => { - const fileName = `mermaid-${fileType}-2022-01-01-000000.${extension}`; - const filePath = `${downloadsFolder}/${fileName}`; - // eslint-disable-next-line @typescript-eslint/no-unsafe-call - cy.verifyDownload(fileName); - cy.readFile(filePath, null, { - log: false - }).then((buffer: ArrayBuffer) => - expect(new TextDecoder('utf8').decode(buffer)).to.contain(content) - ); - cy.task('deleteFile', filePath); + cy.task('readAndDeleteFile', { + folder: downloadsFolder, + fileNamePattern: `^mermaid-${fileType}-.*.${extension}$`, + mode: 'content' + }).then((fileContent: number) => { + expect(fileContent).to.contain(content); + }); }; diff --git a/cypress/support/e2e.js b/cypress/support/e2e.js index d9401131..4ef4ffaa 100644 --- a/cypress/support/e2e.js +++ b/cypress/support/e2e.js @@ -15,7 +15,6 @@ // Import commands.js using ES2015 syntax: import './commands'; -require('cy-verify-downloads').addCustomCommand(); // Alternatively you can use CommonJS syntax: // require('./commands') diff --git a/cypress/tsconfig.json b/cypress/tsconfig.json index edd14f8b..e9f59358 100644 --- a/cypress/tsconfig.json +++ b/cypress/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { "allowJs": true, - "types": ["cypress", "cypress-localstorage-commands", "cy-verify-downloads", "node"] + "types": ["cypress", "cypress-localstorage-commands", "node"] }, "include": ["**/*.ts"] } diff --git a/package.json b/package.json index 91ffa57f..5f8534ed 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "@sveltejs/kit": "2.4.1", "@sveltejs/vite-plugin-svelte": "^3.0.1", "@testing-library/svelte": "4.0.5", + "@types/lodash-es": "^4.17.12", "@types/pako": "2.0.3", "@types/uuid": "9.0.7", "@typescript-eslint/eslint-plugin": "6.19.0", @@ -36,7 +37,6 @@ "c8": "7.14.0", "chai": "^4.3.7", "cssnano": "^6.0.0", - "cy-verify-downloads": "0.2.2", "cypress": "12.17.4", "cypress-localstorage-commands": "2.2.5", "eslint": "8.56.0", @@ -50,7 +50,6 @@ "eslint-plugin-unicorn": "^50.0.1", "eslint-plugin-vitest": "^0.3.20", "esserializer": "^1.3.11", - "font-awesome": "^4.7.0", "husky": "^8.0.3", "jsdom": "^21.1.2", "lint-staged": "^15.2.0", @@ -73,6 +72,7 @@ "daisyui": "2.52.0", "dayjs": "^1.11.7", "js-base64": "3.7.5", + "lodash-es": "^4.17.21", "mermaid": "10.7.0", "monaco-editor": "0.45.0", "pako": "2.1.0", diff --git a/src/lib/components/Actions.svelte b/src/lib/components/Actions.svelte index 9b1fd242..3cd45914 100644 --- a/src/lib/components/Actions.svelte +++ b/src/lib/components/Actions.svelte @@ -1,12 +1,13 @@