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.
npm install --save-dev platelunch
--- or globally
npm install -g platelunch
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"
function add(num1, num2) {
return num1 + num2;
}
module.exports = {
add: add
};
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);
});
});
function add(num1, num2) {
return num1 + num2;
}
export { add };
import { add } from "src/my-module.js"
describe("my-module.js", () => {
test("add", () => {
const num1 = null;
const num2 = null;
const result = add(num1, num2);
});
});
export class TestClass {
add(num1, num2) {
return num1 + num2;
}
};
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);
});
});
The code in this project is licensed under MIT license.