npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

js-test-gen

v1.1.0

Published

Generating js test templates with a little help from babel

Downloads

39

Readme

js-test-gen

js-test-gen is an opinionated unit test template generator using babel and prettier.

It uses babel to identify what modules are being exported. It then generates a test template and formats the template using prettier.

CircleCI

Installation

npm install js-tes-gen

or

yarn add js-test-gen

Input

//name of this file is myfuncs.js

export const someModule1 = () => {};
export const someModule2 = () => {};

const someModule = () => {};

export default someModule;

Output

import someModule, { someModule1, someModule2 } from "./myfuncs";

describe("someModule", () => {
  it("should fail auto generated test", () => {
    expect(someModule()).toBe(false);
  });
});
describe("someModule1", () => {
  it("should fail auto generated test", () => {
    expect(someModule1()).toBe(false);
  });
});
describe("someModule2", () => {
  it("should fail auto generated test", () => {
    expect(someModule2()).toBe(false);
  });
});

API

generateTestTemplate({contents, srcfileName, importFromPath, typeSystem})

generateTestTemplate is used to generate a complete js unit test template.

| property | type | description | | ---------------- | -------------------- | ----------------------------------------------------------------------------------------------- | | contents | string | The JS contents to generate a test from. | | srcFileName | string | The name of the JS module the test is being created for. | | importFromPath | string | The path of where the module is located in relation to the generated test file E.G . or ../ | | typeSystem | FLOW or TYPESCRIPT | If the js module is using a type system this needs to be specified. |

generateTest(contents, typeSystem)

generateTest is used to generate test cases from given js contents.

| arguments | type | description | | ------------ | -------------------- | --------------------------------------------------------------------- | | contents | string | The JS contents to generate a test from. | | typeSystem | FLOW or TYPESCRIPT | If the js contents is using a type system this needs to be specified. |

Usage

import { generateTestTemplate } from "js-test-gen";

const contentToParse = `export const addOne = (x) => x +1`;

const testTemplate = generateTestTemplate({
  contents: contentsToParse, // contents of the mod
  srcFileName: "addOne", // the name of the mod we want to test
  importFromPath: ".." // where the test should import the mod from
});

result

import { addOne } from "../addOne";

describe("addOne", () => {
  it("should fail auto generated test", () => {
    expect(addOne()).toBe(false);
  });
});