From 16540f3005d6d015705a3634d629fe0e47691fc5 Mon Sep 17 00:00:00 2001 From: Alois Klink Date: Thu, 12 Jan 2023 23:55:31 +0000 Subject: [PATCH] test(docs): fix test failure due to bad merge Fixes a semantic merge conflict due to the PRs: - https://github.com/mermaid-js/mermaid/pull/3954 Changed `docs.mts` to use a remark object created by `remark()` - https://github.com/mermaid-js/mermaid/pull/3946 Added test code that mocked the frozen remark object (e.g. `remark` not `remark()`). To fix this issue, we can mock `remark()` so that it always returns the same remark object, which can then be used the `docs.mts` script, as well as spied on in the `docs.spec.ts` test file. Reported-by: Sidharth Vinod --- packages/mermaid/src/docs.spec.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/packages/mermaid/src/docs.spec.ts b/packages/mermaid/src/docs.spec.ts index 3f7465ee4..2d27a6b23 100644 --- a/packages/mermaid/src/docs.spec.ts +++ b/packages/mermaid/src/docs.spec.ts @@ -1,7 +1,21 @@ import { transformBlocks, transformToBlockQuote } from './docs.mjs'; -import { remark } from 'remark'; // import it this way so we can mock it -vi.mock('remark'); +import { remark as remarkBuilder } from 'remark'; // import it this way so we can mock it + +const remark = remarkBuilder(); + +vi.mock('remark', async (importOriginal) => { + const { remark: originalRemarkBuilder } = (await importOriginal()) as { + remark: typeof remarkBuilder; + }; + + // make sure that both `docs.mts` and this test file are using the same remark + // object so that we can mock it + const sharedRemark = originalRemarkBuilder(); + return { + remark: () => sharedRemark, + }; +}); afterEach(() => { vi.restoreAllMocks();