platelunch

Generate boilerplate code for unit tests

Usage no npm install needed!

<script type="module">
  import platelunch from 'https://cdn.skypack.dev/platelunch';
</script>

README

Platelunch

Travis Codecov npm version code style: platelunch semantic-release greenkeeper

Platelunch logo

Intro

Platelunch generates boilerplate unit test code for javascript source files. Currently it will generate unit test files to be used with jest only. More testing frameworks will be supported.

Install

npm install --save-dev platelunch

--- or globally

npm install -g platelunch

CLI

platelunch [opts] [filename ...]

Platelunch will create a directory __tests__ where all the generated unit test files will be created.

WARNING If a test file exists in __tests__ it will be overwritten unless the glob or filename does not include that file.

Using glob to find files to generate unit tests

platelunch --test-framework jest "src/**/*.js"

Only one unit test file will be generated

platelunch --test-framework jest "src/my-file.js"

Examples

module.exports

Source File

function add(num1, num2) {
  return num1 + num2;
}

module.exports = {
  add: add
};

Generated unit test file

const add = require("src/my-module.js").add;

describe("my-module.js", () => {
  test("add", () => {
    const num1 = null;
    const num2 = null;
    
    const result = add(num1, num2);
  });
});

exports

Source File

function add(num1, num2) {
  return num1 + num2;
}

export { add };

Generated unit test file

import { add } from "src/my-module.js"

describe("my-module.js", () => {
  test("add", () => {
    const num1 = null;
    const num2 = null;
    
    const result = add(num1, num2);
  });
});

class (ES2015)

Source File

export class TestClass {
  add(num1, num2) {
    return num1 + num2;
  }
};

Generated unit test file

import { TestClass } from "TestClass.js";

describe("TestClass.js", () => {
  let testClass;

  beforeEach(() => {
    testClass = new TestClass();
  });

  test("add", () => {
    const num1 = null;
    const num2 = null;
    const result = testClass.add(num1, num2);
  });
});

Licensing

The code in this project is licensed under MIT license.