Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.
Go dockerfossgomarkdownmemomicroblognote-takingnotesopen-sourceown-your-datareactself-hostedsqlitetimeline
fix: update marked test cases
stevenb959acc69dc7
diff --git a/web/jest.config.js b/web/jest.config.jsindex 9302e6e57..446412e00 100644--- a/web/jest.config.js+++ b/web/jest.config.js@@ -3,4 +3,7 @@module.exports = {preset: "ts-jest",testEnvironment: "node",+ moduleNameMapper: {+ "lodash-es": "lodash",+ },};diff --git a/web/package.json b/web/package.jsonindex 3ceb3c5e1..89716fe21 100644--- a/web/package.json+++ b/web/package.json@@ -40,6 +40,7 @@"eslint-plugin-react": "^7.27.1","jest": "^29.1.2","less": "^4.1.1",+ "lodash": "^4.17.21","postcss": "^8.4.5","prettier": "2.5.1","tailwindcss": "^3.0.18",diff --git a/web/src/components/Memo.tsx b/web/src/components/Memo.tsxindex 5844cdaa6..976b262d7 100644--- a/web/src/components/Memo.tsx+++ b/web/src/components/Memo.tsx@@ -1,6 +1,5 @@import dayjs from "dayjs";import relativeTime from "dayjs/plugin/relativeTime";-import { indexOf } from "lodash-es";import { memo, useEffect, useRef, useState } from "react";import { useTranslation } from "react-i18next";import { useNavigate } from "react-router-dom";@@ -132,7 +131,7 @@ const Memo: React.FC<Props> = (props: Props) => {const todoElementList = [...(memoContainerRef.current?.querySelectorAll(`span.todo-block[data-value=${status}]`) ?? [])];for (const element of todoElementList) {if (element === targetEl) {- const index = indexOf(todoElementList, element);+ const index = todoElementList.indexOf(element);const tempList = memo.content.split(status === "DONE" ? /- \[x\] / : /- \[ \] /);let finalContent = "";diff --git a/web/src/components/Settings/MemberSection.tsx b/web/src/components/Settings/MemberSection.tsxindex 0c6019dda..ad4980d03 100644--- a/web/src/components/Settings/MemberSection.tsx+++ b/web/src/components/Settings/MemberSection.tsx@@ -1,4 +1,3 @@-import { isEmpty } from "lodash-es";import React, { useEffect, useState } from "react";import { useTranslation } from "react-i18next";import { userService } from "../../services";@@ -47,7 +46,7 @@ const PreferencesSection = () => {};const handleCreateUserBtnClick = async () => {- if (isEmpty(state.createUserEmail) || isEmpty(state.createUserPassword)) {+ if (state.createUserEmail === "" || state.createUserPassword === "") {toastHelper.error(t("message.fill-form"));return;}diff --git a/web/src/helpers/utils.ts b/web/src/helpers/utils.tsindex 86541e1c8..bbc314eed 100644--- a/web/src/helpers/utils.ts+++ b/web/src/helpers/utils.ts@@ -1,7 +1,5 @@-import { assign, isNull, isUndefined } from "lodash-es";-export const isNullorUndefined = (value: any) => {- return isNull(value) || isUndefined(value);+ return value === null || value === undefined;};export function getNowTimeStamp(): number {@@ -96,7 +94,7 @@ export const getElementBounding = (element: HTMLElement, relativeEl?: HTMLElemen};if ((relativeEl.tagName !== "BODY" && relativeElPosition === "relative") || relativeElPosition === "sticky") {- return assign(bounding, {+ return Object.assign(bounding, {top: elementRect.top - relativeElRect.top,left: elementRect.left - relativeElRect.left,});@@ -117,13 +115,13 @@ export const getElementBounding = (element: HTMLElement, relativeEl?: HTMLElemen};if (isElementFixed(element)) {- return assign(bounding, {+ return Object.assign(bounding, {top: elementRect.top,left: elementRect.left,});}- return assign(bounding, {+ return Object.assign(bounding, {top: elementRect.top + scrollTop,left: elementRect.left + scrollLeft,});diff --git a/web/src/labs/marked/index.ts b/web/src/labs/marked/index.tsindex bafa9194b..c7580be89 100644--- a/web/src/labs/marked/index.ts+++ b/web/src/labs/marked/index.ts@@ -27,6 +27,10 @@ export const marked = (markdownStr: string, blockParsers = blockElementParserLislet matchedIndex = -1;for (const parser of inlineElementParserList) {+ if (parser.name === "plain text" && matchedInlineParser !== undefined) {+ continue;+ }+const startIndex = markdownStr.search(parser.regex);const matchedLength = match(markdownStr, parser.regex);diff --git a/web/src/labs/marked/marked.test.ts b/web/src/labs/marked/marked.test.tsindex ecb790711..9581fd3ca 100644--- a/web/src/labs/marked/marked.test.ts+++ b/web/src/labs/marked/marked.test.ts@@ -1,4 +1,5 @@import { describe, expect, test } from "@jest/globals";+import { unescape } from "lodash-es";import { marked } from ".";describe("test marked parser", () => {@@ -27,7 +28,7 @@ console.log("hello world!")];for (const t of tests) {- expect(marked(t.markdown)).toBe(t.want);+ expect(unescape(marked(t.markdown))).toBe(t.want);}});test("parse todo list block", () => {@@ -43,7 +44,7 @@ console.log("hello world!")];for (const t of tests) {- expect(marked(t.markdown)).toBe(t.want);+ expect(unescape(marked(t.markdown))).toBe(t.want);}});test("parse list block", () => {@@ -59,7 +60,7 @@ console.log("hello world!")];for (const t of tests) {- expect(marked(t.markdown)).toBe(t.want);+ expect(unescape(marked(t.markdown))).toBe(t.want);}});test("parse inline element", () => {@@ -71,7 +72,7 @@ console.log("hello world!")];for (const t of tests) {- expect(marked(t.markdown)).toBe(t.want);+ expect(unescape(marked(t.markdown))).toBe(t.want);}});test("parse plain link", () => {@@ -83,7 +84,7 @@ console.log("hello world!")];for (const t of tests) {- expect(marked(t.markdown)).toBe(t.want);+ expect(unescape(marked(t.markdown))).toBe(t.want);}});test("parse inline code", () => {@@ -95,7 +96,7 @@ console.log("hello world!")];for (const t of tests) {- expect(marked(t.markdown)).toBe(t.want);+ expect(unescape(marked(t.markdown))).toBe(t.want);}});test("parse bold and em text", () => {@@ -119,7 +120,7 @@ console.log("hello world!")];for (const t of tests) {- expect(marked(t.markdown)).toBe(t.want);+ expect(unescape(marked(t.markdown))).toBe(t.want);}});});diff --git a/web/src/services/userService.ts b/web/src/services/userService.tsindex 4ed4acbdb..68933eb26 100644--- a/web/src/services/userService.ts+++ b/web/src/services/userService.ts@@ -1,4 +1,3 @@-import { isUndefined } from "lodash-es";import { locationService } from ".";import * as api from "../helpers/api";import store from "../store";@@ -58,7 +57,7 @@ const userService = {},isVisitorMode: () => {- return !isUndefined(userService.getUserIdFromPath());+ return !(userService.getUserIdFromPath() === undefined);},getUserIdFromPath: () => {diff --git a/web/yarn.lock b/web/yarn.lockindex 33f1d1578..b16ebd61a 100644--- a/web/yarn.lock+++ b/web/yarn.lock@@ -2927,6 +2927,11 @@ lodash.merge@^4.6.2:resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-4.6.2.tgz#558aa53b43b661e1925a0afdfa36a9a1085fe57a"integrity sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==+lodash@^4.17.21:+ version "4.17.21"+ resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"+ integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==+loose-envify@^1.1.0, loose-envify@^1.4.0:version "1.4.0"resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf"