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

@blocklytics/truffle-test-generator

v1.0.4

Published

A test file generator for the Truffle framework

Downloads

12

Readme

Truffle Test Generator

A utility for creating new test files in a Truffle project.

Install

npm i @blocklytics/truffle-test-generator --save-dev

Usage

Use Truffle to compile your contracts first.

truffle compile

Generate tests for a contract named MyContract.

npx ttg MyContract

Replace MyContract with the name of the contract you want to create tests for.

How It Works

The test generator will look at the json files located in the ./build/contracts directory for the given contract name. As long as that contract exists and has been compiled, a test file will be created for it.

Each test will include a standard template for the beginning of the file, which includes requireing the artifact, declaring the contract test, and setting some common account variables.

const MyChildContract = artifacts.require('MyChildContract')

contract('MyChildContract', (accounts) => {
  const maintainer = accounts[0]
  const user1 = accounts[1]
  const user2 = accounts[2]
  const stranger = accounts[3]

  let mychildcontract

While reading the contract's json file, it will also generate input parameters for your constructor. However, it will be up to you to update the values as your contract requires.

// Be sure to update these constructor values
let _initialParentValue = 0
let _initialChildValue = 0

beforeEach(async () => {
  mychildcontract = await MyChildContract.new(_initialParentValue, _initialChildValue, {from: maintainer})
})

Any inherited contracts with external or public functions will have a test stub (as a describe block) created for it.

describe('setValue', () => {

})

This allows you to easily have a structure for your tests and ensure that each external/public method will be tested, provided you write a test for it.

The test file will be placed in the test directory within your Truffle project and named MyContract_test.js, where MyContract is the name of the contract. In order to prevent a user from accidentally erasing an existing file, -new will be appended to the name and a new file will be created if the filename already exists. If the -new file exists, it will be overwritten.