mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-10-12 10:39:44 +02:00
@@ -3,3 +3,4 @@ dist/**
|
|||||||
docs/Setup.md
|
docs/Setup.md
|
||||||
cypress.config.js
|
cypress.config.js
|
||||||
cypress/plugins/index.js
|
cypress/plugins/index.js
|
||||||
|
coverage
|
@@ -1,3 +1,4 @@
|
|||||||
dist
|
dist
|
||||||
cypress/platform/xss3.html
|
cypress/platform/xss3.html
|
||||||
.cache
|
.cache
|
||||||
|
coverage
|
@@ -1,3 +0,0 @@
|
|||||||
export const curveBasis = 'basis';
|
|
||||||
export const curveLinear = 'linear';
|
|
||||||
export const curveCardinal = 'cardinal';
|
|
@@ -1,4 +1,7 @@
|
|||||||
let NewD3 = function () {
|
// @ts-nocheck TODO: Fix TS
|
||||||
|
import { vi } from 'vitest';
|
||||||
|
|
||||||
|
const NewD3 = function () {
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@@ -56,9 +59,9 @@ export const MockD3 = (name, parent) => {
|
|||||||
children.push(mockElem);
|
children.push(mockElem);
|
||||||
return mockElem;
|
return mockElem;
|
||||||
};
|
};
|
||||||
elem.lower = jest.fn(() => elem);
|
elem.lower = vi.fn(() => elem);
|
||||||
elem.attr = jest.fn(() => elem);
|
elem.attr = vi.fn(() => elem);
|
||||||
elem.text = jest.fn(() => elem);
|
elem.text = vi.fn(() => elem);
|
||||||
elem.style = jest.fn(() => elem);
|
elem.style = vi.fn(() => elem);
|
||||||
return elem;
|
return elem;
|
||||||
};
|
};
|
3
__mocks__/dagre-d3.ts
Normal file
3
__mocks__/dagre-d3.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
import { vi } from 'vitest';
|
||||||
|
|
||||||
|
// export const render = vi.fn();
|
3
__mocks__/entity-decode/browser.ts
Normal file
3
__mocks__/entity-decode/browser.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
module.exports = function (txt: string) {
|
||||||
|
return txt;
|
||||||
|
};
|
@@ -1,24 +0,0 @@
|
|||||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
||||||
const path = require('path');
|
|
||||||
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
|
|
||||||
module.exports = {
|
|
||||||
testEnvironment: 'jsdom',
|
|
||||||
preset: 'ts-jest',
|
|
||||||
transform: {
|
|
||||||
'^.+\\.[jt]sx?$': 'esbuild-jest',
|
|
||||||
'^.+\\.jison$': [
|
|
||||||
path.resolve(__dirname, './src/jison/transformer.cjs'),
|
|
||||||
{ 'token-stack': true },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
coveragePathIgnorePatterns: [
|
|
||||||
'/node_modules/',
|
|
||||||
'^.+\\.jison$', // might be able to fix in future if .jison adds source-map support
|
|
||||||
],
|
|
||||||
transformIgnorePatterns: ['/node_modules/(?!dagre-d3-renderer/lib|khroma).*\\.js'],
|
|
||||||
testPathIgnorePatterns: ['/node_modules/', '.cache', './cypress'],
|
|
||||||
moduleNameMapper: {
|
|
||||||
'\\.(css|scss)$': 'identity-obj-proxy',
|
|
||||||
},
|
|
||||||
moduleFileExtensions: ['js', 'json', 'jsx', 'ts', 'tsx', 'node', 'jison'],
|
|
||||||
};
|
|
22
package.json
22
package.json
@@ -41,10 +41,9 @@
|
|||||||
"cypress": "cypress run",
|
"cypress": "cypress run",
|
||||||
"cypress:open": "cypress open",
|
"cypress:open": "cypress open",
|
||||||
"e2e": "start-server-and-test dev http://localhost:9000/ cypress",
|
"e2e": "start-server-and-test dev http://localhost:9000/ cypress",
|
||||||
"e2e-upd": "yarn lint && jest e2e -u --config e2e/jest.config.js",
|
"ci": "vitest run",
|
||||||
"ci": "jest src/.*",
|
"test": "yarn lint && vitest run",
|
||||||
"test": "yarn lint && jest src/.*",
|
"test:watch": "vitest --coverage --watch",
|
||||||
"test:watch": "jest --watch src",
|
|
||||||
"prepublishOnly": "yarn build && yarn test",
|
"prepublishOnly": "yarn build && yarn test",
|
||||||
"prepare": "concurrently \"husky install\" \"yarn build\"",
|
"prepare": "concurrently \"husky install\" \"yarn build\"",
|
||||||
"pre-commit": "lint-staged"
|
"pre-commit": "lint-staged"
|
||||||
@@ -87,18 +86,20 @@
|
|||||||
"@types/dompurify": "^2.3.4",
|
"@types/dompurify": "^2.3.4",
|
||||||
"@types/eslint": "^8.4.6",
|
"@types/eslint": "^8.4.6",
|
||||||
"@types/express": "^4.17.13",
|
"@types/express": "^4.17.13",
|
||||||
"@types/jest": "^28.1.7",
|
"@types/jsdom": "^20.0.0",
|
||||||
"@types/lodash": "^4.14.185",
|
"@types/lodash": "^4.14.185",
|
||||||
|
"@types/prettier": "^2.7.0",
|
||||||
"@types/stylis": "^4.0.2",
|
"@types/stylis": "^4.0.2",
|
||||||
"@typescript-eslint/eslint-plugin": "^5.37.0",
|
"@typescript-eslint/eslint-plugin": "^5.37.0",
|
||||||
"@typescript-eslint/parser": "^5.37.0",
|
"@typescript-eslint/parser": "^5.37.0",
|
||||||
|
"@vitest/coverage-c8": "^0.23.2",
|
||||||
|
"@vitest/ui": "^0.23.2",
|
||||||
"concurrently": "^7.4.0",
|
"concurrently": "^7.4.0",
|
||||||
"coveralls": "^3.0.2",
|
"coveralls": "^3.1.1",
|
||||||
"cypress": "^10.0.0",
|
"cypress": "^10.0.0",
|
||||||
"cypress-image-snapshot": "^4.0.1",
|
"cypress-image-snapshot": "^4.0.1",
|
||||||
"documentation": "13.2.0",
|
"documentation": "13.2.0",
|
||||||
"esbuild": "^0.15.8",
|
"esbuild": "^0.15.8",
|
||||||
"esbuild-jest": "^0.5.0",
|
|
||||||
"eslint": "^8.23.1",
|
"eslint": "^8.23.1",
|
||||||
"eslint-config-prettier": "^8.5.0",
|
"eslint-config-prettier": "^8.5.0",
|
||||||
"eslint-plugin-cypress": "^2.12.1",
|
"eslint-plugin-cypress": "^2.12.1",
|
||||||
@@ -111,10 +112,9 @@
|
|||||||
"globby": "^13.1.2",
|
"globby": "^13.1.2",
|
||||||
"husky": "^8.0.0",
|
"husky": "^8.0.0",
|
||||||
"identity-obj-proxy": "^3.0.0",
|
"identity-obj-proxy": "^3.0.0",
|
||||||
"jest": "^28.0.3",
|
|
||||||
"jest-environment-jsdom": "^29.0.3",
|
|
||||||
"jison": "^0.4.18",
|
"jison": "^0.4.18",
|
||||||
"js-base64": "3.7.2",
|
"js-base64": "3.7.2",
|
||||||
|
"jsdom": "^20.0.0",
|
||||||
"lint-staged": "^13.0.0",
|
"lint-staged": "^13.0.0",
|
||||||
"moment": "^2.23.0",
|
"moment": "^2.23.0",
|
||||||
"path-browserify": "^1.0.1",
|
"path-browserify": "^1.0.1",
|
||||||
@@ -123,10 +123,10 @@
|
|||||||
"remark": "^14.0.2",
|
"remark": "^14.0.2",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"start-server-and-test": "^1.12.6",
|
"start-server-and-test": "^1.12.6",
|
||||||
"ts-jest": "^28.0.8",
|
|
||||||
"ts-node": "^10.9.1",
|
"ts-node": "^10.9.1",
|
||||||
"typescript": "^4.8.3",
|
"typescript": "^4.8.3",
|
||||||
"unist-util-flatmap": "^1.0.0"
|
"unist-util-flatmap": "^1.0.0",
|
||||||
|
"vitest": "^0.23.1"
|
||||||
},
|
},
|
||||||
"resolutions": {
|
"resolutions": {
|
||||||
"d3": "^7.0.0"
|
"d3": "^7.0.0"
|
||||||
|
@@ -1,3 +0,0 @@
|
|||||||
module.exports = function (txt) {
|
|
||||||
return txt;
|
|
||||||
};
|
|
@@ -1,18 +1,15 @@
|
|||||||
/**
|
/**
|
||||||
* Mocks for `./mermaidAPI`.
|
* Mocks for `./mermaidAPI`.
|
||||||
*
|
*
|
||||||
* We can't easily use `jest.spyOn(mermaidAPI, "function")` since the object is frozen with `Object.freeze()`.
|
* We can't easily use `vi.spyOn(mermaidAPI, "function")` since the object is frozen with `Object.freeze()`.
|
||||||
*/
|
*/
|
||||||
import * as configApi from '../config';
|
import * as configApi from '../config';
|
||||||
|
import { vi } from 'vitest';
|
||||||
import { addDiagrams } from '../diagram-api/diagram-orchestration';
|
import { addDiagrams } from '../diagram-api/diagram-orchestration';
|
||||||
import Diagram from '../Diagram';
|
import Diagram from '../Diagram';
|
||||||
|
|
||||||
// Normally, we could just do the following to get the original `parse()`
|
// Normally, we could just do the following to get the original `parse()`
|
||||||
// implementation, however, requireActual isn't currently supported in Jest
|
// implementation, however, requireActual returns a promise and it's not documented how to use withing mock file.
|
||||||
// for ESM, see https://github.com/facebook/jest/issues/9430
|
|
||||||
// and https://github.com/facebook/jest/pull/10976
|
|
||||||
// const {parse} = jest.requireActual("./mermaidAPI");
|
|
||||||
|
|
||||||
let hasLoadedDiagrams = false;
|
let hasLoadedDiagrams = false;
|
||||||
/**
|
/**
|
||||||
@@ -31,10 +28,10 @@ function parse(text: string, parseError?: Function): boolean {
|
|||||||
|
|
||||||
// original version cannot be modified since it was frozen with `Object.freeze()`
|
// original version cannot be modified since it was frozen with `Object.freeze()`
|
||||||
export const mermaidAPI = {
|
export const mermaidAPI = {
|
||||||
render: jest.fn(),
|
render: vi.fn(),
|
||||||
parse,
|
parse,
|
||||||
parseDirective: jest.fn(),
|
parseDirective: vi.fn(),
|
||||||
initialize: jest.fn(),
|
initialize: vi.fn(),
|
||||||
getConfig: configApi.getConfig,
|
getConfig: configApi.getConfig,
|
||||||
setConfig: configApi.setConfig,
|
setConfig: configApi.setConfig,
|
||||||
getSiteConfig: configApi.getSiteConfig,
|
getSiteConfig: configApi.getSiteConfig,
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
import { parser } from './parser/classDiagram';
|
import { parser } from './parser/classDiagram';
|
||||||
import classDb from './classDb';
|
import classDb from './classDb';
|
||||||
|
import { vi } from 'vitest';
|
||||||
const spyOn = jest.spyOn;
|
const spyOn = vi.spyOn;
|
||||||
|
|
||||||
describe('class diagram, ', function () {
|
describe('class diagram, ', function () {
|
||||||
describe('when parsing an info graph it', function () {
|
describe('when parsing an info graph it', function () {
|
||||||
@@ -14,7 +14,7 @@ describe('class diagram, ', function () {
|
|||||||
|
|
||||||
parser.parse(str);
|
parser.parse(str);
|
||||||
});
|
});
|
||||||
xit('should handle a leading newline axa', function () {
|
it.skip('should handle a leading newline axa', function () {
|
||||||
const str = '\nclassDiagram\n' + 'class Car';
|
const str = '\nclassDiagram\n' + 'class Car';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@@ -4,9 +4,6 @@ import flowRenderer from './flowRenderer';
|
|||||||
import Diagram from '../../Diagram';
|
import Diagram from '../../Diagram';
|
||||||
import { addDiagrams } from '../../diagram-api/diagram-orchestration';
|
import { addDiagrams } from '../../diagram-api/diagram-orchestration';
|
||||||
addDiagrams();
|
addDiagrams();
|
||||||
afterEach(() => {
|
|
||||||
jest.restoreAllMocks();
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('when using mermaid and ', function () {
|
describe('when using mermaid and ', function () {
|
||||||
describe('when calling addEdges ', function () {
|
describe('when calling addEdges ', function () {
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
import flowDb from '../flowDb';
|
import flowDb from '../flowDb';
|
||||||
import flow from './flow';
|
import flow from './flow';
|
||||||
import { setConfig } from '../../../config';
|
import { setConfig } from '../../../config';
|
||||||
|
import { vi } from 'vitest';
|
||||||
const spyOn = jest.spyOn;
|
const spyOn = vi.spyOn;
|
||||||
|
|
||||||
setConfig({
|
setConfig({
|
||||||
securityLevel: 'strict',
|
securityLevel: 'strict',
|
||||||
|
@@ -284,7 +284,7 @@ describe('[Text] when parsing', () => {
|
|||||||
|
|
||||||
expect(edges[0].text).toBe('text including graph space and v');
|
expect(edges[0].text).toBe('text including graph space and v');
|
||||||
});
|
});
|
||||||
// xit('should handle text on open links',function(){
|
// it.skip('should handle text on open links',function(){
|
||||||
// const res = flow.parser.parse('graph TD;A-- text including graph space --B');
|
// const res = flow.parser.parse('graph TD;A-- text including graph space --B');
|
||||||
//
|
//
|
||||||
// const vert = flow.parser.yy.getVertices();
|
// const vert = flow.parser.yy.getVertices();
|
||||||
@@ -324,7 +324,7 @@ describe('[Text] when parsing', () => {
|
|||||||
expect(vert['C'].type).toBe('round');
|
expect(vert['C'].type).toBe('round');
|
||||||
expect(vert['C'].text).toBe('Chimpansen hoppar åäö <br> - ÅÄÖ');
|
expect(vert['C'].text).toBe('Chimpansen hoppar åäö <br> - ÅÄÖ');
|
||||||
});
|
});
|
||||||
// xit('should handle åäö, minus and space and br',function(){
|
// it.skip('should handle åäö, minus and space and br',function(){
|
||||||
// const res = flow.parser.parse('graph TD; A[Object(foo,bar)]-->B(Thing);');
|
// const res = flow.parser.parse('graph TD; A[Object(foo,bar)]-->B(Thing);');
|
||||||
//
|
//
|
||||||
// const vert = flow.parser.yy.getVertices();
|
// const vert = flow.parser.yy.getVertices();
|
||||||
|
@@ -62,7 +62,7 @@ describe('when parsing subgraphs', function () {
|
|||||||
expect(subgraph.id).toBe('some-id');
|
expect(subgraph.id).toBe('some-id');
|
||||||
});
|
});
|
||||||
|
|
||||||
xit('should handle subgraph without id and space in title', function () {
|
it.skip('should handle subgraph without id and space in title', function () {
|
||||||
const res = flow.parser.parse('graph TB\nsubgraph Some Title\n\ta1-->a2\nend');
|
const res = flow.parser.parse('graph TB\nsubgraph Some Title\n\ta1-->a2\nend');
|
||||||
const subgraphs = flow.parser.yy.getSubGraphs();
|
const subgraphs = flow.parser.yy.getSubGraphs();
|
||||||
expect(subgraphs.length).toBe(1);
|
expect(subgraphs.length).toBe(1);
|
||||||
|
@@ -1,5 +1,8 @@
|
|||||||
|
// @ts-nocheck TODO: Fix TS
|
||||||
import moment from 'moment-mini';
|
import moment from 'moment-mini';
|
||||||
import ganttDb from './ganttDb';
|
import ganttDb from './ganttDb';
|
||||||
|
import { it, describe } from 'vitest';
|
||||||
|
import { convert } from '../../tests/util';
|
||||||
|
|
||||||
describe('when using the ganttDb', function () {
|
describe('when using the ganttDb', function () {
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
@@ -7,14 +10,23 @@ describe('when using the ganttDb', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('when using duration', function () {
|
describe('when using duration', function () {
|
||||||
it.each`
|
it.each([{ str: '1d', expected: moment.duration(1, 'd') }])(
|
||||||
|
'should %s resulting in $o duration',
|
||||||
|
({ str, expected }) => {
|
||||||
|
expect(ganttDb.parseDuration(str)).toEqual(expected);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
it.each(
|
||||||
|
convert`
|
||||||
str | expected
|
str | expected
|
||||||
${'1d'} | ${moment.duration(1, 'd')}
|
${'1d'} | ${moment.duration(1, 'd')}
|
||||||
${'2w'} | ${moment.duration(2, 'w')}
|
${'2w'} | ${moment.duration(2, 'w')}
|
||||||
${'1ms'} | ${moment.duration(1, 'ms')}
|
${'1ms'} | ${moment.duration(1, 'ms')}
|
||||||
${'0.1s'} | ${moment.duration(100, 'ms')}
|
${'0.1s'} | ${moment.duration(100, 'ms')}
|
||||||
${'1f'} | ${moment.duration.invalid()}
|
${'1f'} | ${moment.duration.invalid()}
|
||||||
`('should $str resulting in $expected duration', ({ str, expected }) => {
|
`
|
||||||
|
)('should $str resulting in $expected duration', ({ str, expected }) => {
|
||||||
expect(ganttDb.parseDuration(str)).toEqual(expected);
|
expect(ganttDb.parseDuration(str)).toEqual(expected);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -31,7 +43,7 @@ describe('when using the ganttDb', function () {
|
|||||||
ganttDb.clear();
|
ganttDb.clear();
|
||||||
});
|
});
|
||||||
|
|
||||||
it.each`
|
it.each(convert`
|
||||||
fn | expected
|
fn | expected
|
||||||
${'getTasks'} | ${[]}
|
${'getTasks'} | ${[]}
|
||||||
${'getAccTitle'} | ${''}
|
${'getAccTitle'} | ${''}
|
||||||
@@ -42,12 +54,13 @@ describe('when using the ganttDb', function () {
|
|||||||
${'getExcludes'} | ${[]}
|
${'getExcludes'} | ${[]}
|
||||||
${'getSections'} | ${[]}
|
${'getSections'} | ${[]}
|
||||||
${'endDatesAreInclusive'} | ${false}
|
${'endDatesAreInclusive'} | ${false}
|
||||||
`('should clear $fn', ({ fn, expected }) => {
|
`)('should clear $fn', ({ fn, expected }) => {
|
||||||
expect(ganttDb[fn]()).toEqual(expected);
|
expect(ganttDb[fn]()).toEqual(expected);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it.each`
|
// prettier-ignore
|
||||||
|
it.each(convert`
|
||||||
testName | section | taskName | taskData | expStartDate | expEndDate | expId | expTask
|
testName | section | taskName | taskData | expStartDate | expEndDate | expId | expTask
|
||||||
${'should handle fixed dates'} | ${'testa1'} | ${'test1'} | ${'id1,2013-01-01,2013-01-12'} | ${new Date(2013, 0, 1)} | ${new Date(2013, 0, 12)} | ${'id1'} | ${'test1'}
|
${'should handle fixed dates'} | ${'testa1'} | ${'test1'} | ${'id1,2013-01-01,2013-01-12'} | ${new Date(2013, 0, 1)} | ${new Date(2013, 0, 12)} | ${'id1'} | ${'test1'}
|
||||||
${'should handle duration (days) instead of fixed date to determine end date'} | ${'testa1'} | ${'test1'} | ${'id1,2013-01-01,2d'} | ${new Date(2013, 0, 1)} | ${new Date(2013, 0, 3)} | ${'id1'} | ${'test1'}
|
${'should handle duration (days) instead of fixed date to determine end date'} | ${'testa1'} | ${'test1'} | ${'id1,2013-01-01,2d'} | ${new Date(2013, 0, 1)} | ${new Date(2013, 0, 3)} | ${'id1'} | ${'test1'}
|
||||||
@@ -57,7 +70,7 @@ describe('when using the ganttDb', function () {
|
|||||||
${'should handle duration (weeks) instead of fixed date to determine end date'} | ${'testa1'} | ${'test1'} | ${'id1,2013-01-01,2w'} | ${new Date(2013, 0, 1)} | ${new Date(2013, 0, 15)} | ${'id1'} | ${'test1'}
|
${'should handle duration (weeks) instead of fixed date to determine end date'} | ${'testa1'} | ${'test1'} | ${'id1,2013-01-01,2w'} | ${new Date(2013, 0, 1)} | ${new Date(2013, 0, 15)} | ${'id1'} | ${'test1'}
|
||||||
${'should handle fixed dates without id'} | ${'testa1'} | ${'test1'} | ${'2013-01-01,2013-01-12'} | ${new Date(2013, 0, 1)} | ${new Date(2013, 0, 12)} | ${'task1'} | ${'test1'}
|
${'should handle fixed dates without id'} | ${'testa1'} | ${'test1'} | ${'2013-01-01,2013-01-12'} | ${new Date(2013, 0, 1)} | ${new Date(2013, 0, 12)} | ${'task1'} | ${'test1'}
|
||||||
${'should handle duration instead of a fixed date to determine end date without id'} | ${'testa1'} | ${'test1'} | ${'2013-01-01,4d'} | ${new Date(2013, 0, 1)} | ${new Date(2013, 0, 5)} | ${'task1'} | ${'test1'}
|
${'should handle duration instead of a fixed date to determine end date without id'} | ${'testa1'} | ${'test1'} | ${'2013-01-01,4d'} | ${new Date(2013, 0, 1)} | ${new Date(2013, 0, 5)} | ${'task1'} | ${'test1'}
|
||||||
`('$testName', ({ section, taskName, taskData, expStartDate, expEndDate, expId, expTask }) => {
|
`)('$testName', ({ section, taskName, taskData, expStartDate, expEndDate, expId, expTask }) => {
|
||||||
ganttDb.setDateFormat('YYYY-MM-DD');
|
ganttDb.setDateFormat('YYYY-MM-DD');
|
||||||
ganttDb.addSection(section);
|
ganttDb.addSection(section);
|
||||||
ganttDb.addTask(taskName, taskData);
|
ganttDb.addTask(taskName, taskData);
|
||||||
@@ -68,14 +81,15 @@ describe('when using the ganttDb', function () {
|
|||||||
expect(tasks[0].task).toEqual(expTask);
|
expect(tasks[0].task).toEqual(expTask);
|
||||||
});
|
});
|
||||||
|
|
||||||
it.each`
|
// prettier-ignore
|
||||||
|
it.each(convert`
|
||||||
section | taskName1 | taskName2 | taskData1 | taskData2 | expStartDate2 | expEndDate2 | expId2 | expTask2
|
section | taskName1 | taskName2 | taskData1 | taskData2 | expStartDate2 | expEndDate2 | expId2 | expTask2
|
||||||
${'testa1'} | ${'test1'} | ${'test2'} | ${'id1,2013-01-01,2w'} | ${'id2,after id1,1d'} | ${new Date(2013, 0, 15)} | ${undefined} | ${'id2'} | ${'test2'}
|
${'testa1'} | ${'test1'} | ${'test2'} | ${'id1,2013-01-01,2w'} | ${'id2,after id1,1d'} | ${new Date(2013, 0, 15)} | ${undefined} | ${'id2'} | ${'test2'}
|
||||||
${'testa1'} | ${'test1'} | ${'test2'} | ${'id1,2013-01-01,2w'} | ${'id2,after id3,1d'} | ${new Date(new Date().setHours(0, 0, 0, 0))} | ${undefined} | ${'id2'} | ${'test2'}
|
${'testa1'} | ${'test1'} | ${'test2'} | ${'id1,2013-01-01,2w'} | ${'id2,after id3,1d'} | ${new Date(new Date().setHours(0, 0, 0, 0))} | ${undefined} | ${'id2'} | ${'test2'}
|
||||||
${'testa1'} | ${'test1'} | ${'test2'} | ${'id1,2013-01-01,2w'} | ${'after id1,1d'} | ${new Date(2013, 0, 15)} | ${undefined} | ${'task1'} | ${'test2'}
|
${'testa1'} | ${'test1'} | ${'test2'} | ${'id1,2013-01-01,2w'} | ${'after id1,1d'} | ${new Date(2013, 0, 15)} | ${undefined} | ${'task1'} | ${'test2'}
|
||||||
${'testa1'} | ${'test1'} | ${'test2'} | ${'id1,2013-01-01,2w'} | ${'2013-01-26'} | ${new Date(2013, 0, 15)} | ${new Date(2013, 0, 26)} | ${'task1'} | ${'test2'}
|
${'testa1'} | ${'test1'} | ${'test2'} | ${'id1,2013-01-01,2w'} | ${'2013-01-26'} | ${new Date(2013, 0, 15)} | ${new Date(2013, 0, 26)} | ${'task1'} | ${'test2'}
|
||||||
${'testa1'} | ${'test1'} | ${'test2'} | ${'id1,2013-01-01,2w'} | ${'2d'} | ${new Date(2013, 0, 15)} | ${new Date(2013, 0, 17)} | ${'task1'} | ${'test2'}
|
${'testa1'} | ${'test1'} | ${'test2'} | ${'id1,2013-01-01,2w'} | ${'2d'} | ${new Date(2013, 0, 15)} | ${new Date(2013, 0, 17)} | ${'task1'} | ${'test2'}
|
||||||
`(
|
`)(
|
||||||
'$testName',
|
'$testName',
|
||||||
({
|
({
|
||||||
section,
|
section,
|
||||||
@@ -381,11 +395,11 @@ describe('when using the ganttDb', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it.each`
|
it.each(convert`
|
||||||
type | expected
|
type | expected
|
||||||
${'hide'} | ${'off'}
|
${'hide'} | ${'off'}
|
||||||
${'style'} | ${'stoke:stroke-width:5px,stroke:#00f,opacity:0.5'}
|
${'style'} | ${'stoke:stroke-width:5px,stroke:#00f,opacity:0.5'}
|
||||||
`('should ${type} today marker', ({ expected }) => {
|
`)('should ${type} today marker', ({ expected }) => {
|
||||||
ganttDb.setTodayMarker(expected);
|
ganttDb.setTodayMarker(expected);
|
||||||
expect(ganttDb.getTodayMarker()).toEqual(expected);
|
expect(ganttDb.getTodayMarker()).toEqual(expected);
|
||||||
});
|
});
|
@@ -1,7 +1,8 @@
|
|||||||
import { parser } from './gantt';
|
import { parser } from './gantt';
|
||||||
import ganttDb from '../ganttDb';
|
import ganttDb from '../ganttDb';
|
||||||
|
import { convert } from '../../../tests/util';
|
||||||
const spyOn = jest.spyOn;
|
import { vi } from 'vitest';
|
||||||
|
const spyOn = vi.spyOn;
|
||||||
const parserFnConstructor = (str) => {
|
const parserFnConstructor = (str) => {
|
||||||
return () => {
|
return () => {
|
||||||
parser.parse(str);
|
parser.parse(str);
|
||||||
@@ -92,14 +93,14 @@ describe('when parsing a gantt diagram it', function () {
|
|||||||
expect(tasks[0].id).toEqual('des1');
|
expect(tasks[0].id).toEqual('des1');
|
||||||
expect(tasks[0].task).toEqual('Design jison grammar');
|
expect(tasks[0].task).toEqual('Design jison grammar');
|
||||||
});
|
});
|
||||||
it.each`
|
it.each(convert`
|
||||||
tags | milestone | done | crit | active
|
tags | milestone | done | crit | active
|
||||||
${'milestone'} | ${true} | ${false} | ${false} | ${false}
|
${'milestone'} | ${true} | ${false} | ${false} | ${false}
|
||||||
${'done'} | ${false} | ${true} | ${false} | ${false}
|
${'done'} | ${false} | ${true} | ${false} | ${false}
|
||||||
${'crit'} | ${false} | ${false} | ${true} | ${false}
|
${'crit'} | ${false} | ${false} | ${true} | ${false}
|
||||||
${'active'} | ${false} | ${false} | ${false} | ${true}
|
${'active'} | ${false} | ${false} | ${false} | ${true}
|
||||||
${'crit,milestone,done'} | ${true} | ${true} | ${true} | ${false}
|
${'crit,milestone,done'} | ${true} | ${true} | ${true} | ${false}
|
||||||
`('should handle a task with tags $tags', ({ tags, milestone, done, crit, active }) => {
|
`)('should handle a task with tags $tags', ({ tags, milestone, done, crit, active }) => {
|
||||||
const str =
|
const str =
|
||||||
'gantt\n' +
|
'gantt\n' +
|
||||||
'dateFormat YYYY-MM-DD\n' +
|
'dateFormat YYYY-MM-DD\n' +
|
||||||
|
@@ -25,15 +25,15 @@ describe('more than one sequence diagram', () => {
|
|||||||
Alice->Bob:Hello Bob, how are you?
|
Alice->Bob:Hello Bob, how are you?
|
||||||
Bob-->Alice: I am good thanks!`);
|
Bob-->Alice: I am good thanks!`);
|
||||||
expect(diagram1.db.getMessages()).toMatchInlineSnapshot(`
|
expect(diagram1.db.getMessages()).toMatchInlineSnapshot(`
|
||||||
Array [
|
[
|
||||||
Object {
|
{
|
||||||
"from": "Alice",
|
"from": "Alice",
|
||||||
"message": "Hello Bob, how are you?",
|
"message": "Hello Bob, how are you?",
|
||||||
"to": "Bob",
|
"to": "Bob",
|
||||||
"type": 5,
|
"type": 5,
|
||||||
"wrap": false,
|
"wrap": false,
|
||||||
},
|
},
|
||||||
Object {
|
{
|
||||||
"from": "Bob",
|
"from": "Bob",
|
||||||
"message": "I am good thanks!",
|
"message": "I am good thanks!",
|
||||||
"to": "Alice",
|
"to": "Alice",
|
||||||
@@ -48,15 +48,15 @@ describe('more than one sequence diagram', () => {
|
|||||||
Bob-->Alice: I am good thanks!`);
|
Bob-->Alice: I am good thanks!`);
|
||||||
|
|
||||||
expect(diagram2.db.getMessages()).toMatchInlineSnapshot(`
|
expect(diagram2.db.getMessages()).toMatchInlineSnapshot(`
|
||||||
Array [
|
[
|
||||||
Object {
|
{
|
||||||
"from": "Alice",
|
"from": "Alice",
|
||||||
"message": "Hello Bob, how are you?",
|
"message": "Hello Bob, how are you?",
|
||||||
"to": "Bob",
|
"to": "Bob",
|
||||||
"type": 5,
|
"type": 5,
|
||||||
"wrap": false,
|
"wrap": false,
|
||||||
},
|
},
|
||||||
Object {
|
{
|
||||||
"from": "Bob",
|
"from": "Bob",
|
||||||
"message": "I am good thanks!",
|
"message": "I am good thanks!",
|
||||||
"to": "Alice",
|
"to": "Alice",
|
||||||
@@ -73,15 +73,15 @@ describe('more than one sequence diagram', () => {
|
|||||||
John-->Alice: I am good thanks!`);
|
John-->Alice: I am good thanks!`);
|
||||||
|
|
||||||
expect(diagram3.db.getMessages()).toMatchInlineSnapshot(`
|
expect(diagram3.db.getMessages()).toMatchInlineSnapshot(`
|
||||||
Array [
|
[
|
||||||
Object {
|
{
|
||||||
"from": "Alice",
|
"from": "Alice",
|
||||||
"message": "Hello John, how are you?",
|
"message": "Hello John, how are you?",
|
||||||
"to": "John",
|
"to": "John",
|
||||||
"type": 5,
|
"type": 5,
|
||||||
"wrap": false,
|
"wrap": false,
|
||||||
},
|
},
|
||||||
Object {
|
{
|
||||||
"from": "John",
|
"from": "John",
|
||||||
"message": "I am good thanks!",
|
"message": "I am good thanks!",
|
||||||
"to": "Alice",
|
"to": "Alice",
|
||||||
|
@@ -389,7 +389,7 @@ describe('state diagram, ', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('when parsing an ignored info graph it', function () {
|
describe('when parsing an ignored info graph it', function () {
|
||||||
xit('should handle if statements', function () {
|
it.skip('should handle if statements', function () {
|
||||||
const str = `stateDiagram\n
|
const str = `stateDiagram\n
|
||||||
[*] --> "Order Submitted"
|
[*] --> "Order Submitted"
|
||||||
if "Payment Accepted" then
|
if "Payment Accepted" then
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
import journeyDb from './journeyDb';
|
import journeyDb from './journeyDb';
|
||||||
|
import { convert } from '../../tests/util';
|
||||||
|
|
||||||
describe('when using the journeyDb', function () {
|
describe('when using the journeyDb', function () {
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
@@ -13,13 +14,13 @@ describe('when using the journeyDb', function () {
|
|||||||
journeyDb.clear();
|
journeyDb.clear();
|
||||||
});
|
});
|
||||||
|
|
||||||
it.each`
|
it.each(convert`
|
||||||
fn | expected
|
fn | expected
|
||||||
${'getTasks'} | ${[]}
|
${'getTasks'} | ${[]}
|
||||||
${'getAccTitle'} | ${''}
|
${'getAccTitle'} | ${''}
|
||||||
${'getSections'} | ${[]}
|
${'getSections'} | ${[]}
|
||||||
${'getActors'} | ${[]}
|
${'getActors'} | ${[]}
|
||||||
`('should clear $fn', ({ fn, expected }) => {
|
`)('should clear $fn', ({ fn, expected }) => {
|
||||||
expect(journeyDb[fn]()).toEqual(expected);
|
expect(journeyDb[fn]()).toEqual(expected);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -31,18 +32,18 @@ describe('when using the journeyDb', function () {
|
|||||||
journeyDb.addTask('test2', '1: id2');
|
journeyDb.addTask('test2', '1: id2');
|
||||||
journeyDb.clear();
|
journeyDb.clear();
|
||||||
});
|
});
|
||||||
it.each`
|
it.each(convert`
|
||||||
fn | expected
|
fn | expected
|
||||||
${'getTasks'} | ${[]}
|
${'getTasks'} | ${[]}
|
||||||
${'getAccTitle'} | ${''}
|
${'getAccTitle'} | ${''}
|
||||||
${'getAccDescription'} | ${''}
|
${'getAccDescription'} | ${''}
|
||||||
${'getSections'} | ${[]}
|
${'getSections'} | ${[]}
|
||||||
`('should clear $fn', ({ fn, expected }) => {
|
`)('should clear $fn', ({ fn, expected }) => {
|
||||||
expect(journeyDb[fn]()).toEqual(expected);
|
expect(journeyDb[fn]()).toEqual(expected);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('tasks and actors should be added', function () {
|
it('tasks and actors should be added', function () {
|
||||||
journeyDb.setAccTitle('Shopping');
|
journeyDb.setAccTitle('Shopping');
|
||||||
journeyDb.setAccDescription('A user journey for family shopping');
|
journeyDb.setAccDescription('A user journey for family shopping');
|
||||||
journeyDb.addSection('Journey to the shops');
|
journeyDb.addSection('Journey to the shops');
|
||||||
|
@@ -1,19 +1,12 @@
|
|||||||
// mocks the mermaidAPI.render function (see `./__mocks__/mermaidAPI`)
|
import mermaid from './mermaid';
|
||||||
jest.mock('./mermaidAPI');
|
import { mermaidAPI } from './mermaidAPI';
|
||||||
// jest.mock only works well with CJS, see https://github.com/facebook/jest/issues/9430
|
import { vi, describe, it, beforeEach, afterEach, expect } from 'vitest';
|
||||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
const spyOn = vi.spyOn;
|
||||||
const { default: mermaid } = require('./mermaid');
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
||||||
const { mermaidAPI } = require('./mermaidAPI');
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
||||||
const { default: flowDb } = require('./diagrams/flowchart/flowDb');
|
|
||||||
|
|
||||||
import flowParser from './diagrams/flowchart/parser/flow';
|
vi.mock('./mermaidAPI');
|
||||||
|
|
||||||
const spyOn = jest.spyOn;
|
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
jest.restoreAllMocks();
|
vi.restoreAllMocks();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when using mermaid and ', function () {
|
describe('when using mermaid and ', function () {
|
||||||
@@ -63,11 +56,6 @@ describe('when using mermaid and ', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('checking validity of input ', function () {
|
describe('checking validity of input ', function () {
|
||||||
beforeEach(function () {
|
|
||||||
flowParser.parser.yy = flowDb;
|
|
||||||
flowDb.clear();
|
|
||||||
flowDb.setGen('gen-2');
|
|
||||||
});
|
|
||||||
it('should throw for an invalid definition', function () {
|
it('should throw for an invalid definition', function () {
|
||||||
expect(() => mermaid.parse('this is not a mermaid diagram definition')).toThrow();
|
expect(() => mermaid.parse('this is not a mermaid diagram definition')).toThrow();
|
||||||
});
|
});
|
3
src/tests/setup.ts
Normal file
3
src/tests/setup.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
import { vi } from 'vitest';
|
||||||
|
vi.mock('d3');
|
||||||
|
vi.mock('dagre-d3');
|
44
src/tests/util.ts
Normal file
44
src/tests/util.ts
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
Used to convert jest's Tagged Template literals to object arrays as required by vitest.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
Jest code
|
||||||
|
```ts
|
||||||
|
it.each`
|
||||||
|
str | expected
|
||||||
|
${'1d'} | ${moment.duration(1, 'd')}
|
||||||
|
${'2w'} | ${moment.duration(2, 'w')}
|
||||||
|
`('should parse $str to $expected duration', ({ str, expected }) => {
|
||||||
|
expect(yourFunction(str)).toEqual(expected);
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
Vitest code
|
||||||
|
```ts
|
||||||
|
it.each(convert`
|
||||||
|
str | expected
|
||||||
|
${'1d'} | ${moment.duration(1, 'd')}
|
||||||
|
${'2w'} | ${moment.duration(2, 'w')}
|
||||||
|
`)('should parse $str to $expected duration', ({ str, expected }) => {
|
||||||
|
expect(yourFunction(str)).toEqual(expected);
|
||||||
|
});
|
||||||
|
```
|
||||||
|
*/
|
||||||
|
|
||||||
|
export const convert = (template: TemplateStringsArray, ...params: any[]) => {
|
||||||
|
const header = template[0]
|
||||||
|
.trim()
|
||||||
|
.split('|')
|
||||||
|
.map((s) => s.trim());
|
||||||
|
if (header.length === 0 || params.length % header.length !== 0) {
|
||||||
|
throw new Error('Table column count mismatch');
|
||||||
|
}
|
||||||
|
const chunkSize = header.length;
|
||||||
|
const out = [];
|
||||||
|
for (let i = 0; i < params.length; i += chunkSize) {
|
||||||
|
const chunk = params.slice(i, i + chunkSize);
|
||||||
|
out.push(Object.fromEntries(chunk.map((v, i) => [header[i], v])));
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
};
|
@@ -1,3 +1,4 @@
|
|||||||
|
import { vi, describe, it, expect, beforeEach } from 'vitest';
|
||||||
import utils from './utils';
|
import utils from './utils';
|
||||||
import assignWithDepth from './assignWithDepth';
|
import assignWithDepth from './assignWithDepth';
|
||||||
import { detectType } from './diagram-api/detectType';
|
import { detectType } from './diagram-api/detectType';
|
||||||
@@ -303,14 +304,22 @@ describe('when formatting urls', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('when initializing the id generator', function () {
|
describe('when initializing the id generator', function () {
|
||||||
it('should return a random number generator based on Date', function (done) {
|
beforeEach(() => {
|
||||||
|
// tell vitest we use mocked time
|
||||||
|
vi.useFakeTimers();
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
// restoring date after each test run
|
||||||
|
vi.useRealTimers();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return a random number generator based on Date', function () {
|
||||||
const idGenerator = new utils.initIdGenerator(false);
|
const idGenerator = new utils.initIdGenerator(false);
|
||||||
expect(typeof idGenerator.next).toEqual('function');
|
expect(typeof idGenerator.next).toEqual('function');
|
||||||
const lastId = idGenerator.next();
|
const lastId = idGenerator.next();
|
||||||
setTimeout(() => {
|
vi.advanceTimersByTime(1000);
|
||||||
expect(idGenerator.next() > lastId).toBe(true);
|
expect(idGenerator.next() > lastId).toBe(true);
|
||||||
done();
|
|
||||||
}, 5);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return a non random number generator', function () {
|
it('should return a non random number generator', function () {
|
||||||
|
@@ -11,10 +11,10 @@
|
|||||||
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
|
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
|
||||||
|
|
||||||
/* Language and Environment */
|
/* Language and Environment */
|
||||||
"target": "es2016" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
|
"target": "ES6" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
|
||||||
"lib": [
|
"lib": [
|
||||||
"ES2021",
|
"DOM",
|
||||||
"DOM"
|
"ES2021"
|
||||||
] /* Specify a set of bundled library declaration files that describe the target runtime environment. */,
|
] /* Specify a set of bundled library declaration files that describe the target runtime environment. */,
|
||||||
// "jsx": "preserve", /* Specify what JSX code is generated. */
|
// "jsx": "preserve", /* Specify what JSX code is generated. */
|
||||||
// "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
|
// "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
|
||||||
@@ -34,7 +34,10 @@
|
|||||||
// "paths": {} /* Specify a set of entries that re-map imports to additional lookup locations. */,
|
// "paths": {} /* Specify a set of entries that re-map imports to additional lookup locations. */,
|
||||||
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
||||||
// "typeRoots": [] /* Specify multiple folders that act like `./node_modules/@types`. */,
|
// "typeRoots": [] /* Specify multiple folders that act like `./node_modules/@types`. */,
|
||||||
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
|
"types": [
|
||||||
|
"vitest/globals"
|
||||||
|
] /* Specify type package names to be included without being referenced in a source file. */,
|
||||||
|
|
||||||
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
||||||
"resolveJsonModule": true /* Enable importing .json files */,
|
"resolveJsonModule": true /* Enable importing .json files */,
|
||||||
// "noResolve": true, /* Disallow `import`s, `require`s or `<reference>`s from expanding the number of files TypeScript should add to a project. */
|
// "noResolve": true, /* Disallow `import`s, `require`s or `<reference>`s from expanding the number of files TypeScript should add to a project. */
|
||||||
|
38
vite.config.cts
Normal file
38
vite.config.cts
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
import { Generator } from 'jison';
|
||||||
|
import { defineConfig } from 'vitest/config';
|
||||||
|
|
||||||
|
const fileRegex = /\.jison$/;
|
||||||
|
|
||||||
|
/** Transforms jison to js. */
|
||||||
|
export function jisonPlugin() {
|
||||||
|
return {
|
||||||
|
name: 'transform-jison',
|
||||||
|
|
||||||
|
transform(src: string, id: string) {
|
||||||
|
if (fileRegex.test(id)) {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.log('Transforming', id);
|
||||||
|
return {
|
||||||
|
// @ts-ignore no typings for jison
|
||||||
|
code: new Generator(src, { 'token-stack': true }).generate(),
|
||||||
|
map: null, // provide source map if available
|
||||||
|
};
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
resolve: {
|
||||||
|
extensions: ['.jison', '.js', '.ts', '.json'],
|
||||||
|
},
|
||||||
|
plugins: [jisonPlugin()],
|
||||||
|
test: {
|
||||||
|
environment: 'jsdom',
|
||||||
|
globals: true,
|
||||||
|
setupFiles: ['src/tests/setup.ts'],
|
||||||
|
coverage: {
|
||||||
|
reporter: ['text', 'json', 'html', 'lcov'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
Reference in New Issue
Block a user