Skip to content

Commit ac3c117

Browse files
authored
Migrate tests to the spec-node runner (#1263)
1 parent e06d664 commit ac3c117

File tree

9 files changed

+181
-77
lines changed

9 files changed

+181
-77
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
/bin/docs-search-app.js
1414
.direnv
1515
.envrc
16+
.spec-results
1617
*.node
1718
**/.vscode
1819
**/.DS_Store

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Other improvements:
2222
- `spago bundle` now writes a special marker into the bundle and will refuse to
2323
overwrite the file if the marker isn't present, assuming that the file was
2424
manually created or edited, not generated by Spago itself.
25+
- migrated tests to the `spec-node` runner.
2526

2627
## [0.21.0] - 2023-05-04
2728

CONTRIBUTING.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ spago build
5555
# Can of course run the tests with
5656
spago test
5757

58+
# Can select a subset of tests to run
59+
spago test -- --example "bundle" # run only bundle tests
60+
spago test -- --example "browser" # run only tests that mention browser in their name
61+
62+
# Can select a subset of tests by a regular expression
63+
spago test -- --example-matches "bundle|browser" # run bundle tests _and_ those that mention browser
64+
5865
# To see tests' stdout/stderr output while the tests are running, run
5966
SPAGO_TEST_DEBUG=1 spago
6067

README.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,12 +411,34 @@ You should add some tests.
411411
Tests succeeded.
412412
```
413413

414+
If you are using [the `spec-node` test runner](https://purescript-spec.github.io/purescript-spec/running/#running-under-node),
415+
you can use its command-line options to select a subset of tests with
416+
`--example` or rerun previously failed tests with `--only-failures`:
417+
418+
```console
419+
$ spago test -- --example "some test"
420+
$ spago test -- --only-failures
421+
```
422+
423+
Note that you have to separate test runner options with a double dash `--` to distinguish them from Spago's own options.
424+
If you're on PowerShell (Windows), you will also need to quote the double dash:
425+
426+
```console
427+
> spago test '--' --example "some test"
428+
> spago test '--' --only-failures
429+
```
430+
431+
This has to do with an unfortunate interaction between Node bootstrapping mechanism and the way PowerShell handles parameters.
432+
433+
See [the docs](https://purescript-spec.github.io/purescript-spec/running/#running-under-node)
434+
for more useful options.
435+
414436
As with the `run` command, it's possible to configure the tests using the `spago.yaml` - most importantly to separate test dependencies from the dependencies of your application/library.
415437

416438
Please see [the section about the configuration format](#the-configuration-file) for more info, but in the meantime note that it's possible to install test dependencies by running:
417439

418440
```console
419-
$ spago install --test-deps spec
441+
$ spago install --test-deps spec spec-node
420442
```
421443

422444
### Run a repl

docs-search/index/spago.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,4 @@ package:
3636
dependencies:
3737
- exceptions
3838
- spec
39+
- spec-node

docs-search/index/test/Docs/Search/Main.purs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,28 @@ module Test.Docs.Search.Main where
22

33
import Prelude
44

5-
import Data.Identity (Identity(..))
65
import Data.Maybe (Maybe(..))
7-
import Data.Newtype (un)
86
import Effect (Effect)
9-
import Effect.Aff (Milliseconds(..), launchAff_)
7+
import Effect.Aff (Milliseconds(..))
108
import Test.Declarations as Declarations
119
import Test.IndexBuilder as IndexBuilder
1210
import Test.ModuleIndex as ModuleIndex
1311
import Test.ModuleParser as ModuleParser
1412
import Test.Spec (Spec)
1513
import Test.Spec.Reporter.Console (consoleReporter)
16-
import Test.Spec.Runner (Config, defaultConfig, runSpecT)
14+
import Test.Spec.Runner.Node (runSpecAndExitProcess')
15+
import Test.Spec.Runner.Node.Config as Config
1716
import Test.TypeQuery as TypeQuery
1817

19-
testConfig :: Config
20-
testConfig = defaultConfig
21-
{ slow = Milliseconds 2_000.0
22-
, timeout = Just (Milliseconds 5_000.0)
18+
testConfig :: Config.TestRunConfig
19+
testConfig = Config.defaultConfig
20+
{ timeout = Just (Milliseconds 5_000.0)
2321
}
2422

2523
main :: Effect Unit
26-
main = launchAff_ $ void $ un Identity $ runSpecT testConfig [ consoleReporter ] mainTest
24+
main = do
25+
config <- Config.fromCommandLine' testConfig Config.commandLineOptionParsers
26+
runSpecAndExitProcess' config [ consoleReporter ] mainTest
2727

2828
mainTest :: Spec Unit
2929
mainTest = do

0 commit comments

Comments
 (0)