All Projects → azu → power-doctest

azu / power-doctest

Licence: other
JavaScript Doctest for JavaScript, Markdown and Asciidoc.

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to power-doctest

Quizoo
Online Quiz Platform for conducting quizes
Stars: ✭ 27 (-40%)
Mutual labels:  test
xray-action
... a GitHub action to import test results into "Xray" - A complete Test Management tool for Jira.
Stars: ✭ 16 (-64.44%)
Mutual labels:  test
local-data-api
Data API for local, you can write unittest for AWS Aurora Serverless's Data API
Stars: ✭ 99 (+120%)
Mutual labels:  test
dojos
Alguns desafios para os participantes dos grupos de estudo
Stars: ✭ 33 (-26.67%)
Mutual labels:  test
archifacts
archifacts is a library to extract your architectural concepts out of your application's code
Stars: ✭ 40 (-11.11%)
Mutual labels:  asciidoc
difflicious
Scala library for readable diffs of values
Stars: ✭ 50 (+11.11%)
Mutual labels:  test
jest-fixtures
Use file system fixtures in Jest
Stars: ✭ 39 (-13.33%)
Mutual labels:  test
colortest
Quickly show all your terminal colors
Stars: ✭ 66 (+46.67%)
Mutual labels:  test
xv
❌ ✔️ zero-config test runner for simple projects
Stars: ✭ 588 (+1206.67%)
Mutual labels:  test
instapy-docs
📜 Public information for users, testers, contributors, maintainers
Stars: ✭ 60 (+33.33%)
Mutual labels:  test
BaseUrlManager
⛵ BaseUrlManager的设计初衷主要用于开发时,有多个环境需要打包APK的场景,通过BaseUrlManager提供的BaseUrl动态设置入口,只需打一次包,即可轻松随意的切换不同的开发环境或测试环境。在打生产环境包时,关闭BaseUrl动态设置入口即可。
Stars: ✭ 43 (-4.44%)
Mutual labels:  test
demos
永恒君的案例库
Stars: ✭ 19 (-57.78%)
Mutual labels:  test
kotlin-plugin-generated
A Kotlin compiler plugin that annotates Kotlin-generated methods for improved coverage reports
Stars: ✭ 33 (-26.67%)
Mutual labels:  test
to-string-verifier
To String Verifier provides an easy and convenient way to test the toString method on your class.
Stars: ✭ 25 (-44.44%)
Mutual labels:  test
Microdown
Microdown is a cleaned and simpler markdown but with more powerful features such as extensions.
Stars: ✭ 26 (-42.22%)
Mutual labels:  document
website
Official website and document for Gin
Stars: ✭ 88 (+95.56%)
Mutual labels:  document
airplayreceiver
Open source implementation of AirPlay 2 Mirroring / Audio protocol.
Stars: ✭ 84 (+86.67%)
Mutual labels:  test
action-junit-report
Reports junit test results as GitHub Pull Request Check
Stars: ✭ 103 (+128.89%)
Mutual labels:  test
goverreport
Command line tool for coverage reporting and validation
Stars: ✭ 44 (-2.22%)
Mutual labels:  test
NanoTest
NanoTest is a light weight test library. Its API is similar to the haxe.unit testing framework, but it can run as pre-compilation macro and can output test failures as compiler warnings or errors.
Stars: ✭ 14 (-68.89%)
Mutual labels:  test

power-doctest Actions Status: test

A monorepo for power-doctest.

power-doctest is a project that provide doctest system for JavaScript.

Features

  • Run Comments as Assertions
  • Support JavaScript, Markdown Code Block, Asciidoctor Code Block
  • Control doctest behavior from comments

Packages

power-doctest

power-doctest is consisted of two parts.

  • Comment Assertion Syntax
  • Doctest Control Annotation

Comment Assertion Syntax

You can write following comment in your JavaScript code. These comment will be canistered to assertion.

Syntax Transformed
1; // => 2 assert.strictEqual(1, 2)
console.log(1); // => 2 assert.strictEqual(1, 2)
a; // => b assert.deepStrictEqual(a, b)
[1, 2, 3]; // => [3, 4, 5] assert.deepStrictEqual([1, 2, 3], [3, 4, 5])
console.log({ a: 1 }): // => { b: 2 } assert.deepStrictEqual({ a: 1 }, { b: 2 })
throw new Error("message"); // => Error: "message" assert.throws(function() {throw new Error("message"); });"
Promise.resolve(1); // Resolve: 2 Promise.resolve(Promise.resolve(1)).then(v => { assert.strictEqual(1, 2) })
Promise.reject(1); // Reject: 2 assert.rejects(Promise.reject(1))

For more details, see comment-to-assert.

Doctest Control Annotation

Doctest Control Annotation is defined in Language specific plugin. For more details, see following package's README.

Recipes

Doctest JavaScript Code

Use @power-doctest/tester and @power-doctest/javascript in Mocha.

