Compare commits

...
34 Commits
Author SHA1 Message Date
Sidharth Vinod e69b4def13 Fix test 2022-07-07 01:15:57 +05:30
Sidharth Vinod 10585650fd Fix test 2022-07-07 01:07:16 +05:30
Sidharth Vinod 861fd442c2 Fix test 2022-07-07 00:53:51 +05:30
Sidharth Vinod cab7ae5f65 Merge branch 'master' into vitest
* master:
2022-07-07 00:27:22 +05:30
Sidharth Vinod 31de1c79aa Fix security formatting. 2022-07-07 00:22:37 +05:30
Sidharth Vinod 0ea5d812b2 Fix cypress 2022-07-07 00:19:42 +05:30
Sidharth Vinod 79fb9d1cb1 Pin versions; Fix svelte kit 2022-07-06 23:49:04 +05:30
Sidharth Vinod 4c965fbe2e Cypress 2022-07-06 16:51:25 +05:30
Sidharth Vinod b4fe60d49c Remove mocha 2022-07-06 15:23:51 +05:30
Sidharth Vinod e04bb15c35 Add dom testing 2022-07-06 13:01:59 +05:30
Sidharth Vinod 1c6371cb8c Add vitest 2022-07-06 12:17:37 +05:30
Sidharth Vinod 0b89c8d7e8 Merge pull request #876 from mermaid-js/develop
Develop
2022-07-06 11:08:14 +05:30
Sidharth Vinod bb536e9c36 Add check before typing 2022-07-06 10:57:27 +05:30
Sidharth Vinod 76c421924c Merge branch 'master' into develop
* master:
  fix #796: Export SVG fix
  Fix loading tests
  Bind correct store
  add update test
  Fix #851: Simplify data flow and error handling
