Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
# node-elm-test
Runs [elm-test](https://github.com/deadfoxygrandpa/Elm-Test) suites from Node.js

Install it with `npm install -g elm-test`, then try this after downloading this repository:
## Installation

```bash
cd examples
elm-package install --yes
elm-test Test.elm
npm install -g elm-test
```

## Usage

```bash
elm-test init # Adds the Elm-Test dependency and creates TestRunner.elm and Tests.elm
elm-test TestRunner.elm # Runs the tests
```

Then add your tests to Tests.elm.

Also check out [`elm-check`](https://github.com/TheSeamau5/elm-check) for property-based testing via `elm-test`!
23 changes: 21 additions & 2 deletions bin/elm-test
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,30 @@ process.title = 'elm-test';

var compile = require("node-elm-compiler").compile,
suffix = require("../elm-io-ports.js"),
fs = require("fs"),
fs = require("fs-extra"),
path = require("path"),
temp = require("temp").track(), // Automatically cleans up temp files.
util = require("util"),
_ = require("lodash"),
childProcess = require("child_process");

if (process.argv[2] == "init") {
var copyTemplate = function(templateName) {
if (fs.existsSync(templateName)) {
console.log(templateName + " already exists");
} else {
fs.copySync(path.resolve(__dirname, "../templates/" + templateName), templateName);
console.log("Created " + templateName);
}
};

childProcess.execSync("elm package install deadfoxygrandpa/Elm-Test", {stdio:[0,1,2]});
childProcess.execSync("elm package install maxsnew/IO", {stdio:[0,1,2]});

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably want to include --yes on these, yeah?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm hesitant about that since people using elm-test for the first time might want to get the prompt for the new packages. But how about if we add a --yes option to elm-test init ?

copyTemplate("TestRunner.elm");
copyTemplate("Tests.elm");
process.exit(0);
}

var testFile = process.argv[2],
cwd = __dirname;

Expand All @@ -22,7 +40,8 @@ function spawnCompiler(cmd, args, opts) {
}

if (typeof testFile !== "string") {
console.log("Usage: elm-test TESTFILE\n");
console.log("Usage: elm-test init # Create example tests\n");
console.log("Usage: elm-test TESTFILE # Run tests\n");
process.exit(1);
}

Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"version": "0.3.0",
"description": "Run elm-test suites.",
"main": "elm-test.js",
"engines" : {
"node" : ">=0.12.0"
"engines": {
"node": ">=0.12.0"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
Expand All @@ -28,6 +28,7 @@
},
"homepage": "https://github.com/rtfeldman/node-elm-test#readme",
"dependencies": {
"fs-extra": "^0.23.1",

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any objection to pinning this to exactly 0.23.1?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The correct thing appears to be ~0.23.1, which will match 0.23.* http://stackoverflow.com/questions/22343224/difference-between-tilde-and-caret-in-package-json

"lodash": "3.9.3",
"node-elm-compiler": "0.4.0+elm-0.15.1",
"temp": "0.8.1"
Expand Down
23 changes: 23 additions & 0 deletions templates/TestRunner.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module Main where

import Basics exposing (..)
import Signal exposing (..)

import ElmTest.Assertion as A exposing (assertEqual, assert)
import ElmTest.Run as R
import ElmTest.Runner.Console exposing (runDisplay)
import ElmTest.Test exposing (..)
import IO.IO exposing (..)
import IO.Runner exposing (Request, Response)
import IO.Runner as Run

import String
import Tests

console : IO ()
console = runDisplay Tests.all

port requests : Signal Request
port requests = Run.run responses console

port responses : Signal Response
14 changes: 14 additions & 0 deletions templates/Tests.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module Tests where

import ElmTest.Assertion as A exposing (assertEqual, assert)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable to expose assert and assertEqual by default, but I think as A is more of a personal preference, and might surprise people.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to remove as A

import ElmTest.Test exposing (..)

import String


all : Test
all = suite "A Test Suite"
[ test "Addition" (assertEqual (3 + 7) 10)
, test "String.left" (assertEqual "a" (String.left 1 "abcdefg"))
, test "This test should fail" (assert False)
]

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd format this like so:

all : Test
all =
    suite "A Test Suite"
        [
            test "Addition" (assertEqual (3 + 7) 10),
            test "String.left" (assertEqual "a" (String.left 1 "abcdefg")),
            test "This test should fail" (assert False)
        ]

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay (I had just copied this code from the examples folder)