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

elm-doctest

v0.4.1

Published

doctest for elm

Downloads

18

Readme

Build Status npm version

elm-doctest

doctest runner against Elm-lang source files

installation

npm install elm-doctest

It depends on elm and assumes that elm-make and elm-repl are available either via systemwide installation or npm module installation. Make sure elm-make succeeds with your elm source files.

how does it work?

It utilizes elm-repl for expression evaluation and compare the values against the expected value. (It does not comapre stringified values like haskell doctest does via GHCi outputs.)

It only evaluates the expressions that follows -- >>> (i.e. Elm comment symbol followed by space and three LT chars until end of the line) and the expression on the next line after -- .

For example, if the comment states:

-- >>> x =
-- >>>   1 + 2
--
-- >>> x * 2
-- 6

Then, elm-doctest asks elm-repl to evaluate the actual code section in the source file and effectively following expression:

((1 + 2) * 2) == (6)

If value reported by elm-repl is True then test passes, fail otherwise.

usage

Usage: elm-doctest [--watch] [--help] [--elm-repl-path PATH]
                   [--elm-make-path PATH]
                   [--pretest CMD] FILES...
  run doctest against given Elm files

Available options:
  -h,--help             Show this help text
  --pretest CMD         command to run before doc-test
  --elm-repl-path PATH  Path to elm-repl executable
  --elm-make-path PATH  Path to elm-make executable
  -w,--watch            Watch and run tests when target files get updated

example

ModuleTobeTested.elm:

module ModuleTobeTested exposing(..)

-- |
-- >>> add 3 5
-- 8
--
-- >>> removeZeros [0, 1, 2, 3, 0]
-- [1, 2, 3]
--
-- >>> greetingTo "World"
-- "Konnichiwa World"
--
add : Int -> Int -> Int
add x y = x + y

greetingTo : String -> String
greetingTo x = "Hello " ++ x

removeZeros : List Int -> List Int
removeZeros = List.filter (\x -> x /= 0)

evaluation elm-doctest ModuleTobeTested.elm outputs

Starting elm-doctest ...

 processing: test/TestData/TestFail.elm
### Failure in test/TestData/TestFail.elm:10: expression
  greetingTo "World"
expected: "Konnichiwa World"
 but got: "Hello World"
Examples: 3  Failures: 1

limitation

As it utilizes elm-repl, the script must be runnable inside elm-repl. For example, code which imports elm-lang/[email protected] module cannot be tested. Since the stdout is used to evaluate the test result, avoid using Debug.log.

Also, make sure elm-make runs without error. You can auto run elm-make by using --pretest command-line option.

license

MIT