reveal-test

3.3.0 • Public • Published

reveal-test

npm version npm publish

Utilities for testing presentation code snippets by compiling them on Compiler Explorer.

Check out also reveal-compiler-explorer package.

Example

const { parseMarkdownFile, compile, CompileError } = require('reveal-test');

const codeInfos = await parseMarkdownFile('presentation.md');

describe("demo presentation", function () {
  codeInfo.forEach((info, index) => {
    it(`should have snippet ${index} compiled`, async function () {
      await compile(info);
    });
  });
}, 10000);

For reference, take a look at the demo package in this repo.


Installation

npm install --save-dev reveal-test

or

yarn add -D reveal-test

API

parseMarkdownFile

parseMarkdownFile(path: String, config: Config = {}, preprocessor: (String) => String) => Promise<Array<SnippetInfo>>

Asynchronously generates a list of all code snippets from a given markdown file. For possible config fields, see here. Optionally pre-processes the markdown file with the given preprocessor function.

parseMarkdown

parseMarkdown(markdown: String, config: Config = {}) => Array<SnippetInfo>

Generates a list of all code snippets from a given markdown string. For possible config fields, see here.

compile

compile(info: SnippetInfo) => String

Calls CE's Rest API to compile a code snippet.

Returns output from compiling and running the code (if enabled) on success, otherwise throws CompileError with code being the exit code and message being the compiler's error message.


Directives

In addition to the directives mentioned here, the following directives are supported:

///skip

Avoid testing this code snippet.

///fails=<reason>

When given, compile will fail if compiling and running the code (if enabled) succeeds, or if the error message doesn't include the given reason.

Cannot be defined together with output.

Usage example:

///fails=expected ';' before '}' token
#include <iostream>

int main() {
  std::cout << "Hello CE!"
}

///output=<expected>

When given, compile will fail if the snippet's output doesn't include the given output.

Cannot be defined together with fails.

Usage example:

///external
///output=Hello CE!
#include <iostream>

int main() {
  std::cout << "Hello CE!";
}

Package Sidebar

Install

npm i reveal-test

Weekly Downloads

94

Version

3.3.0

License

MIT

Unpacked Size

3.68 MB

Total Files

6

Last publish

Collaborators

  • dvirtz