Détail du package

@gerhobbelt/markdown-it-testgen

GerHobbelt30MIT0.1.6-23

Tests generator for markdown-it markdown parser

markdown-it, test generator, test

readme

markdown-it-testgen

Node.js CI CircleCI NPM version

This package parses fixtures in commonmark spec format and generates tests for markdown-it parser and plugins.

npm install markdown-it-testgen

Fixture format

Each fixture can have optional metadata in yaml format:

---
desc: Batch description # file name used if not exists.
skip: true              # mark batch as pending
---

Then tests should follow in this format:

optional header
.
source
data
.
parsed
data
.


header2
.
src
.
result
.

If header missed - line number will be used instead.

API

generate: module.exports(path, options, md, env)

  • path - file or directory name
  • options (not mandatory)

    • header - Set true to use fixture headers for test names or false to use fixture line numbers for test names like so: "line 123". Default false.
    • sep - array of allowed separators for samples, [ '.' ] by default
    • assert - custom assertion package, require('assert') by default.

      The assert library you supply must at least provide these member functions:

      • assert.strictEqual(a, b, message)
      • assert(booleanTestResult, message)
    • test - optional test function which will be used instead of the global it(...) test function when provided.

      The test() function is invoked like so:

      options.test(it, testTitle, fixture, options, md, Object.assign({}, env))

      where:

      • it is a reference to the global it() test function (which must have been set up by your test framework)
      • testTitle is either the fixture.header or a 'line 123' string listing the starting line of the fixture test spec block.
      • fixture is a reference to the current fixture record, the format of which is described further below at parse record fixture
      • options is a reference to the shallow copy of the options instance
      • md is a reference to the user-provided md markdown-it instance as described further below.
      • env is a shallow copy of the user-provided env structure as described further below.

      The options.test() callback allows the creation of arbitrary fixture-file based test rigs, whether it is for markdown-it or another library. See the 'generator correctly handles options.test user-defined test function' test for an example.

  • md - markdown-it instance to parse and compare samples

    The md instance is expected to contain a render function member, which will be invoked like md.render(fixture.first.text, Object.assign({}, env)).

  • env (not mandatory) - environment object to be passed through to markdown-it.render()

module.exports.load(path, options, iterator)

For each loaded file: parse and pass data to iterator function. Currently used for tests only.

Returns NULL (when no fixture file could be found in the given directory) or a non-empty array of parse records. The parse record structure is described further below at the options.iterator option.

  • path - file or directory name

    When the path is a directory, it is traversed rescursively to load all files within. Every non-empty file will be parsed as a single fixture record.

  • options (not mandatory)

    • sep - array of allowed separators for samples, [ '.' ] by default

    Note: when the options are a string instead of an options object, the options string is assumed to be a string of separator characters, which will be split into an array of seaprators like so: options = { sep: options.split('') }.

  • iterator - every non-empty parsed file will invoke the iterator(record) callback once, passing a parse record with the following structure:

    • meta - the YAML-parsed frontmatter metadata at the head of the loaded fixture file -- this frontmatter metadata must be enclosed between a top and bottom line containing only a --- separator as is usual with MarkDown frontmatter.
    • file - the path to the actual file loaded & parsed.
    • fixtures - an array with zero or more fixture records with the following structure:

      • header - (possibly empty) header/title.

        This can serve as a test descriptor/title and is a trimmed copy of the last non-empty line of text preceding the fixture test spec itself.

      • type - identifies the separator used for this particular fixture test spec. '.' by default.
      • first - object:
        • text - the first text extracted from the fixture test spec block
        • range - array listing both the starting and ending line numbers for this text
      • second - object:
        • text - the second text extracted from the fixture test spec block
        • range - array listing both the starting and ending line numbers for this text

License

MIT

changelog

0.1.6-17 (2020/7/26)

Features

  • updated the README documentation to describe the latest features and all userland-code visible object structures. (1f9ac79d)

Testing

  • augmented some tests to also verify the correctness of API return values/structures. (d9a5a910)

0.1.6-16 (2020/7/26)

  • Maintenance release.

0.1.6-15 (2020/7/6)

Features

  • changed options.test method interface to function (it, title, fixture, options, md, env) for maximum flexibility: added are the it and title parameters and the test() function is now expected to generate a test using the it() function. (Hm, maybe a rename from test to testgen is in order?) (9a96473c)

0.1.6-14 (2020/7/6)

Testing

  • removed the need for the generator empty 'md' object hack to be able to easily use options.test: now the code performs a minimal sanity check to see if the potential md object has the mandatory bits (read: a render() function) (f380bb8a)

