Skip to content

Commit a631ddf

Browse files
committed
Add trivial entrypoint + update docs
1 parent 1822082 commit a631ddf

File tree

5 files changed

+60
-29
lines changed

5 files changed

+60
-29
lines changed

Diff for: CHANGELOG.md

+11-7
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,21 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8-
## [Unreleased]
8+
## v8.4.0
99

10-
@srghma Use `spec-node` in tests
10+
## Added
11+
12+
- Use `spec-node` in tests by @srghma
13+
- New trivial entrypoint function `discoverAndRunSpecs` for ergonomics by @fsoikin
1114

1215
## v8.0.1
1316

14-
- @CarstenKoenig Fix discovery on Windows by prepending `file://`
17+
## Changed
18+
19+
- Fix discovery on Windows by prepending `file://` by @CarstenKoenig
1520

1621
## v8.0.0
17-
Features:
18-
- Update to v0.15.0 and support es modules
1922

20-
Breaking changes:
21-
- `discover` now needs `MonadAff` constraint instead of `MonadEffect` due to dynamic imports returning promises
23+
## Changed
24+
- Update to v0.15.0 and support es modules
25+
- **breaking** `discover` now needs `MonadAff` constraint instead of `MonadEffect` due to dynamic imports returning promises

Diff for: README.md

+30-7
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,35 @@ purescript-spec-discovery is an extension to
44
[purescript-spec](https://github.com/purescript-spec/purescript-spec) that finds
55
specs automatically, given a regular expression pattern.
66

7-
It only works for NodeJS environments, currently.
7+
It only works for NodeJS environments, currently, since it's using NodeJS
8+
facilities to list and load modules.
89

910
## Usage
1011

12+
Install via Spago:
13+
1114
```bash
1215
spago install spec-discovery
1316
```
1417

18+
Use as main entry point:
19+
20+
```purescript
21+
module Test.Main where
22+
23+
import Prelude
24+
import Effect (Effect)
25+
import Test.Spec.Discovery (discoverAndRunSpec)
26+
import Test.Spec.Reporter.Console (consoleReporter)
27+
28+
main :: Effect Unit
29+
main = discoverAndRunSpecs [consoleReporter] """My\.Package\..*Spec"""
30+
```
31+
32+
Or, if you need more sophistication, like an alternative config or whatnot, use
33+
the `discover` function to just return a list of specs and then run them in
34+
whatever way you need:
35+
1536
```purescript
1637
module Test.Main where
1738
@@ -20,21 +41,23 @@ import Effect (Effect)
2041
import Effect.Aff (launchAff_)
2142
import Test.Spec.Discovery (discover)
2243
import Test.Spec.Reporter.Console (consoleReporter)
23-
import Test.Spec.Runner (runSpec)
44+
import Test.Spec.Runner.Node (runSpecAndExitProcess)
45+
import Test.Spec.Runner.Node.Config (defaultConfig)
2446
2547
main :: Effect Unit
2648
main = launchAff_ do
2749
specs <- discover """My\.Package\..*Spec"""
28-
runSpec [consoleReporter] specs
50+
liftEffect $ runSpecAndExitProcess'
51+
{ defaultConfig: defaultConfig { timeout = Nothing }
52+
, parseCLIOptions: true
53+
}
54+
[consoleReporter]
55+
specs
2956
```
3057

3158
All modules that match the regular expression, **and have a definition
3259
`spec :: Spec Unit`**, will be included and run.
3360

34-
## Documentation
35-
36-
Documentation is publised on [Pursuit](https://pursuit.purescript.org/packages/purescript-spec-discovery).
37-
3861
## Contribute
3962

4063
If you have any issues or possible improvements please file them as

Diff for: spago.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ package:
66
name: spec-discovery
77
publish:
88
license: MPL-2.0
9-
version: 8.3.0
9+
version: 8.4.0
1010
location:
1111
githubOwner: purescript-spec
1212
githubRepo: purescript-spec-discovery

Diff for: src/Test/Spec/Discovery.purs

+16-9
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
1-
module Test.Spec.Discovery (discover) where
1+
module Test.Spec.Discovery
2+
( discover
3+
, discoverAndRunSpecs
4+
)
5+
where
26

37
import Prelude
48

59
import Control.Promise (Promise)
610
import Control.Promise as Promise
711
import Data.Traversable (sequence_)
812
import Effect (Effect)
13+
import Effect.Aff (launchAff_)
914
import Effect.Aff.Class (class MonadAff, liftAff)
15+
import Effect.Class (liftEffect)
1016
import Test.Spec (Spec)
17+
import Test.Spec.Runner (Reporter)
18+
import Test.Spec.Runner.Node (runSpecAndExitProcess)
1119

12-
foreign import getSpecs
13-
:: String
14-
-> Effect (Promise (Array (Spec Unit)))
20+
foreign import getSpecs :: String -> Effect (Promise (Array (Spec Unit)))
1521

16-
discover
17-
:: forall m
18-
. MonadAff m
19-
=> String
20-
-> m (Spec Unit)
22+
discover :: m. MonadAff m => String -> m (Spec Unit)
2123
discover pattern = getSpecs pattern # Promise.toAffE >>= (pure <<< sequence_) # liftAff
24+
25+
discoverAndRunSpecs :: Array Reporter -> String -> Effect Unit
26+
discoverAndRunSpecs reporters pattern = launchAff_ do
27+
specs <- discover pattern
28+
liftEffect $ runSpecAndExitProcess reporters specs

Diff for: test/Main.purs

+2-5
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,8 @@ module Test.Main where
33
import Prelude
44

55
import Effect (Effect)
6-
import Effect.Aff (launchAff_)
7-
import Effect.Class (liftEffect)
8-
import Test.Spec.Discovery (discover)
6+
import Test.Spec.Discovery (discoverAndRunSpecs)
97
import Test.Spec.Reporter.Console (consoleReporter)
10-
import Test.Spec.Runner.Node (runSpecAndExitProcess)
118

129
main :: Effect Unit
13-
main = launchAff_ $ discover "Test\\.Spec\\.Discovery.*Spec" >>= (liftEffect <<< runSpecAndExitProcess [consoleReporter])
10+
main = discoverAndRunSpecs [consoleReporter] "Test\\.Spec\\.Discovery.*Spec"

0 commit comments

Comments
 (0)