From ac3c117c428ca7a70cb0b94b79837640ae99db00 Mon Sep 17 00:00:00 2001 From: Fyodor Soikin Date: Tue, 6 Aug 2024 19:31:27 -0400 Subject: [PATCH] Migrate tests to the spec-node runner (#1263) --- .gitignore | 1 + CHANGELOG.md | 1 + CONTRIBUTING.md | 7 + README.md | 24 +++- docs-search/index/spago.yaml | 1 + docs-search/index/test/Docs/Search/Main.purs | 18 +-- spago.lock | 141 ++++++++++++++----- spago.yaml | 3 +- test/Spago.purs | 62 ++++---- 9 files changed, 181 insertions(+), 77 deletions(-) diff --git a/.gitignore b/.gitignore index 6b295bede..8bc2cfb9d 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ /bin/docs-search-app.js .direnv .envrc +.spec-results *.node **/.vscode **/.DS_Store diff --git a/CHANGELOG.md b/CHANGELOG.md index 80fd2a262..fc55b3730 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index fe37642bd..46151bfcb 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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 diff --git a/README.md b/README.md index 1cb7a49d3..143a8f386 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/docs-search/index/spago.yaml b/docs-search/index/spago.yaml index e2bf0c7a5..c86198be7 100644 --- a/docs-search/index/spago.yaml +++ b/docs-search/index/spago.yaml @@ -36,3 +36,4 @@ package: dependencies: - exceptions - spec + - spec-node diff --git a/docs-search/index/test/Docs/Search/Main.purs b/docs-search/index/test/Docs/Search/Main.purs index 82c45143c..267987ebd 100644 --- a/docs-search/index/test/Docs/Search/Main.purs +++ b/docs-search/index/test/Docs/Search/Main.purs @@ -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 diff --git a/spago.lock b/spago.lock index 879fa6716..ea0b151e9 100644 --- a/spago.lock +++ b/spago.lock @@ -276,10 +276,12 @@ workspace: test_dependencies: - exceptions - spec + - spec-node build_plan: - aff - aff-promise - ansi + - argonaut-codecs - argonaut-core - arraybuffer-types - arrays @@ -300,6 +302,7 @@ workspace: - enums - exceptions - exists + - exitcodes - fixed-points - foldable-traversable - foreign @@ -333,6 +336,8 @@ workspace: - now - nullable - numbers + - open-memoize + - optparse - ordered-collections - orders - parallel @@ -343,6 +348,7 @@ workspace: - prelude - profunctor - profunctor-lenses + - psci-support - quickcheck - quickcheck-laws - random @@ -351,6 +357,7 @@ workspace: - safe-coerce - search-trie - spec + - spec-node - st - string-parsers - strings @@ -430,12 +437,14 @@ workspace: - identity - quickcheck - spec + - spec-node build_plan: - aff - aff-promise - affjax - affjax-node - ansi + - argonaut-codecs - argonaut-core - arraybuffer-types - arrays @@ -459,6 +468,7 @@ workspace: - enums - exceptions - exists + - exitcodes - filterable - fixed-points - foldable-traversable @@ -504,6 +514,8 @@ workspace: - now - nullable - numbers + - open-memoize + - optparse - ordered-collections - orders - parallel @@ -514,6 +526,7 @@ workspace: - prelude - profunctor - profunctor-lenses + - psci-support - quickcheck - quickcheck-laws - random @@ -525,6 +538,7 @@ workspace: - search-trie - spago-core - spec + - spec-node - st - string-parsers - strings @@ -579,6 +593,7 @@ workspace: - affjax - affjax-node - ansi + - argonaut-codecs - argonaut-core - arraybuffer-types - arrays @@ -673,6 +688,7 @@ workspace: - spago - spago-core - spec + - spec-node - st - string-parsers - strings @@ -822,7 +838,7 @@ workspace: - variant package_set: address: - registry: 51.0.0 + registry: 56.4.0 compiler: ">=0.15.15 <0.16.0" content: abc-parser: 2.0.1 @@ -847,7 +863,7 @@ workspace: argonaut-traversals: 10.0.0 argparse-basic: 2.0.0 array-builder: 0.1.2 - array-search: 0.5.6 + array-search: 0.6.0 arraybuffer: 13.2.0 arraybuffer-builder: 3.1.0 arraybuffer-types: 3.0.2 @@ -856,7 +872,7 @@ workspace: arrays-zipper: 2.0.1 ask: 1.0.0 assert: 6.0.0 - assert-multiple: 0.3.4 + assert-multiple: 0.4.0 avar: 5.0.0 b64: 0.0.8 barbies: 1.0.1 @@ -871,7 +887,7 @@ workspace: canvas-action: 9.0.0 cartesian: 1.0.6 catenable-lists: 7.0.0 - cbor-stream: 1.0.4 + cbor-stream: 1.3.0 chameleon: 1.0.0 chameleon-halogen: 1.0.3 chameleon-react-basic: 1.1.0 @@ -887,7 +903,7 @@ workspace: classnames: 2.0.0 codec: 6.1.0 codec-argonaut: 10.0.0 - codec-json: 1.1.0 + codec-json: 1.2.0 colors: 7.0.1 concur-core: 0.5.0 concur-react: 0.5.0 @@ -900,7 +916,7 @@ workspace: coroutines: 7.0.0 css: 6.0.0 css-frameworks: 1.0.1 - csv-stream: 2.0.2 + csv-stream: 2.3.0 data-mvc: 0.0.2 datetime: 6.1.0 datetime-parsing: 0.2.0 @@ -918,26 +934,27 @@ workspace: dotenv: 4.0.3 droplet: 0.6.0 dts: 1.0.0 - dual-numbers: 1.0.2 + dual-numbers: 1.0.3 dynamic-buffer: 3.0.1 echarts-simple: 0.0.1 effect: 4.0.0 either: 6.1.0 - elmish: 0.11.3 + elmish: 0.13.0 elmish-enzyme: 0.1.1 - elmish-hooks: 0.10.0 - elmish-html: 0.8.2 + elmish-hooks: 0.10.3 + elmish-html: 0.9.0 elmish-testing-library: 0.3.2 email-validate: 7.0.0 encoding: 0.0.9 enums: 6.0.1 - env-names: 0.3.4 + env-names: 0.4.0 error: 2.0.0 eta-conversion: 0.3.2 - exceptions: 6.0.0 + exceptions: 6.1.0 exists: 6.0.0 exitcodes: 4.0.0 expect-inferred: 3.0.0 + ezfetch: 1.0.0 fahrtwind: 2.0.0 fallback: 0.1.0 fast-vect: 1.2.0 @@ -976,7 +993,7 @@ workspace: generate-values: 1.0.1 generic-router: 0.0.1 geojson: 0.0.5 - geometry-plane: 1.0.3 + geometria: 2.2.0 gojs: 0.1.1 grain: 3.0.0 grain-router: 3.0.0 @@ -1006,6 +1023,7 @@ workspace: homogeneous: 0.4.0 http-methods: 6.0.0 httpurple: 4.0.0 + huffman: 0.4.0 humdrum: 0.0.1 hyrule: 2.3.8 identity: 6.0.0 @@ -1053,7 +1071,7 @@ workspace: logging-journald: 0.4.0 lumi-components: 18.0.0 machines: 7.0.0 - maps-eager: 0.4.1 + maps-eager: 0.5.0 marionette: 1.0.0 marionette-react-basic-hooks: 0.1.1 marked: 0.1.0 @@ -1089,7 +1107,7 @@ workspace: node-child-process: 11.1.0 node-event-emitter: 3.0.0 node-execa: 5.0.0 - node-fs: 9.1.0 + node-fs: 9.2.0 node-glob-basic: 1.3.0 node-http: 9.1.0 node-http2: 1.1.1 @@ -1098,9 +1116,9 @@ workspace: node-os: 5.1.0 node-path: 5.0.0 node-process: 11.2.0 - node-readline: 8.1.0 + node-readline: 8.1.1 node-sqlite3: 8.0.0 - node-stream-pipes: 1.4.1 + node-stream-pipes: 2.1.6 node-streams: 9.0.0 node-tls: 0.3.1 node-url: 7.0.1 @@ -1109,7 +1127,7 @@ workspace: now: 6.0.0 npm-package-json: 2.0.0 nullable: 6.0.0 - numberfield: 0.1.0 + numberfield: 0.2.2 numbers: 9.0.1 oak: 3.1.1 oak-debug: 1.2.2 @@ -1140,11 +1158,12 @@ workspace: pointed-list: 0.5.1 polymorphic-vectors: 4.0.0 posix-types: 6.0.0 - postgresql: 1.6.3 + postgresql: 2.0.17 precise: 6.0.0 precise-datetime: 7.0.0 prelude: 6.0.1 prettier-printer: 3.0.0 + priority-queue: 0.1.0 profunctor: 6.0.1 profunctor-lenses: 8.0.0 protobuf: 4.3.0 @@ -1184,6 +1203,7 @@ workspace: record-studio: 1.0.4 refs: 6.0.0 remotedata: 5.0.1 + repr: 0.5.0 resize-observer: 1.0.0 resource: 2.0.1 resourcet: 1.0.0 @@ -1191,6 +1211,7 @@ workspace: return: 0.2.0 ring-modules: 5.0.1 rito: 0.3.4 + roman: 0.4.0 rough-notation: 1.0.2 routing: 11.0.0 routing-duplex: 0.7.0 @@ -1209,14 +1230,17 @@ workspace: simple-ulid: 3.0.0 sized-matrices: 1.0.0 sized-vectors: 5.0.2 - slug: 3.0.8 + slug: 3.1.0 small-ffi: 4.0.1 soundfonts: 4.1.0 - sparse-matrices: 1.3.0 - sparse-polynomials: 2.0.5 - spec: 7.6.0 - spec-mocha: 5.1.0 - spec-quickcheck: 5.0.0 + sparse-matrices: 2.0.1 + sparse-polynomials: 3.0.1 + spec: 7.6.1 + spec-discovery: 8.3.0 + spec-mocha: 5.1.1 + spec-node: 0.0.1 + spec-quickcheck: 5.0.2 + spec-reporter-xunit: 0.7.1 splitmix: 2.1.0 ssrs: 1.0.0 st: 6.2.0 @@ -1238,9 +1262,10 @@ workspace: thermite: 6.3.1 thermite-dom: 0.3.1 these: 6.0.0 + threading: 0.0.3 toestand: 0.9.0 transformation-matrix: 1.0.1 - transformers: 6.0.0 + transformers: 6.1.0 tree-rose: 4.0.2 ts-bridge: 4.0.0 tuples: 7.0.0 @@ -1269,6 +1294,7 @@ workspace: untagged-to-tagged: 0.1.4 untagged-union: 1.0.0 uri: 9.0.0 + url-immutable: 1.0.0 uuid: 9.0.0 uuidv4: 1.0.0 validation: 6.0.0 @@ -1607,6 +1633,22 @@ packages: - foldable-traversable - lists - strings + argonaut-codecs: + type: registry + version: 9.1.0 + integrity: sha256-N6efXByUeg848ompEqJfVvZuZPfdRYDGlTDFn0G0Oh8= + dependencies: + - argonaut-core + - arrays + - effect + - foreign-object + - identity + - integers + - maybe + - nonempty + - ordered-collections + - prelude + - record argonaut-core: type: registry version: 7.0.0 @@ -1861,8 +1903,8 @@ packages: - unfoldable exceptions: type: registry - version: 6.0.0 - integrity: sha256-y/xTAEIZIARCE+50/u1di0ncebJ+CIwNOLswyOWzMTw= + version: 6.1.0 + integrity: sha256-K0T89IHtF3vBY7eSAO7eDOqSb2J9kZGAcDN5+IKsF8E= dependencies: - effect - either @@ -2461,8 +2503,8 @@ packages: - unsafe-reference node-fs: type: registry - version: 9.1.0 - integrity: sha256-TzhvGdrwcM0bazDvrWSqh+M/H8GKYf1Na6aGm2Qg4+c= + version: 9.2.0 + integrity: sha256-Sg0vkXycEzkEerX6hLccz21Ygd9w1+QSk1thotRZPGI= dependencies: - datetime - effect @@ -2934,8 +2976,8 @@ packages: - prelude spec: type: registry - version: 7.6.0 - integrity: sha256-+merGdQbL9zWONbnt8S8J9afGJ59MQqGtS0qSd3yu4I= + version: 7.6.1 + integrity: sha256-VycY2SgN8rHZGqcMqZEiTh9OdCw40CUMX2pCoSUJ/zY= dependencies: - aff - ansi @@ -2964,6 +3006,36 @@ packages: - tailrec - transformers - tuples + spec-node: + type: registry + version: 0.0.1 + integrity: sha256-RFcAi44CZWTfWF4xrZ25L13nd8syuCa9uC2iHZttZRY= + dependencies: + - aff + - argonaut-codecs + - argonaut-core + - arrays + - control + - datetime + - effect + - either + - foldable-traversable + - identity + - integers + - maybe + - newtype + - node-buffer + - node-fs + - node-process + - now + - numbers + - optparse + - ordered-collections + - partial + - prelude + - spec + - strings + - tuples st: type: registry version: 6.2.0 @@ -3057,8 +3129,8 @@ packages: - tuples transformers: type: registry - version: 6.0.0 - integrity: sha256-Pzw40HjthX77tdPAYzjx43LK3X5Bb7ZspYAp27wksFA= + version: 6.1.0 + integrity: sha256-3Bm+Z6tsC/paG888XkywDngJ2JMos+JfOhRlkVfb7gI= dependencies: - control - distributive @@ -3071,6 +3143,7 @@ packages: - maybe - newtype - prelude + - st - tailrec - tuples - unfoldable diff --git a/spago.yaml b/spago.yaml index 54dc3cfeb..ffe5c54bf 100644 --- a/spago.yaml +++ b/spago.yaml @@ -79,9 +79,10 @@ package: - identity - quickcheck - spec + - spec-node workspace: packageSet: - registry: 51.0.0 + registry: 56.4.0 extraPackages: codec-json: 1.2.0 registry-lib: diff --git a/test/Spago.purs b/test/Spago.purs index 1390d1095..58020a0a5 100644 --- a/test/Spago.purs +++ b/test/Spago.purs @@ -2,12 +2,9 @@ module Test.Spago where import Prelude -import Data.Identity (Identity(..)) import Data.Maybe (Maybe(..)) -import Data.Newtype (un) import Effect (Effect) import Effect.Aff (Milliseconds(..)) -import Effect.Aff as Aff import Test.Spago.Build as Build import Test.Spago.Bundle as Bundle import Test.Spago.Docs as Docs @@ -29,36 +26,37 @@ import Test.Spago.Unit as Unit import Test.Spago.Upgrade as Upgrade import Test.Spec as Spec import Test.Spec.Reporter as Spec.Reporter -import Test.Spec.Runner as Spec.Runner +import Test.Spec.Runner.Node (runSpecAndExitProcess') +import Test.Spec.Runner.Node.Config as Config -testConfig :: Spec.Runner.Config -testConfig = Spec.Runner.defaultConfig - { slow = Milliseconds 10_000.0 - , timeout = Just (Milliseconds 90_000.0) - , exit = true +testConfig :: Config.TestRunConfig +testConfig = Config.defaultConfig + { timeout = Just (Milliseconds 90_000.0) } main :: Effect Unit -main = Aff.launchAff_ $ void $ un Identity $ Spec.Runner.runSpecT testConfig [ Spec.Reporter.consoleReporter ] do - Spec.describe "spago" do - -- TODO: script - Init.spec - Sources.spec - Install.spec - Uninstall.spec - Ls.spec - Build.spec - Repl.spec - Run.spec - Test.spec - Bundle.spec - Registry.spec - Docs.spec - Upgrade.spec - Publish.spec - Graph.spec - Spec.describe "miscellaneous" do - Lock.spec - Unit.spec - Glob.spec - Errors.spec +main = do + config <- Config.fromCommandLine' testConfig Config.commandLineOptionParsers + runSpecAndExitProcess' config [ Spec.Reporter.consoleReporter ] do + Spec.describe "spago" do + -- TODO: script + Init.spec + Sources.spec + Install.spec + Uninstall.spec + Ls.spec + Build.spec + Repl.spec + Run.spec + Test.spec + Bundle.spec + Registry.spec + Docs.spec + Upgrade.spec + Publish.spec + Graph.spec + Spec.describe "miscellaneous" do + Lock.spec + Unit.spec + Glob.spec + Errors.spec