0.1.6-13 (2020/7/6)

Bug Fixes

  • any: added options.test function: this can be used to produce customized tests based on the fixtures' data. Interface: options.test(fixture, options, md, env) (38805213)

0.1.6-12 (2020/7/5)

Bug Fixes

  • Tested the new code with markdown-it-dirty-dozen.

    Added fixes for test description issue uncovered there:

    • options.desc must win over meta.desc
    • test description obtained from meta (or options) MAY be a number or other type: cast it to string before using it (89bd5d49)

0.1.6-11 (2020/7/5)

Features

  • provide two ways to override the test set description: options.desc (the options object are the options of generate/load, not markdown-it, so this is safe anyway) and ultimately the code takes the filename of the fixture as-is (basename). (5daeb0c4)

0.1.6-10 (2020/7/5)

Bug Fixes

  • any: Changes:
    • improve test coverage
      • added test for the load() API: check to make sure the loaded files are correctly parsed. This test has been constructed such that it also tests the single-file-in-directory path inside load()
      • added test for the generate() API by letting it generate (and execute) a set of dummy tests, which MUST pass. This test re-uses the same set of fixture files as the other test to maximize usefulness of those 'dummy files'.
    • remove object.assign npm package: Node 10+ has this built-in
    • remove chai package: Node assert is powerful enough and nobody should be enforced to load an extra test package if they don't want (or need) to. Proper test execution is guaranteed by the added tests above: everyone can expect their generate()d tests to pass/fail as before. (cc733f03)

Testing

  • Changes:
    • added another test to test the generate() API, now with minimal parameters (while we aim for 100% coverage :) )
    • there's some weird sh*t going on with nyc as it reports an inexplicable line as not covered yet, even after moving the code to a "single statement per line" format. Shuffling the functions around can trigger a whole series of other lines being reported as 'not covered', so there's some very odd interplay between microbundle and nyc perhaps?!?! (de74a3c6)

0.1.6-9 (2020/7/3)

Features

  • fix/feature: add meta override parameter to generate() function -- turns out some tests don't produce a decent title and this way we can override the standard heuristic -- bug was discovered in markdown-it-dirty-dozen. (c9fd9855)

0.1.6-8 (2020/6/17)

Chore

  • Changes:
    • synced with template markdown-it plugin build tooling files (df09544b)

0.1.6-7 (2020/4/4)

Bug Fixes

Testing

  • Changes:
    • patched eslint to make the build and test run pass: warnings instead of errors for the mocha/assert globals (8ff330bc)
    • Allow optionally passing env to tests (67a5698b)

Documentation

  • Add documentation for passing env (d12ecad3)

Miscellaneous

  • Changes:

    • added 'prep' and 'superclean' make targets to help clean and re-install NPM package dependencies (e016812c)
    • add npm run pub publish task for scoped packages (f99dbee6)
    • synced build/environment files with main project: markdown-it (45949bd8)
    • Switch env to final position

      This way we can differentiate between options and env (e3e1e42c)

    • Use _.clone instead of adding a dependency on merge (81ddd5bb)

0.1.6 (2019/7/9)

Miscellaneous

0.1.5 (2019/3/12)

  • Maintenance release.
  • Drop lodash use.
  • Pin dev deps.
  • Add latest node to travis.
  • Cleanup package.json.

Miscellaneous

  • Changes:
    • Drop lodash use (023c23ea)
    • added 'prep' and 'superclean' make targets to help clean and re-install NPM package dependencies (e016812c)
    • add npm run pub publish task for scoped packages (f99dbee6)
    • make this a scoped npm package. (7e9ba40e)

0.1.5-1 (2017/8/5)

Testing

  • Allow optionally passing env to tests (67a5698b)

Documentation

  • Add documentation for passing env (d12ecad3)

Miscellaneous

  • synced build/environment files with main project: markdown-it (45949bd8)
  • Switch env to final position

    This way we can differentiate between options and env (e3e1e42c)

0.1.4 (2015/1/12)

Bug Fixes

  • Fixed swapped params in error reports (09976176)

0.1.3 (2015/1/12)

Miscellaneous

  • Changes:
    • Added option to pass custom assertion object. (a515d963)
    • Use chai assertions by default. (a515d963)

0.1.2 (2014/12/23)

  • One more maintenance release :)

0.1.1 (2014/12/22)

  • Maintenance release.

Miscellaneous

0.1.0 (2014/12/20)

  • First release.