Compare commits
34
Commits
fix/dataFlow
...
vitest
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e69b4def13 | ||
|
|
10585650fd | ||
|
|
861fd442c2 | ||
|
|
cab7ae5f65 | ||
|
|
31de1c79aa | ||
|
|
0ea5d812b2 | ||
|
|
79fb9d1cb1 | ||
|
|
4c965fbe2e | ||
|
|
b4fe60d49c | ||
|
|
e04bb15c35 | ||
|
|
1c6371cb8c | ||
|
|
0b89c8d7e8 | ||
|
|
bb536e9c36 | ||
|
|
76c421924c | ||
|
|
0e331a42d8 | ||
|
|
9cd19f2a81 | ||
|
|
a08d392b1b | ||
|
|
54cdae4f40 | ||
|
|
caa536b781 | ||
|
|
a2d95320b8 | ||
|
|
3009619e79 | ||
|
|
6977a3d4a3 | ||
|
|
e83e287546 | ||
|
|
30d67e1d6f | ||
|
|
5d66248c78 | ||
|
|
754f80dd94 | ||
|
|
2cff54b33d | ||
|
|
ddc1291d1b | ||
|
|
dd17fd7e3f | ||
|
|
ac7cfbd286 | ||
|
|
19b1ca9b2e | ||
|
|
a4e10b936b | ||
|
|
66a75e72ea | ||
|
|
a367bf6499 |
@@ -0,0 +1,8 @@
|
|||||||
|
docs/**
|
||||||
|
.svelte-kit/**
|
||||||
|
static/**
|
||||||
|
build/**
|
||||||
|
node_modules/**
|
||||||
|
coverage/**
|
||||||
|
__snapshots__/**
|
||||||
|
snapshots.js
|
||||||
+1
-1
@@ -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
|
||||||
@@ -3,4 +3,6 @@ docs/**
|
|||||||
static/**
|
static/**
|
||||||
build/**
|
build/**
|
||||||
node_modules/**
|
node_modules/**
|
||||||
|
coverage/**
|
||||||
|
__snapshots__/**
|
||||||
snapshots.js
|
snapshots.js
|
||||||
Vendored
+15
@@ -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
@@ -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
@@ -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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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(
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
@@ -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', {
|
||||||
|
|||||||
@@ -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
@@ -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}": [
|
||||||
|
|||||||
Vendored
+14
@@ -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
@@ -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, {
|
||||||
|
|||||||
@@ -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>"`;
|
||||||
@@ -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();
|
||||||
|
});
|
||||||
|
});
|
||||||
Vendored
+1
-1
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
@@ -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
@@ -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}`);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
import matchers from '@testing-library/jest-dom/matchers';
|
||||||
|
import { expect } from 'vitest';
|
||||||
|
|
||||||
|
expect.extend(matchers);
|
||||||
@@ -20,10 +20,6 @@ const config = {
|
|||||||
}
|
}
|
||||||
: {},
|
: {},
|
||||||
trailingSlash: 'ignore',
|
trailingSlash: 'ignore',
|
||||||
vite: {
|
|
||||||
envPrefix: 'MERMAID_',
|
|
||||||
optimizeDeps: { include: ['mermaid'] }
|
|
||||||
},
|
|
||||||
prerender: {
|
prerender: {
|
||||||
default: true
|
default: true
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-1
@@ -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"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
Reference in New Issue
Block a user