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

pico-test

v0.0.1

Published

⚡ PICO-8 testing framework

Downloads

12

Readme

pico-test

Note: This project is still in its initial stages, so I'd love feedback about the API and issue reports.

Intro

PICO-8 is great but debugging your code in this little vm can be a chore.

If you're tired of riddling your carts with prinths or have given up on test-driven development, this tool should help you out.

Installation

npm i -g pico-test

Usage

Copy/paste the following snippet into the cart you wish to test:

function test(title,f)
local desc=function(msg,f)
 printh('⚡:desc:'..msg)
 f()
end
local it=function(msg,f)
 printh('⚡:it:'..msg)
 local xs={f()}
 for i=1,#xs do
  if xs[i] == true then
   printh('⚡:assert:true')
  else
   printh('⚡:assert:false')
  end
 end
 printh('⚡:it_end')
end
printh('⚡:test:'..title)
f(desc,it)
printh('⚡:test_end')
end

Next, be sure PICO-8 is aliased properly in your terminal. You may have to do something like the following:

alias pico-8='/Applications/PICO-8.app/Contents/MacOS/pico8'

Last, run Pico-8 from your terminal and pipe its output to pico-test.

pico-8 | pico-test

Each time your run your cart, test results will be printed to stdout. Now, you just have to write some tests! :)

API

pico-test's api is will be pretty familiar if you've ever used mocha. There are only 3 functions to learn: test(), desc(), and it()

test(title:string, fn:function)

initiates testing, wraps around test descriptions and tests, providing the callback fn with two args: desc and it – the other two functions in this API.

| Type | Param | Description | |----------|-------|-------------| | String | title | title of test suite | Function | fn | callback to call with desc and it

desc(description:string, fn:function)

Describes a set of tests. This function is applied as the first argument of the callback function passed to test

| Type | Param | Description | |----------|-------------|-------------| | String | description | description for tests to be run inside of param fn | Function | fn | callback to call with desc and it

it(message:string, fn:function)

Returns one or more boolean values representing test assertions. all returned values must be true or your test will fail. This function is applied as the second argument of the callback function passed to test

| Type | Param | Description | |----------|---------|-------------| | String | message | message starting with "should" | Function | fn | callback to return assertions from

Example

Here's what it looks like in action:

-- here's an object with methods we want to test
local math={
  gt=function(a,b) return a>b end,
  lt=function(a,b) return a<b end,
  mul=function(a,b) return a*b end,
  div=function(a,b) return a/b end
}

test('math functions', function(desc,it)
  desc('math.gt()', function()
    local gt = math.gt
    it('should return type boolean', function()
      return 'boolean' == type(gt(1,0))
    end)
    it('should give same result as > operator', function()
      return gt(1,0)
    end)
  end)

  desc('math.lt()', function()
    local lt = math.lt
    it('should return type boolean',function()
      return 'boolean' == type(lt(1,0))
    end)
    it('should give same result as < operator',function()
      return lt(1, 0) == false
    end)
  end)

  desc('math.mul()', function()
    local mul = math.mul
    it('should return type number', function()
      local a = rnd(time())
      local b = rnd(time())
      return 'number' == type(mul(a,b))
    end)
    it('should give same result as * operator', function()
      local x=rnd(time())
      return
        x*1 == mul(x,1),
        x*2 == mul(x,2),
        x*3 == mul(x,3)
   end)
  end)

  desc('math.div()', function()
    local div = math.div
    it('should return type number', function()
      local a = rnd(time())
      local b = rnd(time())
      return 'number' == type(div(a,b))
    end)
    it('should give same result as / operator', function()
      local x=1+rnd(time())
      return
        x/1 == div(x,1),
        x/2 == div(x,2),
        x/3 == div(x,3)
    end)
  end)

end)

License

Copyright (c) 2015 Josiah Savary. Made available under The MIT License (MIT).