Skip to content

Commit

Permalink
test(docs): fix test failure due to bad merge
Browse files Browse the repository at this point in the history
Fixes a semantic merge conflict due to the PRs:
  - mermaid-js#3954
    Changed `docs.mts` to use a remark object created by `remark()`
  - mermaid-js#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 <[email protected]>
  • Loading branch information
aloisklink committed Jan 13, 2023
1 parent 6c86256 commit 16540f3
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions packages/mermaid/src/docs.spec.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand Down

0 comments on commit 16540f3

Please sign in to comment.