import { test } from "@power-doctest/tester";
import { parse } from "@power-doctest/javascript";
const globby = require("globby");
const fs = require("fs");
const path = require("path");
// doctest for source/**/*.js
describe("doctest:js", function() {
    const sourceDir = path.join(__dirname, "..", "source");
    const files = globby.sync([
        `${sourceDir}/**/*.js`,
        `!${sourceDir}/**/node_modules{,/**}`
    ]);
    files.forEach(filePath => {
        const normalizeFilePath = filePath.replace(sourceDir, "");
        it(`doctest:js ${normalizeFilePath}`, function() {
            const content = fs.readFileSync(filePath, "utf-8");
            const parsedResults = parse({
                content,
                filePath
            });
            const parsedCode = parsedResults[0];
            return test(parsedCode).catch(error => {
                // Stack Trace like
                console.error(`StrictEvalError: strict eval is failed
    at strictEval (${filePath}:1:1)`);
                return Promise.reject(error);
            });
        });
    });
});

Example

Doctest JavaScript Code in Markdown

Use @power-doctest/tester and @power-doctest/markdown in Mocha.

import { test } from "@power-doctest/tester";
import { parse } from "@power-doctest/markdown";
const globby = require("globby");
const fs = require("fs");
const path = require("path");
const transform = (code) => {
    return code; // you need pre transform for the code if needed.
};
// doctest for source/**/*.md
describe("doctest:md", function() {
    const sourceDir = path.join(__dirname, "..", "source");
    const files = globby.sync([
        `${sourceDir}/**/*.md`,
        `!${sourceDir}/**/node_modules{,/**}`,
    ]);
    files.forEach(filePath => {
        const normalizeFilePath = filePath.replace(sourceDir, "");
        describe(`${normalizeFilePath}`, function() {
            const content = fs.readFileSync(filePath, "utf-8");
            const parsedCodes = parse({
                filePath,
                content
            });
            // try to eval
            const dirName = path.dirname(filePath).split(path.sep).pop();
            parsedCodes.forEach((parsedCode, index) => {
                const codeValue = parsedCode.code;
                const testCaseName = codeValue.slice(0, 32).replace(/[\r\n]/g, "_");
                it(dirName + ": " + testCaseName, function() {
                    return test({
                        ...parsedCode,
                        code: transform(parsedCode.code)
                    }, {
                        defaultDoctestRunnerOptions: {
                            // Default timeout: 2sec
                            timeout: 1000 * 2
                        }
                    }).catch(error => {
                        const filePathLineColumn = `${error.fileName}:${error.lineNumber}:${error.columnNumber}`;
                        console.error(`Markdown Doctest is failed
  at ${filePathLineColumn}

----------
${codeValue}
----------
`);
                        return Promise.reject(error);
                    });
                });
            });
        });
    });
});

Example

Doctest JavaScript in Asciidoctor

Use @power-doctest/tester and @power-doctest/asciidoctor in Mocha.

const { test } = require("@power-doctest/tester");
const { parse } = require("@power-doctest/asciidoctor");
const globby = require("globby");
const fs = require("fs");
const path = require("path");
// Avoid "do not support nested sections" Error
// Replace Header with Dummy text
const replaceDummyHeader = (content) => {
    return content.split("\n").map(line => {
        return line.replace(/^(=+)/g, (all, match) => {
            return "♪".repeat(match.length);
        });
    }).join("\n");
};
// doctest for source/**/*.adoc
describe("doctest:adoc", function () {
    const sourceDir = path.join(__dirname, "..", "source");
    const files = globby.sync([
        `${sourceDir}/**/*.adoc`,
        `!**/node_modules{,/**}`,
    ]);
    files.forEach(filePath => {
        const normalizeFilePath = filePath.replace(sourceDir, "");
        describe(`${normalizeFilePath}`, function () {
            const content = fs.readFileSync(filePath, "utf-8");
            const parsedCodes = parse({
                filePath,
                content: replaceDummyHeader(content)
            });
            console.log("parsedCodes", parsedCodes);
            // try to eval
            const dirName = path.dirname(filePath).split(path.sep).pop();
            parsedCodes.forEach((parsedCode, index) => {
                const codeValue = parsedCode.code;
                const testCaseName = codeValue.slice(0, 32).replace(/[\r\n]/g, "_");
                it(dirName + ": " + testCaseName, function () {
                    return test(parsedCode).catch(error => {
                        const filePathLineColumn = `${error.fileName}:${error.lineNumber}:${error.columnNumber}`;
                        console.error(`Asciidoc Doctest is failed
  at ${filePathLineColumn}

----------
${codeValue}
----------
`);
                        return Promise.reject(error);
                    });
                });
            });
        });
    });
});

Example

Development

Require Yarn

Install project

yarn install
yarn boostrap

Build

yarn run build

Test

yarn test

Release: use npm

npm run versionup
# GH_TOKEN="${GITHUB_TOKEN}" yarn run versionup:patch --create-release=github
# prepare release note
npm relase
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].