Skip to content

Commit

Permalink
Update to v0.15.0 (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
sigma-andex authored Apr 17, 2022
1 parent d62f362 commit 0ef42b2
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 19 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
/output/
/.psci*
/src/.webpack.js
/.spago/
/.psc-ide-port
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

Features:
- Update to v0.15.0 and support es modules

Breaking changes:
- `discover` now needs `MonadAff` constraint instead of `MonadEffect` due to dynamic imports returning promises
24 changes: 24 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "purescript-spec-discovery",
"version": "1.0.0",
"description": "purescript-spec-discovery is an extension to [purescript-spec](https://github.com/purescript-spec/purescript-spec) that finds specs automatically, given a regular expression pattern.",
"main": "index.js",
"directories": {
"test": "test"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/working-group-purescript-es/purescript-spec-discovery.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/working-group-purescript-es/purescript-spec-discovery/issues"
},
"homepage": "https://github.com/working-group-purescript-es/purescript-spec-discovery#readme",
"type": "module"
}
24 changes: 24 additions & 0 deletions packages.dhall
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
let upstream =
https://raw.githubusercontent.com/purescript/package-sets/prepare-0.15/src/packages.dhall
sha256:5f32c078b014909642302b328bd9bebcdcedc301956a709b302f19521680a0aa

in upstream
with metadata.version = "v0.15.0-alpha-02"
with spec =
{ repo = "https://github.com/purescript-spec/purescript-spec.git"
, version = "master"
, dependencies =
[ "aff"
, "ansi"
, "avar"
, "console"
, "exceptions"
, "foldable-traversable"
, "fork"
, "now"
, "pipes"
, "prelude"
, "strings"
, "transformers"
]
}
27 changes: 27 additions & 0 deletions spago.dhall
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{-
Welcome to a Spago project!
You can edit this file as you like.
Need help? See the following resources:
- Spago documentation: https://github.com/purescript/spago
- Dhall language tour: https://docs.dhall-lang.org/tutorials/Language-Tour.html
When creating a new Spago project, you can use
`spago init --no-comments` or `spago init -C`
to generate this file without the comments in this block.
-}
{ name = "spec-discovery"
, dependencies =
[ "aff"
, "aff-promise"
, "arrays"
, "console"
, "effect"
, "foldable-traversable"
, "node-fs"
, "prelude"
, "spec"
]
, packages = ./packages.dhall
, sources = [ "src/**/*.purs", "test/**/*.purs" ]
}
30 changes: 18 additions & 12 deletions src/Test/Spec/Discovery.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
'use strict';
import path from "path"
import fs from 'fs';
import { fileURLToPath } from "url"

if (typeof require !== 'function') {
throw new Error('Sorry, purescript-spec-discovery only supports NodeJS environments!');
}
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)

var fs = require('fs');
var path = require('path');
if (import.meta.url === `file://${process.argv[1]}`) {
throw new Error('Sorry, purescript-spec-discovery only supports NodeJS environments!');
}

function getMatchingModules(pattern) {
var directories = fs.readdirSync(path.join(__dirname, '..'));
return directories.filter(function (directory) {
const modulePromises = directories.filter(function (directory) {
return (new RegExp(pattern).test(directory));
}).map(function (name) {
var module = require(path.join(__dirname, '..', name));
return (module && typeof module.spec !== 'undefined') ? module.spec : null;
}).filter(function (x) { return x; });
var modulePromise = import(path.join(__dirname, '..', name, 'index.js'));
return modulePromise.then( module => {
return (module && typeof module.spec !== 'undefined') ? module.spec : null;
})
})
const modules = Promise.all(modulePromises)
return modules.then(ms => ms.filter(function (x) { return x; }));
}

exports.getSpecs = function (pattern) {
export function getSpecs(pattern) {
return function () {
return getMatchingModules(pattern);
};
};
}
18 changes: 12 additions & 6 deletions src/Test/Spec/Discovery.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@ module Test.Spec.Discovery (discover) where

import Prelude

import Control.Promise (Promise)
import Control.Promise as Promise
import Data.Traversable (sequence_)
import Effect (Effect)
import Effect.Class (class MonadEffect, liftEffect)
import Effect.Aff.Class (class MonadAff, liftAff)
import Test.Spec (Spec)

foreign import getSpecs :: String
-> Effect (Array (Spec Unit))
foreign import getSpecs
:: String
-> Effect (Promise (Array (Spec Unit)))

discover :: forall m. MonadEffect m => String
-> m (Spec Unit)
discover pattern = getSpecs pattern >>= (pure <<< sequence_) # liftEffect
discover
:: forall m
. MonadAff m
=> String
-> m (Spec Unit)
discover pattern = getSpecs pattern # Promise.toAffE >>= (pure <<< sequence_) # liftAff
2 changes: 1 addition & 1 deletion test/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ import Test.Spec.Reporter.Console (consoleReporter)
import Test.Spec.Runner (runSpec)

main :: Effect Unit
main = discover "Test\\.Spec\\.Discovery.*Spec" >>= runSpec [consoleReporter] >>> launchAff_
main = launchAff_ $ discover "Test\\.Spec\\.Discovery.*Spec" >>= runSpec [consoleReporter]

0 comments on commit 0ef42b2

Please sign in to comment.