Skip to content

Commit

Permalink
Migrate tests to the spec-node runner (#1263)
Browse files Browse the repository at this point in the history
  • Loading branch information
fsoikin authored Aug 6, 2024
1 parent e06d664 commit ac3c117
Show file tree
Hide file tree
Showing 9 changed files with 181 additions and 77 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
/bin/docs-search-app.js
.direnv
.envrc
.spec-results
*.node
**/.vscode
**/.DS_Store
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Other improvements:
- `spago bundle` now writes a special marker into the bundle and will refuse to
overwrite the file if the marker isn't present, assuming that the file was
manually created or edited, not generated by Spago itself.
- migrated tests to the `spec-node` runner.

## [0.21.0] - 2023-05-04

Expand Down
7 changes: 7 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ spago build
# Can of course run the tests with
spago test

# Can select a subset of tests to run
spago test -- --example "bundle" # run only bundle tests
spago test -- --example "browser" # run only tests that mention browser in their name

# Can select a subset of tests by a regular expression
spago test -- --example-matches "bundle|browser" # run bundle tests _and_ those that mention browser

# To see tests' stdout/stderr output while the tests are running, run
SPAGO_TEST_DEBUG=1 spago

Expand Down
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -411,12 +411,34 @@ You should add some tests.
Tests succeeded.
```

If you are using [the `spec-node` test runner](https://purescript-spec.github.io/purescript-spec/running/#running-under-node),
you can use its command-line options to select a subset of tests with
`--example` or rerun previously failed tests with `--only-failures`:

```console
$ spago test -- --example "some test"
$ spago test -- --only-failures
```

Note that you have to separate test runner options with a double dash `--` to distinguish them from Spago's own options.
If you're on PowerShell (Windows), you will also need to quote the double dash:

```console
> spago test '--' --example "some test"
> spago test '--' --only-failures
```

This has to do with an unfortunate interaction between Node bootstrapping mechanism and the way PowerShell handles parameters.

See [the docs](https://purescript-spec.github.io/purescript-spec/running/#running-under-node)
for more useful options.

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.

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:

```console
$ spago install --test-deps spec
$ spago install --test-deps spec spec-node
```

### Run a repl
Expand Down
1 change: 1 addition & 0 deletions docs-search/index/spago.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ package:
dependencies:
- exceptions
- spec
- spec-node
18 changes: 9 additions & 9 deletions docs-search/index/test/Docs/Search/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@ module Test.Docs.Search.Main where

import Prelude

import Data.Identity (Identity(..))
import Data.Maybe (Maybe(..))
import Data.Newtype (un)
import Effect (Effect)
import Effect.Aff (Milliseconds(..), launchAff_)
import Effect.Aff (Milliseconds(..))
import Test.Declarations as Declarations
import Test.IndexBuilder as IndexBuilder
import Test.ModuleIndex as ModuleIndex
import Test.ModuleParser as ModuleParser
import Test.Spec (Spec)
import Test.Spec.Reporter.Console (consoleReporter)
import Test.Spec.Runner (Config, defaultConfig, runSpecT)
import Test.Spec.Runner.Node (runSpecAndExitProcess')
import Test.Spec.Runner.Node.Config as Config
import Test.TypeQuery as TypeQuery

testConfig :: Config
testConfig = defaultConfig
{ slow = Milliseconds 2_000.0
, timeout = Just (Milliseconds 5_000.0)
testConfig :: Config.TestRunConfig
testConfig = Config.defaultConfig
{ timeout = Just (Milliseconds 5_000.0)
}

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

mainTest :: Spec Unit
mainTest = do
Expand Down
Loading

0 comments on commit ac3c117

Please sign in to comment.