mirror of
https://github.com/mermaid-js/mermaid-live-editor.git
synced 2025-03-18 17:16:21 +03:00
Remove use of cy.clock
This commit is contained in:
@@ -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;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
@@ -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');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -29,17 +29,14 @@ 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.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 +44,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);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -16,7 +16,7 @@ module.exports = {
|
||||
"1": "{\"code\":\"graph TD\\n A[Party] -->|Get money| B(Go shopping!!)\\n \",\"mermaid\":\"{\\n \\\"theme\\\": \\\"forest\\\",\\n \\\"test\\\": \\\"hello world\\\"\\n}\",\"autoSync\":true,\"updateDiagram\":true,\"loader\":{\"type\":\"files\",\"config\":{\"codeURL\":\"https://gist.githubusercontent.com/sidharthv96/6268a23e673a533dcb198f241fd7012a/raw/4eb03887e6a41397e80bdcdbf94017c498f8f1e2/code.mmd\",\"configURL\":\"https://gist.githubusercontent.com/sidharthv96/6268a23e673a533dcb198f241fd7012a/raw/4eb03887e6a41397e80bdcdbf94017c498f8f1e2/config.json\"}}}"
|
||||
}
|
||||
},
|
||||
"__version": "12.17.4",
|
||||
"__version": "13.6.3",
|
||||
"Auto sync tests": {
|
||||
"should dim diagram when code is edited": {
|
||||
"1": "{\"code\":\"flowchart TD\\n A[Christmas] -->|Get money| B(Go shopping)\\n B --> C{Let me think}\\n C -->|One| D[Laptop]\\n C -->|Two| E[iPhone]\\n C -->|Three| F[fa:fa-car Car]\\n C --> Test\",\"mermaid\":\"{\\n \\\"theme\\\": \\\"default\\\"\\n}\",\"autoSync\":false,\"updateDiagram\":false}"
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"allowJs": true,
|
||||
"types": ["cypress", "cypress-localstorage-commands", "cy-verify-downloads", "node"]
|
||||
"types": ["cypress", "cypress-localstorage-commands", "node"]
|
||||
},
|
||||
"include": ["**/*.ts"]
|
||||
}
|
||||
|
||||
@@ -37,7 +37,6 @@
|
||||
"c8": "7.14.0",
|
||||
"chai": "^4.3.7",
|
||||
"cssnano": "^6.0.0",
|
||||
"cy-verify-downloads": "0.2.2",
|
||||
"cypress": "13.6.3",
|
||||
"cypress-localstorage-commands": "2.2.5",
|
||||
"eslint": "8.56.0",
|
||||
|
||||
@@ -123,7 +123,6 @@
|
||||
error = true;
|
||||
}
|
||||
const timeTaken = Date.now() - startTime;
|
||||
console.log({ timeTaken });
|
||||
saveStatistics(code, timeTaken);
|
||||
recordRenderTime(timeTaken, () => {
|
||||
$inputStateStore.updateDiagram = true;
|
||||
|
||||
@@ -1651,11 +1651,6 @@ cssstyle@^3.0.0:
|
||||
dependencies:
|
||||
rrweb-cssom "^0.6.0"
|
||||
|
||||
cy-verify-downloads@0.2.2:
|
||||
version "0.2.2"
|
||||
resolved "https://registry.yarnpkg.com/cy-verify-downloads/-/cy-verify-downloads-0.2.2.tgz#c5eb96724f1abdaf3456a3ca5669030be52da01c"
|
||||
integrity sha512-Cr4U38xg5z8AK8XiYuEcbAy1rfgtkZTdUFTWkG5NM+BxKSjRlpGt6LpylLpHp9B6ikKCBPotpeewW7fOuBFKlA==
|
||||
|
||||
cypress-localstorage-commands@2.2.5:
|
||||
version "2.2.5"
|
||||
resolved "https://registry.yarnpkg.com/cypress-localstorage-commands/-/cypress-localstorage-commands-2.2.5.tgz#81c8f53a06e2ed93c1e068c1101da85f80f27f61"
|
||||
|
||||
Reference in New Issue
Block a user