2022-07-06 10:44:49 +05:30
Sidharth Vinod 0e331a42d8 Split vite config 2022-07-06 10:34:35 +05:30
Sidharth Vinod 9cd19f2a81 Update kit 2022-07-06 10:27:51 +05:30
Sidharth Vinod a08d392b1b Update kit 2022-07-06 10:25:34 +05:30
sidharthv96 54cdae4f40 Update Browserslist 2022-07-06 04:46:29 +00:00
Sidharth Vinod caa536b781 Add license 2022-07-06 10:15:21 +05:30
dependabot[bot]anddependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> a2d95320b8 chore(deps): bump mermaid from 9.1.2 to 9.1.3 (#877)
Bumps [mermaid](https://github.com/knsv/mermaid) from 9.1.2 to 9.1.3.
- [Release notes](https://github.com/knsv/mermaid/releases)
- [Changelog](https://github.com/mermaid-js/mermaid/blob/develop/CHANGELOG.md)
- [Commits](https://github.com/knsv/mermaid/compare/9.1.2...9.1.3)

---
updated-dependencies:
- dependency-name: mermaid
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-07-01 09:54:17 +02:00
dependabot[bot]anddependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> 3009619e79 chore(deps-dev): bump lint-staged from 13.0.2 to 13.0.3 (#872)
Bumps [lint-staged](https://github.com/okonet/lint-staged) from 13.0.2 to 13.0.3.
- [Release notes](https://github.com/okonet/lint-staged/releases)
- [Commits](https://github.com/okonet/lint-staged/compare/v13.0.2...v13.0.3)

---
updated-dependencies:
- dependency-name: lint-staged
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-07-01 09:53:44 +02:00
mmorel-35 6977a3d4a3 Update Browserslist 2022-07-01 07:39:17 +00:00
dependabot[bot]anddependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> e83e287546 chore(deps-dev): bump cypress from 10.2.0 to 10.3.0 (#873)
Bumps [cypress](https://github.com/cypress-io/cypress) from 10.2.0 to 10.3.0.
- [Release notes](https://github.com/cypress-io/cypress/releases)
- [Changelog](https://github.com/cypress-io/cypress/blob/develop/.releaserc.base.js)
- [Commits](https://github.com/cypress-io/cypress/compare/v10.2.0...v10.3.0)

---
updated-dependencies:
- dependency-name: cypress
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-07-01 09:38:19 +02:00
dependabot[bot]anddependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> 30d67e1d6f chore(deps-dev): bump @sveltejs/kit (#871)
Bumps [@sveltejs/kit](https://github.com/sveltejs/kit/tree/HEAD/packages/kit) from 1.0.0-next.354 to 1.0.0-next.357.
- [Release notes](https://github.com/sveltejs/kit/releases)
- [Changelog](https://github.com/sveltejs/kit/blob/master/packages/kit/CHANGELOG.md)
- [Commits](https://github.com/sveltejs/kit/commits/@sveltejs/kit@1.0.0-next.357/packages/kit)

---
updated-dependencies:
- dependency-name: "@sveltejs/kit"
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-07-01 09:38:04 +02:00
dependabot[bot]anddependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> 5d66248c78 chore(deps-dev): bump typescript from 4.7.3 to 4.7.4 (#874)
Bumps [typescript](https://github.com/Microsoft/TypeScript) from 4.7.3 to 4.7.4.
- [Release notes](https://github.com/Microsoft/TypeScript/releases)
- [Commits](https://github.com/Microsoft/TypeScript/compare/v4.7.3...v4.7.4)

---
updated-dependencies:
- dependency-name: typescript
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-07-01 09:37:47 +02:00
dependabot[bot]anddependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> 754f80dd94 chore(deps-dev): bump eslint-plugin-tailwindcss from 3.5.2 to 3.6.0 (#875)
Bumps [eslint-plugin-tailwindcss](https://github.com/francoismassart/eslint-plugin-tailwindcss) from 3.5.2 to 3.6.0.
- [Release notes](https://github.com/francoismassart/eslint-plugin-tailwindcss/releases)
- [Commits](https://github.com/francoismassart/eslint-plugin-tailwindcss/compare/v3.5.2...v3.6.0)

---
updated-dependencies:
- dependency-name: eslint-plugin-tailwindcss
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-07-01 09:37:29 +02:00
Sidharth Vinod 2cff54b33d Merge pull request #864 from mermaid-js/fix/dataFlow
Fix/data flow
2022-06-30 09:24:36 +05:30
Sidharth Vinod ddc1291d1b Merge pull request #867 from mermaid-js/fix/796
fix #796: Export SVG fix
2022-06-29 00:39:15 +05:30
Sidharth Vinod dd17fd7e3f fix #796: Export SVG fix 2022-06-29 00:25:25 +05:30
Sidharth Vinod ac7cfbd286 Merge pull request #863 from mermaid-js/develop
Develop
2022-06-27 20:22:13 +05:30
Sidharth Vinod 19b1ca9b2e Merge pull request #860 from mermaid-js/develop
Develop
2022-06-24 14:27:45 +05:30
Sidharth Vinod a4e10b936b Merge pull request #854 from mermaid-js/develop
Develop
2022-06-24 00:18:12 +05:30
Sidharth Vinod 66a75e72ea Merge pull request #850 from mermaid-js/develop
Develop
2022-06-19 19:04:31 +05:30
Sidharth Vinod a367bf6499 Merge pull request #840 from mermaid-js/develop
Update mermaid to 9.1.2
2022-06-16 11:16:01 +05:30
27 changed files with 1392 additions and 651 deletions
+8
View File
@@ -0,0 +1,8 @@
docs/**
.svelte-kit/**
static/**
build/**
node_modules/**
coverage/**
__snapshots__/**
snapshots.js
+1 -1
View File
@@ -7,7 +7,7 @@ module.exports = {
// 'plugin:@typescript-eslint/recommended-requiring-type-checking', // 'plugin:@typescript-eslint/recommended-requiring-type-checking',
'prettier' 'prettier'
], ],
plugins: ['svelte3', 'tailwindcss', '@typescript-eslint', 'es'], plugins: ['svelte3', 'tailwindcss', '@typescript-eslint', 'es', 'vitest'],
ignorePatterns: [ ignorePatterns: [
'docs/*', 'docs/*',
'*.cjs', '*.cjs',
@@ -1,4 +1,4 @@
name: Cypress Tests name: Tests
on: on:
pull_request: pull_request:
@@ -30,17 +30,18 @@ jobs:
node-version: 16 node-version: 16
cache: 'yarn' cache: 'yarn'
- name: Build & Lint - name: Lint & Test
run: | run: |
yarn install yarn install
yarn build
yarn lint yarn lint
yarn test:unit
# Install NPM dependencies, cache them correctly # Install NPM dependencies, cache them correctly
# and run all Cypress tests # and run all Cypress tests
- name: Cypress run - name: Cypress run
uses: cypress-io/github-action@v3 uses: cypress-io/github-action@v3
with: with:
build: yarn build
start: yarn preview start: yarn preview
wait-on: 'http://localhost:3000' wait-on: 'http://localhost:3000'
record: true record: true
+2
View File
@@ -3,4 +3,6 @@ docs/**
static/** static/**
build/** build/**
node_modules/** node_modules/**
coverage/**
__snapshots__/**
snapshots.js snapshots.js
+15
View File
@@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "pwa-chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:3000",
"webRoot": "${workspaceFolder}"
}
]
}
+1 -1
View File
@@ -6,7 +6,7 @@ Live editor only has a single version, which will be maintained.
| Version | Supported | | Version | Supported |
| ------- | ------------------ | | ------- | ------------------ |
| latest | :white_check_mark: | | latest | :white_check_mark: |
## Reporting a Vulnerability ## Reporting a Vulnerability
+4 -6
View File
@@ -1,12 +1,10 @@
{ {
"plugins": ["cypress", "mocha"], "plugins": ["cypress"],
"extends": ["plugin:cypress/recommended", "plugin:mocha/recommended"], "extends": ["plugin:cypress/recommended"],
"rules": { "rules": {
"jest/expect-expect": "off", "jest/expect-expect": "off"
"mocha/no-mocha-arrows": "off"
}, },
"env": { "env": {
"cypress/globals": true, "cypress/globals": true
"mocha": true
} }
} }
+17 -8
View File
@@ -1,4 +1,13 @@
describe('Auto sync tests', () => { describe('Auto sync tests', () => {
const cmd = Cypress.platform === 'darwin' ? 'meta' : 'ctrl';
const getEditor = ({ bottom = true, newline = false } = {}) =>
cy
.get('#editor textarea:first')
.click()
.focused()
.type(`${bottom ? '{pageDown}' : `{${cmd}}`}`)
.type(`${newline ? '{enter}' : `{${cmd}}`}`);
beforeEach(() => { beforeEach(() => {
cy.clearLocalStorage(); cy.clearLocalStorage();
cy.visit('/'); cy.visit('/');
@@ -7,7 +16,7 @@ describe('Auto sync tests', () => {
it('should dim diagram when code is edited', () => { it('should dim diagram when code is edited', () => {
cy.contains('Auto sync').click(); cy.contains('Auto sync').click();
cy.get('#view').should('not.have.class', 'outOfSync'); cy.get('#view').should('not.have.class', 'outOfSync');
cy.get('#editor').type(' C --> Test'); getEditor().type(' C --> Test');
cy.get('#view').should('have.class', 'outOfSync'); cy.get('#view').should('have.class', 'outOfSync');
cy.getLocalStorage('codeStore').snapshot(); cy.getLocalStorage('codeStore').snapshot();
}); });
@@ -19,26 +28,25 @@ describe('Auto sync tests', () => {
cy.get('#autoSync').check(); cy.get('#autoSync').check();
cy.get('[data-cy=sync]').should('not.exist'); cy.get('[data-cy=sync]').should('not.exist');
}); });
it('should not dim diagram when code is in sync', () => { it('should not dim diagram when code is in sync', () => {
cy.contains('Auto sync').click(); cy.contains('Auto sync').click();
cy.get('#view').should('not.have.class', 'outOfSync'); cy.get('#view').should('not.have.class', 'outOfSync');
cy.get('#editor').type(' C --> Test'); getEditor().type(' C --> Test');
cy.get('#view').should('have.class', 'outOfSync'); cy.get('#view').should('have.class', 'outOfSync');
cy.get('[data-cy=sync]').click(); cy.get('[data-cy=sync]').click();
cy.get('#view').should('not.have.class', 'outOfSync'); cy.get('#view').should('not.have.class', 'outOfSync');
cy.get('#autoSync').check(); cy.get('#autoSync').check();
cy.get('#editor').type('ing'); getEditor().type('ing');
cy.get('#view').should('not.have.class', 'outOfSync'); cy.get('#view').should('not.have.class', 'outOfSync');
cy.getLocalStorage('codeStore').snapshot(); cy.getLocalStorage('codeStore').snapshot();
}); });
it('supports commenting code out/in', () => { it('supports commenting code out/in', () => {
const cmd = Cypress.platform === 'darwin' ? 'meta' : 'ctrl'; getEditor().type(`{uparrow}{${cmd}}/`);
cy.get('#editor').type(`{uparrow}{${cmd}}/`);
cy.get('#view').contains('Car').should('not.exist'); cy.get('#view').contains('Car').should('not.exist');
cy.get('#editor').type(`{uparrow}{${cmd}}/`); getEditor().type(`{uparrow}{${cmd}}/`);
cy.get('#view').contains('Car').should('exist'); cy.get('#view').contains('Car').should('exist');
}); });
@@ -46,7 +54,8 @@ describe('Auto sync tests', () => {
cy.visit( cy.visit(
'/edit#pako:eNpljjEKwzAMRa8SNOcEnlt6gK5eVFvYJsgOqkwpIXevg9smEE1PnyfxF3DFExgISW-CczQ2D21cYU7a-SGYXRwyvTp9jUhuKlVP-eHy7zA-leQsMEmg_QOM0BLG5FujZVMsaCQmC6ahR5ks2Lw2r84ela4-aREwKpVGwKrl_s7ut3fnkjAIcg_XDzuaUhs' '/edit#pako:eNpljjEKwzAMRa8SNOcEnlt6gK5eVFvYJsgOqkwpIXevg9smEE1PnyfxF3DFExgISW-CczQ2D21cYU7a-SGYXRwyvTp9jUhuKlVP-eHy7zA-leQsMEmg_QOM0BLG5FujZVMsaCQmC6ahR5ks2Lw2r84ela4-aREwKpVGwKrl_s7ut3fnkjAIcg_XDzuaUhs'
); );
cy.get('#editor').type(`{enter}branch test`); cy.get('#errorContainer').should('not.exist');
getEditor({ newline: true }).type(`branch test`);
cy.get('#editor').contains('branch test').should('exist'); cy.get('#editor').contains('branch test').should('exist');
cy.get('#errorContainer') cy.get('#errorContainer')
.contains( .contains(
-1
View File
@@ -47,7 +47,6 @@ describe('Save History', () => {
}); });
// TODO: Fix #639 // TODO: Fix #639
// eslint-disable-next-line mocha/no-skipped-tests
xit('should auto save history', () => { xit('should auto save history', () => {
cy.get('#editor').type(' C --> HistoryTest'); cy.get('#editor').type(' C --> HistoryTest');
cy.tick(70000); cy.tick(70000);
-1
View File
@@ -32,7 +32,6 @@ describe('Test themes', () => {
}); });
describe('Test dark mode', () => { describe('Test dark mode', () => {
// eslint-disable-next-line mocha/no-hooks-for-single-case
beforeEach(() => { beforeEach(() => {
cy.clearLocalStorage(); cy.clearLocalStorage();
cy.visit('/edit', { cy.visit('/edit', {
+1 -1
View File
@@ -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}\",\"updateEditor\":false,\"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\"}}}" "1": "{\"code\":\"graph TD\\n A[Party] -->|Get money| B(Go shopping!!)\\n \",\"mermaid\":\"{\\n \\\"theme\\\": \\\"forest\\\",\\n \\\"test\\\": \\\"hello world\\\"\\n}\",\"updateEditor\":false,\"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": "10.2.0", "__version": "10.3.0",
"Auto sync tests": { "Auto sync tests": {
"should dim diagram when code is edited": { "should dim diagram when code is edited": {
"1": "{\"code\":\"graph 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}\",\"updateEditor\":false,\"autoSync\":false,\"updateDiagram\":false}" "1": "{\"code\":\"graph 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}\",\"updateEditor\":false,\"autoSync\":false,\"updateDiagram\":false}"
+59 -47
View File
@@ -1,67 +1,79 @@
{ {
"name": "mermaid-live-editor", "name": "mermaid-live-editor",
"version": "2.0.67", "version": "2.0.67",
"type": "module",
"license": "MIT",
"scripts": { "scripts": {
"dev": "svelte-kit dev --host 0.0.0.0", "dev": "vite dev --host 0.0.0.0",
"build": "svelte-kit build", "build": "vite build",
"preview": "svelte-kit preview", "preview": "vite preview",
"lint": "prettier --check --cache --plugin-search-dir=. .;eslint --ignore-path .gitignore .", "lint": "prettier --check --cache --plugin-search-dir=. .;eslint --ignore-path .gitignore .",
"lint:fix": "prettier --write --cache --plugin-search-dir=. .;eslint --fix --ignore-path .gitignore .", "lint:fix": "prettier --write --cache --plugin-search-dir=. .;eslint --fix --ignore-path .gitignore .",
"format": "prettier --write --cache --plugin-search-dir=. .", "format": "prettier --write --cache --plugin-search-dir=. .",
"pre-commit": "lint-staged", "pre-commit": "lint-staged",
"postinstall": "husky install; cypress cache prune", "postinstall": "husky install; cypress cache prune; svelte-kit sync",
"test": "cypress run", "test:unit": "vitest",
"test:ui": "vitest --ui",
"test:coverage": "vitest run --coverage",
"test:browser": "cypress run",
"test": "test:unit && test:browser",
"cy": "cypress open" "cy": "cypress open"
}, },
"devDependencies": { "devDependencies": {
"@cypress/snapshot": "^2.1.7", "@cypress/snapshot": "2.1.7",
"@sveltejs/adapter-static": "1.0.0-next.34", "@sveltejs/adapter-static": "1.0.0-next.34",
"@sveltejs/kit": "1.0.0-next.354", "@sveltejs/kit": "1.0.0-next.359",
"@types/mermaid": "^8.2.9", "@testing-library/jest-dom": "5.16.4",
"@types/pako": "^1.0.3", "@testing-library/svelte": "3.1.3",
"@typescript-eslint/eslint-plugin": "^4.33.0", "@types/mermaid": "8.2.9",
"@typescript-eslint/parser": "^4.33.0", "@types/pako": "1.0.3",
"autoprefixer": "^10.4.7", "@typescript-eslint/eslint-plugin": "5.30.5",
"chai": "^4.3.6", "@typescript-eslint/parser": "5.30.5",
"cssnano": "^5.1.12", "@vitest/ui": "0.17.0",
"cy-verify-downloads": "^0.1.8", "autoprefixer": "10.4.7",
"cypress": "10.2.0", "c8": "7.11.3",
"cypress-localstorage-commands": "^2.1.0", "chai": "4.3.6",
"eslint": "^7.32.0", "cssnano": "5.1.12",
"eslint-config-prettier": "^8.5.0", "cy-verify-downloads": "0.1.8",
"eslint-plugin-cypress": "^2.12.1", "cypress": "10.3.0",
"eslint-plugin-es": "^4.1.0", "cypress-localstorage-commands": "2.1.0",
"eslint-plugin-mocha": "^10.0.5", "eslint": "8.19.0",
"eslint-plugin-postcss-modules": "^2.0.0", "eslint-config-prettier": "8.5.0",
"eslint-plugin-svelte3": "^3.4.1", "eslint-plugin-cypress": "2.12.1",
"eslint-plugin-tailwindcss": "^3.5.2", "eslint-plugin-es": "4.1.0",
"husky": "^8.0.1", "eslint-plugin-postcss-modules": "2.0.0",
"lint-staged": "13.0.2", "eslint-plugin-svelte3": "4.0.0",
"mocha": "^10.0.0", "eslint-plugin-tailwindcss": "3.6.0",
"node-html-parser": "^5.3.3", "eslint-plugin-vitest": "0.0.8",
"postcss": "^8.4.14", "husky": "8.0.1",
"postcss-load-config": "^4.0.1", "jsdom": "20.0.0",
"prettier": "~2.7.1", "lint-staged": "13.0.3",
"prettier-plugin-svelte": "^2.7.0", "node-html-parser": "5.3.3",
"svelte": "^3.48.0", "postcss": "8.4.14",
"postcss-load-config": "4.0.1",
"prettier": "2.7.1",
"prettier-plugin-svelte": "2.7.0",
"svelte": "3.48.0",
"svelte-preprocess": "4.10.7", "svelte-preprocess": "4.10.7",
"tailwindcss": "^3.1.4", "tailwindcss": "3.1.4",
"tslib": "^2.4.0", "tslib": "2.4.0",
"typescript": "^4.7.3" "typescript": "4.7.4",
"vite": "2.9.13",
"vitest": "0.17.0",
"vitest-svelte-kit": "0.0.6"
}, },
"type": "module",
"dependencies": { "dependencies": {
"@analytics/google-analytics": "^0.5.3", "@analytics/google-analytics": "0.5.3",
"@macfja/svelte-persistent-store": "^1.3.0", "@macfja/svelte-persistent-store": "1.3.0",
"analytics": "^0.8.1", "analytics": "0.8.1",
"daisyui": "2.17.0", "daisyui": "2.17.0",
"js-base64": "^3.7.2", "js-base64": "3.7.2",
"mermaid": "9.1.2", "mermaid": "9.1.3",
"moment": "^2.29.3", "moment": "2.29.4",
"monaco-editor": "^0.33.0", "monaco-editor": "0.33.0",
"monaco-mermaid": "^1.0.6", "monaco-mermaid": "1.0.6",
"pako": "2.0.4", "pako": "2.0.4",
"random-word-slugs": "^0.1.6" "random-word-slugs": "0.1.6"
}, },
"lint-staged": { "lint-staged": {
"*.{ts,svelte,js,css,md,json}": [ "*.{ts,svelte,js,css,md,json}": [
+14
View File
@@ -1 +1,15 @@
/* eslint-disable @typescript-eslint/no-empty-interface */
/* eslint-disable @typescript-eslint/ban-types */
/* eslint-disable @typescript-eslint/no-unused-vars */
/// <reference types="@sveltejs/kit" /> /// <reference types="@sveltejs/kit" />
import type { TestingLibraryMatchers } from '@testing-library/jest-dom/matchers';
declare global {
namespace jest {
interface Matchers<R = void>
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
extends TestingLibraryMatchers<typeof expect.stringContaining, R> {}
}
}
+1 -1
View File
@@ -1,4 +1,4 @@
import type { Handle } from '@sveltejs/kit/types/hooks'; import type { Handle } from '@sveltejs/kit';
export const handle: Handle = async ({ event, resolve }) => { export const handle: Handle = async ({ event, resolve }) => {
const response = await resolve(event, { const response = await resolve(event, {
+1
View File
@@ -57,6 +57,7 @@
const svgEl: HTMLElement = document const svgEl: HTMLElement = document
.querySelector('#container svg') .querySelector('#container svg')
.cloneNode(true) as HTMLElement; .cloneNode(true) as HTMLElement;
svgEl.setAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
const fontAwesomeCdnUrl = Array.from(document.head.getElementsByTagName('link')) const fontAwesomeCdnUrl = Array.from(document.head.getElementsByTagName('link'))
.map((l) => l.href) .map((l) => l.href)
.find((h) => h && h.includes('font-awesome')); .find((h) => h && h.includes('font-awesome'));
@@ -0,0 +1,3 @@
// Vitest Snapshot v1
exports[`card.svelte > mounts 1`] = `"<div><div class=\\"card rounded overflow-hidden m-2 flex-grow flex flex-col shadow-2xl\\"><div class=\\"bg-primary p-2 pb-0 flex-none cursor-pointer\\"><div class=\\"flex justify-between\\"><div class=\\"flex cursor-default s-_wx1E_JHsCoF\\"><span class=\\"mr-2 font-semibold s-_wx1E_JHsCoF\\"><i class=\\"fas fa-chevron-right icon s-_wx1E_JHsCoF isOpen\\"></i> TabTest</span> <ul class=\\"tabs s-_wx1E_JHsCoF\\"><div class=\\"tab tab-lifted tab-active s-_wx1E_JHsCoF\\"><i class=\\"mr-1 undefined s-_wx1E_JHsCoF\\"></i> title1 </div><div class=\\"tab tab-lifted text-primary-content s-_wx1E_JHsCoF\\"><i class=\\"mr-1 undefined s-_wx1E_JHsCoF\\"></i> title2 </div></ul></div><!--<Tabs>--> <div class=\\"flex gap-x-4 items-center -mt-2\\"></div></div></div> <div class=\\"card-body p-0 flex-grow overflow-auto text-base-content\\"></div></div><!--<Card>--></div>"`;
+24
View File
@@ -0,0 +1,24 @@
import { cleanup, render } from '@testing-library/svelte';
import { describe, expect, it, afterEach } from 'vitest';
import Card from './card.svelte';
describe('card.svelte', () => {
// TODO: @testing-library/svelte claims to add this automatically but it doesn't work without explicit afterEach
afterEach(() => cleanup());
it('mounts', () => {
const { container } = render(Card, {
title: 'TabTest',
tabs: [
{ id: 't1', title: 'title1' },
{ id: 't2', title: 'title2' }
]
});
expect(container).toBeTruthy();
expect(container).toHaveTextContent('TabTest');
expect(container).toHaveTextContent('title1');
expect(container).toHaveTextContent('title2');
expect(container).not.toHaveTextContent('title3');
expect(container.innerHTML).toMatchSnapshot();
});
});
+1 -1
View File
@@ -43,7 +43,7 @@ export interface State {
} }
export interface ValidatedState extends State { export interface ValidatedState extends State {
error: any; error: unknown;
errorMarkers: MarkerData[]; errorMarkers: MarkerData[];
serialized: string; serialized: string;
} }
+2
View File
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-unsafe-return */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */ /* eslint-disable @typescript-eslint/no-unsafe-assignment */
/* eslint-disable @typescript-eslint/no-unsafe-member-access */ /* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/no-explicit-any */
@@ -43,6 +44,7 @@ const getGistData = async (gistURL: string): Promise<GistData> => {
} }
const currentItem = history[0]; const currentItem = history[0];
return { return {
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
url: `${html_url}/${currentItem.version}`, url: `${html_url}/${currentItem.version}`,
code, code,
config, config,
+3
View File
@@ -23,6 +23,9 @@ export const loadDataFromUrl = async (): Promise<void> => {
config = defaultState.mermaid; config = defaultState.mermaid;
} }
if (!code) { if (!code) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
for (const [key, value] of searchParams.entries()) { for (const [key, value] of searchParams.entries()) {
if (key in loaders) { if (key in loaders) {
try { try {
+40
View File
@@ -0,0 +1,40 @@
import { describe, expect, it } from 'vitest';
import { serializeState, deserializeState, type SerdeType } from './serde';
import { defaultState } from './state';
import type { State } from '$lib/types';
describe('Serde tests', () => {
const verifySerde = (state: State, serde?: SerdeType): string => {
const serialized = serializeState(state, serde);
const deserialized = deserializeState(serialized);
expect(deserialized).to.deep.equal(state);
return serialized;
};
it('should serialize and deserialize with default serde', () => {
expect(verifySerde(defaultState)).toMatchInlineSnapshot(
'"pako:eNpVkM1qw0AMhF9F6JRC_AI-FBo7ySXQQnPz5iC8cnZp9oe1TAm2373rmEKik5j5ZhAasQ2ascRromjgXCsPeT6ayiTbi6P-AkXxPh1ZwAXP9wl2m2OA3oQYrb--rfxugaAaTwvGIMb6n3m1qkf-0_MEdXOiKCFenp3zb5hg39gvk-tfHZM4pw5NR2VHRUsJKkoPBLfoODmyOp8-LopCMexYYZlXzR0NN1Go_JzRIWoS3msrIWGuuvW8RRokfN99i6Wkgf-h2lL-hFvF-Q9-YFyS"'
);
});
it('should serialize and deserialize with base64 serde', () => {
expect(verifySerde(defaultState, 'base64')).toMatchInlineSnapshot(
'"base64:eyJjb2RlIjoiZ3JhcGggVERcbiAgICBBW0NocmlzdG1hc10gLS0-fEdldCBtb25leXwgQihHbyBzaG9wcGluZylcbiAgICBCIC0tPiBDe0xldCBtZSB0aGlua31cbiAgICBDIC0tPnxPbmV8IERbTGFwdG9wXVxuICAgIEMgLS0-fFR3b3wgRVtpUGhvbmVdXG4gICAgQyAtLT58VGhyZWV8IEZbZmE6ZmEtY2FyIENhcl1cbiAgIiwibWVybWFpZCI6IntcbiAgXCJ0aGVtZVwiOiBcImRlZmF1bHRcIlxufSIsInVwZGF0ZUVkaXRvciI6ZmFsc2UsImF1dG9TeW5jIjp0cnVlLCJ1cGRhdGVEaWFncmFtIjp0cnVlfQ"'
);
});
it('should serialize and deserialize with pako serde', () => {
expect(verifySerde(defaultState, 'pako')).toMatchInlineSnapshot(
'"pako:eNpVkM1qw0AMhF9F6JRC_AI-FBo7ySXQQnPz5iC8cnZp9oe1TAm2373rmEKik5j5ZhAasQ2ascRromjgXCsPeT6ayiTbi6P-AkXxPh1ZwAXP9wl2m2OA3oQYrb--rfxugaAaTwvGIMb6n3m1qkf-0_MEdXOiKCFenp3zb5hg39gvk-tfHZM4pw5NR2VHRUsJKkoPBLfoODmyOp8-LopCMexYYZlXzR0NN1Go_JzRIWoS3msrIWGuuvW8RRokfN99i6Wkgf-h2lL-hFvF-Q9-YFyS"'
);
});
it('should throw error for unrecognized serde', () => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
expect(() => serializeState(defaultState, 'unknown')).toThrowError(
'Unknown serde type: unknown'
);
expect(() => deserializeState('unknown:hello')).toThrowError('Unknown serde type: unknown');
});
});
+10 -8
View File
@@ -28,18 +28,20 @@ export const pakoSerde: Serde = {
} }
}; };
const serdes: { [key: string]: Serde } = { export type SerdeType = 'base64' | 'pako';
const serdes: { [key in SerdeType]: Serde } = {
base64: base64Serde, base64: base64Serde,
pako: pakoSerde pako: pakoSerde
}; };
type SerdeType = keyof typeof serdes; export const serializeState = (state: State, serde: SerdeType = 'pako'): string => {
if (serdes[serde] === undefined) {
export const serializeState = (state: State): string => { throw new Error(`Unknown serde type: ${serde}`);
}
const json = JSON.stringify(state); const json = JSON.stringify(state);
const defaultSerde: SerdeType = 'pako'; const serialized = serdes[serde].serialize(json);
const serialized = serdes[defaultSerde].serialize(json); return `${serde}:${serialized}`;
return `${defaultSerde}:${serialized}`;
}; };
export const deserializeState = (state: string): State => { export const deserializeState = (state: string): State => {
@@ -48,7 +50,7 @@ export const deserializeState = (state: string): State => {
let tempType: string; let tempType: string;
[tempType, serialized] = state.split(':'); [tempType, serialized] = state.split(':');
if (tempType in serdes) { if (tempType in serdes) {
type = tempType; type = tempType as SerdeType;
} else { } else {
throw new Error(`Unknown serde type: ${tempType}`); throw new Error(`Unknown serde type: ${tempType}`);
} }
+4
View File
@@ -0,0 +1,4 @@
import matchers from '@testing-library/jest-dom/matchers';
import { expect } from 'vitest';
expect.extend(matchers);
-4
View File
@@ -20,10 +20,6 @@ const config = {
} }
: {}, : {},
trailingSlash: 'ignore', trailingSlash: 'ignore',
vite: {
envPrefix: 'MERMAID_',
optimizeDeps: { include: ['mermaid'] }
},
prerender: { prerender: {
default: true default: true
} }
+3 -1
View File
@@ -8,7 +8,9 @@
"static/**/*.js" "static/**/*.js"
], ],
"compilerOptions": { "compilerOptions": {
"allowSyntheticDefaultImports": true "resolveJsonModule": true,
"allowSyntheticDefaultImports": true,
"types": ["vitest/importMeta"]
}, },
"extends": "./.svelte-kit/tsconfig.json" "extends": "./.svelte-kit/tsconfig.json"
} }
+21
View File
@@ -0,0 +1,21 @@
import { sveltekit } from '@sveltejs/kit/vite';
/** @type {import('vite').UserConfig} */
const config = {
plugins: [sveltekit()],
envPrefix: 'MERMAID_',
optimizeDeps: { include: ['mermaid'] },
ssr: {
noExternal: ['@macfja/svelte-persistent-store']
},
test: {
environment: 'jsdom',
// in-source testing
includeSource: ['src/**/*.{js,ts,svelte}'],
setupFiles: ['./src/tests/setup.ts'],
coverage: {
exclude: ['src/mocks', '.svelte-kit', 'src/**/*.test.ts'],
reporter: ['text', 'json', 'html', 'lcov']
}
}
};
export default config;
+1153 -567
View File
File diff suppressed because it is too large Load Diff