Skip to content
This repository was archived by the owner on Dec 14, 2024. It is now read-only.

Commit c6aa505

Browse files
committed
Fixed js test runner for phantom
1 parent b733654 commit c6aa505

File tree

5 files changed

+30
-11
lines changed

5 files changed

+30
-11
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ script:
66
- nix-channel --add https://nixos.org/channels/nixos-16.09 nixpkgs
77
- nix-channel --update
88
- nix-build release.nix
9-
- phantomjs --web-security=no jsbits/options.js dist/build/ghcjs-tests/ghcjs-tests.jsexe/index.html
9+
- phantomjs --web-security=no jsbits/options.js result-2/bin/ghcjs-tests.jsexe/index.html

ghcjs-tests/Test.hs

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
{-# LANGUAGE OverloadedStrings #-}
22
{-# LANGUAGE ScopedTypeVariables #-}
33
{-# OPTIONS_GHC -fno-warn-orphans #-}
4+
{-# LANGUAGE RecordWildCards #-}
45
module Main where
56

67
import Control.Applicative
78
import Data.Aeson
89
import Data.Either (isRight)
10+
import Data.JSString
911
import Generics.SOP.Arbitrary
1012
import Generics.SOP.Universe
11-
import Test.Hspec (it, hspec, describe, shouldSatisfy, shouldBe)
13+
import System.Exit
14+
import Test.Hspec (it, hspec, describe, shouldSatisfy, shouldBe)
15+
import Test.Hspec.Core.Runner (hspecResult, Summary(..))
1216
import Test.QuickCheck
1317
import Test.QuickCheck.Instances ()
1418

@@ -67,7 +71,7 @@ instance Generic Descendants
6771

6872
main :: IO ()
6973
main = do
70-
hspec $ do
74+
Summary{..} <- hspecResult $ do
7175
describe "HackerNews API tests" $ do
7276
it "should round trip Updates JSON" $ property $ \(x :: Updates) ->
7377
Just x == decode (encode x)
@@ -98,4 +102,9 @@ main = do
98102
(`shouldSatisfy` isRight) =<< getJobStories
99103
it "should retrieve updates" $ do
100104
(`shouldSatisfy` isRight) =<< getUpdates
101-
putStr "done"
105+
case summaryFailures of
106+
x | x > 0 -> putStrLn "error"
107+
| otherwise -> putStrLn "done"
108+
109+
110+

hackernews.cabal

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ executable ghcjs-tests
3131
, hackernews
3232
, ghcjs-base
3333
, hspec
34+
, hspec-core
3435
, basic-sop
3536
, generics-sop
3637
, quickcheck-instances

hackernews.nix

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{ mkDerivation, aeson, base, hspec, http-client, http-client-tls
22
, servant, servant-client, stdenv, text, transformers, compiler
33
, quickcheck-instances, basic-sop, servant-quickcheck, nixpkgs, generics-sop
4-
, http-types, string-conversions
4+
, http-types, string-conversions, hspec-core
55
}:
66
let
77
phantomjs = nixpkgs.nodePackags.phantomjs;
@@ -12,7 +12,7 @@ let
1212
transformers http-client-tls http-types string-conversions
1313
quickcheck-instances
1414
];
15-
ghcjs-deps = [ basic-sop' generics-sop
15+
ghcjs-deps = [ basic-sop' generics-sop hspec-core
1616
ghcjs-base aeson base text
1717
transformers hspec servant quickcheck-instances
1818
string-conversions ];

jsbits/options.js

+14-5
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,25 @@ if (system.args.length !== 2) {
44
console.log('Usage: phantomjsOpen.js URL');
55
phantom.exit(1);
66
}
7+
78
var page = require('webpage').create();
89

9-
page.onConsoleMessage = function (msg) {
10-
console.log(msg);
11-
};
1210
page.onError = function (msg, trace) {
13-
error.append(msg);
14-
console.log(msg);
11+
if (msg.match("error").length > 0) {
12+
phantom.exit(1);
13+
}
1514
};
15+
1616
page.open(system.args[1], function (status) {
17+
page.onConsoleMessage = function (msg) {
18+
if (msg.match("done")) {
19+
phantom.exit(0);
20+
} else if (msg.match("error")) {
21+
phantom.exit(1);
22+
} else {
23+
console.log(msg);
24+
}
25+
};
1726
if (status !== "success") {
1827
console.log("Unable to open " + system.args[1]);
1928
phantom.exit(1);

0 commit comments

Comments
 (0)