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 <sidharthv96@gmail.com>
This commit is contained in:
Alois Klink 2023-01-12 23:55:31 +00:00
parent 6c862565aa
commit 16540f3005
1 changed files with 16 additions and 2 deletions

View File

@ -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();