commonmark / commonmark/commonmark.js

Doesn’t read commonmark when included in unit testing

Open
#253 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
1.6k
Forks
231
Avg merge
2d 11h
Merged PRs (30d)
3

Description

I create a util function that uses commonmark to convert markdown to HTML. And then I tried to write a test case for that function, it throws error saying that commonmark is not defined.

Here is my code:

markdown.test.js

const {markdownToHtml} = require('../../services/util/markdown');
const assert = require('assert');

describe('Commonmark plugin', () => {
  it('normal text returns HTML string', () => {
    assert.strictEqual(markdownToHtml('Hello world').toBe('<p>Hello world</p>\n'));
  });
});

markdown.js

const markdownToHtml = (text) => {
  const reader = new commonmark.Parser();
  const writer = new commonmark.HtmlRenderer({safe: true});

  const parsed = reader.parse(text); // parsed is a 'Node' tree
  // transform parsed if you like...
  const result = writer.render(parsed); // result is a String
  return result;
};

module.exports = {markdownToHtml};

I get the following error when I run the test:
ReferenceError: commonmark is not defined

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with services/util/markdown.js and markdown.test.js, then check how commonmark is exposed to modules in this project. Run the focused test and confirm the utility can construct the parser and renderer and return the expected HTML for “Hello world”.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
testing-qa
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.