Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from mermaid-js:master #13

Merged
merged 24 commits into from
Jul 9, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
5b98232
fix #783: Add sub-resource integrity (SRI) hash to all CDN resources
jonmbake Jun 30, 2022
1c6371c
Add vitest
sidharthv96 Jul 6, 2022
e04bb15
Add dom testing
sidharthv96 Jul 6, 2022
b4fe60d
Remove mocha
sidharthv96 Jul 6, 2022
4c965fb
Cypress
sidharthv96 Jul 6, 2022
79fb9d1
Pin versions; Fix svelte kit
sidharthv96 Jul 6, 2022
0ea5d81
Fix cypress
sidharthv96 Jul 6, 2022
31de1c7
Fix security formatting.
sidharthv96 Jul 6, 2022
cab7ae5
Merge branch 'master' into vitest
sidharthv96 Jul 6, 2022
861fd44
Fix test
sidharthv96 Jul 6, 2022
1058565
Fix test
sidharthv96 Jul 6, 2022
e69b4de
Fix test
sidharthv96 Jul 6, 2022
1ab98b5
Merge pull request #878 from mermaid-js/vitest
sidharthv96 Jul 7, 2022
fb91377
chore(deps-dev): bump vitest from 0.17.0 to 0.17.1 (#880)
dependabot[bot] Jul 8, 2022
e410f77
chore(deps-dev): bump @sveltejs/kit (#882)
dependabot[bot] Jul 8, 2022
e39254d
chore(deps-dev): bump tailwindcss from 3.1.4 to 3.1.5 (#884)
dependabot[bot] Jul 8, 2022
8c37a3b
chore(deps-dev): bump svelte from 3.48.0 to 3.49.0 (#881)
dependabot[bot] Jul 8, 2022
852d426
chore(deps-dev): bump @vitest/ui from 0.17.0 to 0.17.1 (#883)
dependabot[bot] Jul 8, 2022
d7388b0
Use 'node-html-parser'
sidharthv96 Jul 8, 2022
185fd55
Merge pull request #869 from jonmbake/add-integrity-hash-sri
sidharthv96 Jul 8, 2022
67a4cff
Install deps before updating monaco
sidharthv96 Jul 8, 2022
57df1cf
Merge pull request #886 from mermaid-js/develop
sidharthv96 Jul 8, 2022
950de30
improve button to be link
johannchopin Jul 8, 2022
91c3564
Merge pull request #888 from johannchopin/feature/improve-view-button
sidharthv96 Jul 9, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add vitest
  • Loading branch information
sidharthv96 committed Jul 6, 2022
commit 1c6371cb8cab29f17d6e2d1cf8691e2df7b088d3
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Cypress Tests
name: Tests

on:
pull_request:
Expand Down Expand Up @@ -36,6 +36,9 @@ jobs:
yarn build
yarn lint

- name: Unit Tests
run: yarn test:unit

# Install NPM dependencies, cache them correctly
# and run all Cypress tests
- name: Cypress run
Expand Down
13 changes: 11 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,24 @@
"format": "prettier --write --cache --plugin-search-dir=. .",
"pre-commit": "lint-staged",
"postinstall": "husky install; cypress cache prune",
"test": "cypress run",
"test:unit": "vitest",
"test:coverage": "vitest run --coverage",
"test:browser": "cypress run",
"test": "test:unit && test:browser",
"cy": "cypress open"
},
"devDependencies": {
"@cypress/snapshot": "^2.1.7",
"@sveltejs/adapter-static": "1.0.0-next.34",
"@sveltejs/kit": "1.0.0-next.359",
"@testing-library/jest-dom": "^5.16.4",
"@testing-library/svelte": "^3.1.3",
"@types/mermaid": "^8.2.9",
"@types/pako": "^1.0.3",
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
"autoprefixer": "^10.4.7",
"c8": "^7.11.3",
"chai": "^4.3.6",
"cssnano": "^5.1.12",
"cy-verify-downloads": "^0.1.8",
Expand All @@ -38,8 +44,10 @@
"eslint-plugin-svelte3": "^3.4.1",
"eslint-plugin-tailwindcss": "^3.6.0",
"husky": "^8.0.1",
"jsdom": "^20.0.0",
"lint-staged": "13.0.3",
"mocha": "^10.0.0",
"msw": "^0.43.0",
"node-html-parser": "^5.3.3",
"postcss": "^8.4.14",
"postcss-load-config": "^4.0.1",
Expand All @@ -50,7 +58,8 @@
"tailwindcss": "^3.1.4",
"tslib": "^2.4.0",
"typescript": "^4.7.4",
"vite": "^2.9.13"
"vite": "^2.9.13",
"vitest": "^0.17.0"
},
"dependencies": {
"@analytics/google-analytics": "^0.5.3",
Expand Down
40 changes: 40 additions & 0 deletions src/lib/util/serde.test.ts
Original file line number Diff line number Diff line change
@@ -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');
});
});
18 changes: 10 additions & 8 deletions src/lib/util/serde.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
pako: pakoSerde
};

type SerdeType = keyof typeof serdes;

export const serializeState = (state: State): string => {
export const serializeState = (state: State, serde: SerdeType = 'pako'): string => {
if (serdes[serde] === undefined) {
throw new Error(`Unknown serde type: ${serde}`);
}
const json = JSON.stringify(state);
const defaultSerde: SerdeType = 'pako';
const serialized = serdes[defaultSerde].serialize(json);
return `${defaultSerde}:${serialized}`;
const serialized = serdes[serde].serialize(json);
return `${serde}:${serialized}`;
};

export const deserializeState = (state: string): State => {
Expand All @@ -48,7 +50,7 @@ export const deserializeState = (state: string): State => {
let tempType: string;
[tempType, serialized] = state.split(':');
if (tempType in serdes) {
type = tempType;
type = tempType as SerdeType;
} else {
throw new Error(`Unknown serde type: ${tempType}`);
}
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"static/**/*.js"
],
"compilerOptions": {
"allowSyntheticDefaultImports": true
"allowSyntheticDefaultImports": true,
"types": ["vitest/importMeta"]
},
"extends": "./.svelte-kit/tsconfig.json"
}
15 changes: 14 additions & 1 deletion vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@ import { sveltekit } from '@sveltejs/kit/vite';
const config = {
plugins: [sveltekit()],
envPrefix: 'MERMAID_',
optimizeDeps: { include: ['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;
Loading