WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit fdecfd5

Browse files
Chore: Tests: Make renderBlockImages.test.ts less likely to fail in CI
1 parent f9d5874 commit fdecfd5

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

packages/editor/CodeMirror/extensions/rendering/renderBlockImages.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ const allowImageUrlsToBeFetched = async () => {
99
await Promise.resolve();
1010
};
1111

12-
const createEditor = async (initialMarkdown: string, hasImage: boolean) => {
12+
const createEditor = async (initialMarkdown: string, expectedTags: string[] = ['Image']) => {
1313
const resolveImageSrc = jest.fn((src, counter) => Promise.resolve(`${src}?r=${counter}`));
1414
const editor = await createTestEditor(
1515
initialMarkdown,
1616
EditorSelection.cursor(0),
17-
hasImage ? ['Image'] : [],
17+
expectedTags,
1818
[renderBlockImages({ resolveImageSrc })],
1919
);
2020
await allowImageUrlsToBeFetched();
@@ -40,7 +40,7 @@ describe('renderBlockImages', () => {
4040
{ spaceBefore: ' ', spaceAfter: ' ', alt: 'test' },
4141
{ spaceBefore: '', spaceAfter: '', alt: '!!!!' },
4242
])('should render images below their Markdown source (case %#)', async ({ spaceBefore, spaceAfter, alt }) => {
43-
const editor = await createEditor(`${spaceBefore}![${alt}](:/0123456789abcdef0123456789abcdef)${spaceAfter}`, true);
43+
const editor = await createEditor(`${spaceBefore}![${alt}](:/0123456789abcdef0123456789abcdef)${spaceAfter}`);
4444

4545
const images = findImages(editor);
4646
expect(images).toHaveLength(1);
@@ -51,13 +51,13 @@ describe('renderBlockImages', () => {
5151
// For now, only Joplin resources are rendered. This simplifies the implementation and avoids
5252
// potentially-unwanted web requests when opening a note with only the editor open.
5353
test('should not render web images', async () => {
54-
const editor = await createEditor('![test](https://example.com/test.png)\n\n', true);
54+
const editor = await createEditor('![test](https://example.com/test.png)\n\n');
5555
const images = findImages(editor);
5656
expect(images).toHaveLength(0);
5757
});
5858

5959
test('should allow reloading specific images', async () => {
60-
const editor = await createEditor('![test](:/a123456789abcdef0123456789abcdef)\n![test 2](:/b123456789abcdef0123456789abcde2)', true);
60+
const editor = await createEditor('![test](:/a123456789abcdef0123456789abcdef)\n![test 2](:/b123456789abcdef0123456789abcde2)');
6161

6262
// Should have the expected original image URLs
6363
expect(getImageUrls(editor)).toMatchObject([
@@ -98,7 +98,7 @@ describe('renderBlockImages', () => {
9898
const widthAttr = width ? ` width="${width}"` : '';
9999
const editor = await createEditor(
100100
`${spaceBefore}<img src=":/0123456789abcdef0123456789abcdef" alt="${alt}"${widthAttr} />${spaceAfter}`,
101-
false,
101+
['HTMLTag'],
102102
);
103103

104104
const images = findImages(editor);
@@ -117,7 +117,7 @@ describe('renderBlockImages', () => {
117117
test('should render non-self-closing HTML img tags', async () => {
118118
const editor = await createEditor(
119119
'<img src=":/0123456789abcdef0123456789abcdef" alt="test" width="300">',
120-
false,
120+
['HTMLBlock'],
121121
);
122122

123123
const images = findImages(editor);
@@ -128,7 +128,7 @@ describe('renderBlockImages', () => {
128128
test('should not render HTML img tags with web URLs', async () => {
129129
const editor = await createEditor(
130130
'<img src="https://example.com/test.png" alt="test" />',
131-
false,
131+
['HTMLTag'],
132132
);
133133

134134
const images = findImages(editor);
@@ -138,7 +138,7 @@ describe('renderBlockImages', () => {
138138
test('should render both markdown and HTML images in same document', async () => {
139139
const editor = await createEditor(
140140
'![markdown](:/a123456789abcdef0123456789abcdef)\n\n<img src=":/b123456789abcdef0123456789abcde2" alt="html" width="400" />',
141-
true,
141+
['Image', 'HTMLTag'],
142142
);
143143

144144
const images = findImages(editor);
@@ -151,7 +151,7 @@ describe('renderBlockImages', () => {
151151
const editor = await createEditor(
152152
// eslint-disable-next-line quotes
153153
"<img src=':/0123456789abcdef0123456789abcdef' alt='test' width='250' />",
154-
false,
154+
['HTMLTag'],
155155
);
156156

157157
const images = findImages(editor);

0 commit comments

Comments
 (0)