From 9926b68f11c28261ac3df1e817e5956da4857ad1 Mon Sep 17 00:00:00 2001 From: Stoeffel Date: Thu, 4 Jan 2024 14:04:47 +0100 Subject: [PATCH 1/9] Read source-dirs from elm.json --- CHANGELOG.md | 8 +++-- Makefile | 5 +-- Readme.md | 2 +- bin/cli-helpers.js | 19 +++++++++- bin/runner.js | 35 +++++++++++++----- bin/templates/elm-verify-examples.json | 2 +- example/elm.json | 50 +++++++++++++------------- example/src-other/util/Other.elm | 13 +++++++ example/tests/elm-verify-examples.json | 13 +++---- package-lock.json | 4 +-- run-tests.sh | 2 +- tests/elm-verify-examples.json | 6 ++-- 12 files changed, 102 insertions(+), 57 deletions(-) create mode 100644 example/src-other/util/Other.elm diff --git a/CHANGELOG.md b/CHANGELOG.md index 0395800..84bdd4f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,15 +1,19 @@ # Changelog + All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). -## [Unreleased] +## 6.0.0 + +- Change elm-verify-examples.json to contain elm root and not source root. In addition it will respect source-directories defined in elm.json [#109](https://github.com/stoeffel/elm-verify-examples/pull/109) + +## 5.3.0 - Do not run tests by default, only generate [#65](https://github.com/stoeffel/elm-verify-examples/issues/65) - Add --run-tests (-r) option to run generated tests [#65](https://github.com/stoeffel/elm-verify-examples/issues/65) - ## 2.0.0 - We have a changelog now :tada: diff --git a/Makefile b/Makefile index 8acc92f..6d96108 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: npm-install build test watch release-major release-minor release-patch +.PHONY: npm-install build test watch release-major release-minor release-patch run-examples verify-own-docs npm-install: npm install @@ -11,8 +11,9 @@ verify-own-docs: build test: verify-own-docs ./run-tests.sh + run-examples: build - cd example && ../bin/cli.js + cd example && ../bin/cli.js --run-tests watch: watchexec \ diff --git a/Readme.md b/Readme.md index 1b417cc..3baec55 100644 --- a/Readme.md +++ b/Readme.md @@ -24,7 +24,7 @@ $ touch tests/elm-verify-examples.json ```json { - "root": "../src", + "elm-root": "..", "tests": ["Mock", "Mock.Foo.Bar.Moo", "./README.md"] } ``` diff --git a/bin/cli-helpers.js b/bin/cli-helpers.js index ff65f06..21b16a7 100644 --- a/bin/cli-helpers.js +++ b/bin/cli-helpers.js @@ -7,9 +7,26 @@ function loadVerifyExamplesConfig(configPath) { */ var verifyExamples = null; + var elmJson = null; try { verifyExamples = require(configPath); + if (verifyExamples["elm-root"] === undefined) { + throw new Error( + `elm-verify-examples.json at ${configPath} does not have an elm-root key` + ); + } + if (verifyExamples["root"] !== undefined) { + throw new Error( + `elm-verify-examples.json at ${configPath} has a root key, but it should be elm-root and point to the location of elm.json` + ); + } + var elmJsonPath = path.join( + path.dirname(configPath), + verifyExamples["elm-root"], + "elm.json" + ); + elmJson = require(elmJsonPath); } catch (e) { console.log(`Copying initial elm-verify-examples.json to ${configPath}`); fsExtra.copySync( @@ -23,7 +40,7 @@ function loadVerifyExamplesConfig(configPath) { )); } - return resolveTests(configPath, verifyExamples); + return resolveTests(configPath, Object.assign({}, verifyExamples, elmJson)); } function resolveTests(configPath, config) { diff --git a/bin/runner.js b/bin/runner.js index 2eeb405..9dc172f 100644 --- a/bin/runner.js +++ b/bin/runner.js @@ -50,9 +50,9 @@ function generate(model, allTestsGenerated) { }); }); } else { - var pathToModule = path.join( - model.testsPath, - model.root, + var pathToModule = findModule( + path.join(model.testsPath, model["elm-root"]), + model["source-directories"], elmModuleToPath(inputName) ); @@ -154,7 +154,13 @@ function forFiles(model, files) { .filter(function (v) { return v.endsWith(".elm"); }) - .map(elmPathToModule(model.root, model.testsPath)); + .map( + elmPathToModule( + model["elm-root"], + model["source-directories"], + model.testsPath + ) + ); return model; } @@ -215,12 +221,9 @@ function writeFile(testsDocPath) { }; } -function elmPathToModule(root, testsPath) { +function elmPathToModule(elmRoot, sourceDirs, testsPath) { return function (pathName) { - var relativePath = path.relative( - path.resolve(path.join(testsPath, root)), - pathName - ); + var relativePath = findModule(elmRoot, sourceDirs, pathName); if (relativePath.startsWith("./")) { relativePath = relativePath.substr(2); } @@ -228,6 +231,20 @@ function elmPathToModule(root, testsPath) { }; } +function findModule(elmRoot, sourceDirs, pathName) { + for (var i = 0; i < sourceDirs.length; i++) { + const dir = sourceDirs[i]; + const module = path.join(elmRoot, dir, pathName); + if (fs.existsSync(module)) { + return module; + } + } + console.error( + `Could not find module ${pathName} in ${sourceDirs} with root ${elmRoot}` + ); + process.exit(1); +} + function elmModuleToPath(moduleName) { return moduleName.replace(/\./g, "/") + ".elm"; } diff --git a/bin/templates/elm-verify-examples.json b/bin/templates/elm-verify-examples.json index 7f2c8f2..a5eb901 100644 --- a/bin/templates/elm-verify-examples.json +++ b/bin/templates/elm-verify-examples.json @@ -1,4 +1,4 @@ { - "root": "../src", + "elm-root": "..", "tests": [] } diff --git a/example/elm.json b/example/elm.json index fb428a3..e2fdf8a 100644 --- a/example/elm.json +++ b/example/elm.json @@ -1,30 +1,28 @@ { - "type": "application", - "source-directories": [ - "src" - ], - "elm-version": "0.19.0", - "dependencies": { - "direct": { - "elm/browser": "1.0.0", - "elm/core": "1.0.0", - "elm/html": "1.0.0", - "elm/json": "1.0.0", - "elm/regex": "1.0.0", - "elm-community/list-extra": "8.0.0" - }, - "indirect": { - "elm/time": "1.0.0", - "elm/url": "1.0.0", - "elm/virtual-dom": "1.0.0" - } + "type": "application", + "source-directories": ["src", "src-other/util"], + "elm-version": "0.19.0", + "dependencies": { + "direct": { + "elm/browser": "1.0.0", + "elm/core": "1.0.0", + "elm/html": "1.0.0", + "elm/json": "1.0.0", + "elm/regex": "1.0.0", + "elm-community/list-extra": "8.0.0" }, - "test-dependencies": { - "direct": { - "elm-explorations/test": "1.0.0" - }, - "indirect": { - "elm/random": "1.0.0" - } + "indirect": { + "elm/time": "1.0.0", + "elm/url": "1.0.0", + "elm/virtual-dom": "1.0.0" } + }, + "test-dependencies": { + "direct": { + "elm-explorations/test": "1.0.0" + }, + "indirect": { + "elm/random": "1.0.0" + } + } } diff --git a/example/src-other/util/Other.elm b/example/src-other/util/Other.elm new file mode 100644 index 0000000..2a3014f --- /dev/null +++ b/example/src-other/util/Other.elm @@ -0,0 +1,13 @@ +module Other exposing (other) + +{-| -} + + +{-| Stuff + + other 4 --> 4 + +-} +other : Int -> Int +other x = + x + 1 diff --git a/example/tests/elm-verify-examples.json b/example/tests/elm-verify-examples.json index d2e9284..14f7558 100644 --- a/example/tests/elm-verify-examples.json +++ b/example/tests/elm-verify-examples.json @@ -1,5 +1,5 @@ { - "root": "../src", + "elm-root": "..", "tests": [ "Mock", "Mock.Foo.Bar.Moo", @@ -7,20 +7,17 @@ "Failing", "Todo", "FalseTodo", - "README.md" + "README.md", + "Other" ], "ignoreWarnings": { "Mock.Foo.Bar.Moo": [ { "name": "dontCare", - "ignore": [ - "NoExampleForExposedDefinition" - ] + "ignore": ["NoExampleForExposedDefinition"] }, { - "ignore": [ - "ExposingDotDot" - ] + "ignore": ["ExposingDotDot"] } ] } diff --git a/package-lock.json b/package-lock.json index e403258..7fde1da 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "elm-verify-examples", - "version": "5.2.0", + "version": "5.3.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "elm-verify-examples", - "version": "5.2.0", + "version": "5.3.0", "license": "BSD-3-Clause", "dependencies": { "chalk": "^4.1.2", diff --git a/run-tests.sh b/run-tests.sh index 71f423f..4a091ab 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash PASSED_COUNT=34 -FAILED_COUNT=2 +FAILED_COUNT=3 TODO_COUNT=1 pushd example diff --git a/tests/elm-verify-examples.json b/tests/elm-verify-examples.json index c6c7237..6d51986 100644 --- a/tests/elm-verify-examples.json +++ b/tests/elm-verify-examples.json @@ -1,6 +1,4 @@ { - "root": "../src", - "tests": [ - "String.Util" - ] + "elm-root": "..", + "tests": ["String.Util"] } From 136b7623c093407af609e6bd3eb0a433753d4f18 Mon Sep 17 00:00:00 2001 From: Christoph Hermann Date: Mon, 8 Jan 2024 12:41:31 +0100 Subject: [PATCH 2/9] Update bin/cli-helpers.js Co-authored-by: Johannes Emerich --- bin/cli-helpers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/cli-helpers.js b/bin/cli-helpers.js index 21b16a7..f94258c 100644 --- a/bin/cli-helpers.js +++ b/bin/cli-helpers.js @@ -18,7 +18,7 @@ function loadVerifyExamplesConfig(configPath) { } if (verifyExamples["root"] !== undefined) { throw new Error( - `elm-verify-examples.json at ${configPath} has a root key, but it should be elm-root and point to the location of elm.json` + `elm-verify-examples.json at ${configPath} has a root key, but it should be elm-root and point to the root of the Elm project` ); } var elmJsonPath = path.join( From 26acf923430037dae864ddfde24d297a312a914a Mon Sep 17 00:00:00 2001 From: Stoeffel Date: Mon, 8 Jan 2024 13:50:31 +0100 Subject: [PATCH 3/9] Add default for elm-root --- Readme.md | 2 +- bin/cli-helpers.js | 4 +--- example/tests/elm-verify-examples.json | 1 - 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/Readme.md b/Readme.md index 3baec55..7f44d22 100644 --- a/Readme.md +++ b/Readme.md @@ -24,7 +24,7 @@ $ touch tests/elm-verify-examples.json ```json { - "elm-root": "..", + "elm-root": "..", -- directory of elm.json. default is `..` "tests": ["Mock", "Mock.Foo.Bar.Moo", "./README.md"] } ``` diff --git a/bin/cli-helpers.js b/bin/cli-helpers.js index f94258c..872446b 100644 --- a/bin/cli-helpers.js +++ b/bin/cli-helpers.js @@ -12,9 +12,7 @@ function loadVerifyExamplesConfig(configPath) { try { verifyExamples = require(configPath); if (verifyExamples["elm-root"] === undefined) { - throw new Error( - `elm-verify-examples.json at ${configPath} does not have an elm-root key` - ); + verifyExamples["elm-root"] = ".."; } if (verifyExamples["root"] !== undefined) { throw new Error( diff --git a/example/tests/elm-verify-examples.json b/example/tests/elm-verify-examples.json index 14f7558..0861269 100644 --- a/example/tests/elm-verify-examples.json +++ b/example/tests/elm-verify-examples.json @@ -1,5 +1,4 @@ { - "elm-root": "..", "tests": [ "Mock", "Mock.Foo.Bar.Moo", From 98b79ca2a05c4af1cc8fc2c2f22f7f1524752b44 Mon Sep 17 00:00:00 2001 From: Christoph Hermann Date: Mon, 8 Jan 2024 13:52:01 +0100 Subject: [PATCH 4/9] Update CHANGELOG.md Co-authored-by: Jakub Hampl --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 84bdd4f..a5215fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Change elm-verify-examples.json to contain elm root and not source root. In addition it will respect source-directories defined in elm.json [#109](https://github.com/stoeffel/elm-verify-examples/pull/109) + To migrate, replace the "root" key in your config file for a "elm-root" pointing to the folder containing your elm.json file. Typically this will look like this: + + ```diff + - "root": "../src", + + "elm-root": "..", + ``` + ## 5.3.0 - Do not run tests by default, only generate [#65](https://github.com/stoeffel/elm-verify-examples/issues/65) From 4b9cb2f1068a444463ed7b757a83bec552e60b4a Mon Sep 17 00:00:00 2001 From: Stoeffel Date: Tue, 9 Jan 2024 10:58:01 +0100 Subject: [PATCH 5/9] Remove root completely --- CHANGELOG.md | 15 +++++++-------- Readme.md | 1 - bin/cli-helpers.js | 11 ++--------- bin/runner.js | 10 ++-------- bin/templates/elm-verify-examples.json | 1 - tests/elm-verify-examples.json | 1 - 6 files changed, 11 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a5215fc..167f995 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,14 +7,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## 6.0.0 -- Change elm-verify-examples.json to contain elm root and not source root. In addition it will respect source-directories defined in elm.json [#109](https://github.com/stoeffel/elm-verify-examples/pull/109) - - To migrate, replace the "root" key in your config file for a "elm-root" pointing to the folder containing your elm.json file. Typically this will look like this: - - ```diff - - "root": "../src", - + "elm-root": "..", - ``` +- Remove `root` from elm-verify-examples.json. In addition it will respect source-directories defined in elm.json [#109](https://github.com/stoeffel/elm-verify-examples/pull/109) + + To migrate, remove the "root" key in your config file and move it into `/tests`. + + ```diff + - "root": "../src", + ``` ## 5.3.0 diff --git a/Readme.md b/Readme.md index 7f44d22..9d99594 100644 --- a/Readme.md +++ b/Readme.md @@ -24,7 +24,6 @@ $ touch tests/elm-verify-examples.json ```json { - "elm-root": "..", -- directory of elm.json. default is `..` "tests": ["Mock", "Mock.Foo.Bar.Moo", "./README.md"] } ``` diff --git a/bin/cli-helpers.js b/bin/cli-helpers.js index 872446b..6c0f3fe 100644 --- a/bin/cli-helpers.js +++ b/bin/cli-helpers.js @@ -11,19 +11,12 @@ function loadVerifyExamplesConfig(configPath) { try { verifyExamples = require(configPath); - if (verifyExamples["elm-root"] === undefined) { - verifyExamples["elm-root"] = ".."; - } if (verifyExamples["root"] !== undefined) { throw new Error( - `elm-verify-examples.json at ${configPath} has a root key, but it should be elm-root and point to the root of the Elm project` + "elm-verify-examples.json: 'root' is no longer a valid key. It defaults to point one directory up from `/tests`." ); } - var elmJsonPath = path.join( - path.dirname(configPath), - verifyExamples["elm-root"], - "elm.json" - ); + var elmJsonPath = path.join(path.dirname(configPath), "..", "elm.json"); elmJson = require(elmJsonPath); } catch (e) { console.log(`Copying initial elm-verify-examples.json to ${configPath}`); diff --git a/bin/runner.js b/bin/runner.js index 9dc172f..5e1b0ff 100644 --- a/bin/runner.js +++ b/bin/runner.js @@ -51,7 +51,7 @@ function generate(model, allTestsGenerated) { }); } else { var pathToModule = findModule( - path.join(model.testsPath, model["elm-root"]), + path.join(model.testsPath, ".."), model["source-directories"], elmModuleToPath(inputName) ); @@ -154,13 +154,7 @@ function forFiles(model, files) { .filter(function (v) { return v.endsWith(".elm"); }) - .map( - elmPathToModule( - model["elm-root"], - model["source-directories"], - model.testsPath - ) - ); + .map(elmPathToModule("..", model["source-directories"], model.testsPath)); return model; } diff --git a/bin/templates/elm-verify-examples.json b/bin/templates/elm-verify-examples.json index a5eb901..08b8a0e 100644 --- a/bin/templates/elm-verify-examples.json +++ b/bin/templates/elm-verify-examples.json @@ -1,4 +1,3 @@ { - "elm-root": "..", "tests": [] } diff --git a/tests/elm-verify-examples.json b/tests/elm-verify-examples.json index 6d51986..0f02dc6 100644 --- a/tests/elm-verify-examples.json +++ b/tests/elm-verify-examples.json @@ -1,4 +1,3 @@ { - "elm-root": "..", "tests": ["String.Util"] } From 55680ab4111007abf2b9d409b776a8b06b82fd52 Mon Sep 17 00:00:00 2001 From: Stoeffel Date: Tue, 9 Jan 2024 14:05:47 +0100 Subject: [PATCH 6/9] Dry reading elm.json --- bin/cli-helpers.js | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/bin/cli-helpers.js b/bin/cli-helpers.js index 6c0f3fe..ba0aff9 100644 --- a/bin/cli-helpers.js +++ b/bin/cli-helpers.js @@ -16,7 +16,7 @@ function loadVerifyExamplesConfig(configPath) { "elm-verify-examples.json: 'root' is no longer a valid key. It defaults to point one directory up from `/tests`." ); } - var elmJsonPath = path.join(path.dirname(configPath), "..", "elm.json"); + var elmJsonPath = findParentElmJson(path.dirname(configPath)); elmJson = require(elmJsonPath); } catch (e) { console.log(`Copying initial elm-verify-examples.json to ${configPath}`); @@ -36,21 +36,8 @@ function loadVerifyExamplesConfig(configPath) { function resolveTests(configPath, config) { if (config.tests === "exposed") { - /* This is asserting that we want to run for all exposed modules in a package - */ - var elmJson = null; - var elmJsonPath = findParentElmJson(path.dirname(configPath)); - try { - elmJson = require(elmJsonPath); - } catch (e) { - console.error( - "Config asks for 'exposed', but could not find elm.json at " + - elmJsonPath - ); - process.exit(1); - } - if (elmJson.type == "package") { - config.tests = elmJson["exposed-modules"].concat("./README.md"); + if (config.type == "package") { + config.tests = config["exposed-modules"].concat("./README.md"); } else { console.error( "Config asks for 'exposed', but elm.json type is not 'package'" From d3d111f2189e81429c7d9b916f8346a1a0c5e2cc Mon Sep 17 00:00:00 2001 From: Stoeffel Date: Wed, 10 Jan 2024 10:36:45 +0100 Subject: [PATCH 7/9] Verify all elm files --- CHANGELOG.md | 20 ++- Readme.md | 18 +++ bin/cli-helpers.js | 31 ++-- bin/runner.js | 9 +- bin/templates/elm-verify-examples.json | 3 - example/tests/elm-verify-examples.json | 23 --- package-lock.json | 216 ++++++------------------- package.json | 1 + run-tests.sh | 4 +- src/VerifyExamples.elm | 5 +- 10 files changed, 117 insertions(+), 213 deletions(-) delete mode 100644 bin/templates/elm-verify-examples.json delete mode 100644 example/tests/elm-verify-examples.json diff --git a/CHANGELOG.md b/CHANGELOG.md index 167f995..c798bfb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,13 +7,23 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## 6.0.0 -- Remove `root` from elm-verify-examples.json. In addition it will respect source-directories defined in elm.json [#109](https://github.com/stoeffel/elm-verify-examples/pull/109) +- Make `elm-verify-examples.json` optional [#110](https://github.com/stoeffel/elm-verify-examples/pull/110) - To migrate, remove the "root" key in your config file and move it into `/tests`. + - Run elm-verify-examples on all elm files in source directory by default. - ```diff - - "root": "../src", - ``` + - Add option `all` to `elm-verify-examples.json` to verify all elm files. + + ```diff + + "tests": "all" + ``` + + - Remove `root` from elm-verify-examples.json. In addition it will respect source-directories defined in elm.json + + To migrate, remove the "root" key in your config file and move it into `/tests`. + + ```diff + - "root": "../src", + ``` ## 5.3.0 diff --git a/Readme.md b/Readme.md index 9d99594..1f300f7 100644 --- a/Readme.md +++ b/Readme.md @@ -16,6 +16,8 @@ $ elm-test init ## Setup +There is no need for any configuration. elm-verify-examples will run on all elm files in the specified `source-directories` (`elm.json`). It's possible to create a config file if you want to run it on only a supset of files or on additional markdown files. + ```bash $ touch tests/elm-verify-examples.json ``` @@ -28,6 +30,22 @@ $ touch tests/elm-verify-examples.json } ``` +Alternatively you can run elm-verify-examples on all elm files in your source directories: + +```json +{ + "tests": "all" +} +``` + +or + +```json +{ + "tests": ["all", "Some.md"] +} +``` + It's recommended to add `./tests/VerifyExamples` to your `.gitignore`. If you are building a _package_, you can pass the string `"exposed"` instead of an explicit list of modules, diff --git a/bin/cli-helpers.js b/bin/cli-helpers.js index ba0aff9..c453c42 100644 --- a/bin/cli-helpers.js +++ b/bin/cli-helpers.js @@ -1,5 +1,6 @@ var path = require("path"); var fsExtra = require("fs-extra"); +const { globSync } = require("glob"); function loadVerifyExamplesConfig(configPath) { /* load the doc test config if we can find it @@ -19,23 +20,16 @@ function loadVerifyExamplesConfig(configPath) { var elmJsonPath = findParentElmJson(path.dirname(configPath)); elmJson = require(elmJsonPath); } catch (e) { - console.log(`Copying initial elm-verify-examples.json to ${configPath}`); - fsExtra.copySync( - path.resolve(__dirname, "./templates/elm-verify-examples.json"), - configPath - ); - - verifyExamples = require(path.resolve( - __dirname, - "templates/elm-verify-examples.json" - )); + var elmJsonPath = findParentElmJson(path.dirname(configPath)); + elmJson = require(elmJsonPath); + verifyExamples = { tests: "all" }; } return resolveTests(configPath, Object.assign({}, verifyExamples, elmJson)); } function resolveTests(configPath, config) { - if (config.tests === "exposed") { + if (config.tests === "exposed" || config.tests.includes("exposed")) { if (config.type == "package") { config.tests = config["exposed-modules"].concat("./README.md"); } else { @@ -45,6 +39,17 @@ function resolveTests(configPath, config) { process.exit(1); } } + if (config.tests === "all" || config.tests.includes("all")) { + var allElmFiles = config["source-directories"] + .map((d) => + globSync("**/*.elm", { + cwd: path.join(path.dirname(configPath), "..", d), + }) + ) + .flat() + .map(elmPathToModuleName); + config.tests = allElmFiles.concat("./README.md"); + } return config; } @@ -59,6 +64,10 @@ function findParentElmJson(p) { } } +function elmPathToModuleName(pathName) { + return pathName.slice(0, -4).replace(/\//g, "."); +} + module.exports = { loadVerifyExamplesConfig: loadVerifyExamplesConfig, }; diff --git a/bin/runner.js b/bin/runner.js index 5e1b0ff..82bffb2 100644 --- a/bin/runner.js +++ b/bin/runner.js @@ -73,10 +73,17 @@ function generate(model, allTestsGenerated) { }); var writtenTests = 0; + var noExamples = 0; + app.ports.noExamples.subscribe(function () { + noExamples = noExamples + 1; + }); app.ports.writeFiles.subscribe(function (data) { serial(data, writeFile(model.testsDocPath), function () { writtenTests = writtenTests + 1; - if (writtenTests === model.tests.length && allTestsGenerated) { + if ( + writtenTests + noExamples === model.tests.length && + allTestsGenerated + ) { allTestsGenerated(warnings); } }); diff --git a/bin/templates/elm-verify-examples.json b/bin/templates/elm-verify-examples.json deleted file mode 100644 index 08b8a0e..0000000 --- a/bin/templates/elm-verify-examples.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "tests": [] -} diff --git a/example/tests/elm-verify-examples.json b/example/tests/elm-verify-examples.json deleted file mode 100644 index 0861269..0000000 --- a/example/tests/elm-verify-examples.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "tests": [ - "Mock", - "Mock.Foo.Bar.Moo", - "Robustness", - "Failing", - "Todo", - "FalseTodo", - "README.md", - "Other" - ], - "ignoreWarnings": { - "Mock.Foo.Bar.Moo": [ - { - "name": "dontCare", - "ignore": ["NoExampleForExposedDefinition"] - }, - { - "ignore": ["ExposingDotDot"] - } - ] - } -} diff --git a/package-lock.json b/package-lock.json index 7fde1da..dd6fe77 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,6 +12,7 @@ "chalk": "^4.1.2", "elm-test": "^0.19.1-revision7", "fs-extra": "^11.1.1", + "glob": "^10.3.10", "mkdirp": "^3.0.1", "rimraf": "^5.0.5", "yargs": "^17.7.2" @@ -440,21 +441,6 @@ "node": "^14.17.0 || ^16.13.0 || >=18.0.0" } }, - "node_modules/@tufjs/models/node_modules/minimatch": { - "version": "9.0.3", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.3.tgz", - "integrity": "sha512-RHiac9mvaRw0x3AYRgDC1CxAP7HTcNrrECeA8YYJeWnpo+2Q5CegtZjaotWTWxDG3UeGA1coE05iH1mPjT/2mg==", - "dev": true, - "dependencies": { - "brace-expansion": "^2.0.1" - }, - "engines": { - "node": ">=16 || 14 >=14.17" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, "node_modules/@types/http-cache-semantics": { "version": "4.0.3", "resolved": "https://registry.npmjs.org/@types/http-cache-semantics/-/http-cache-semantics-4.0.3.tgz", @@ -776,43 +762,6 @@ "node": "^14.17.0 || ^16.13.0 || >=18.0.0" } }, - "node_modules/cacache/node_modules/glob": { - "version": "10.3.10", - "resolved": "https://registry.npmjs.org/glob/-/glob-10.3.10.tgz", - "integrity": "sha512-fa46+tv1Ak0UPK1TOy/pZrIybNNt4HCv7SDzwyfiOZkvZLEbjsZkJBPtDHVshZjbecAoAGSC20MjLDG/qr679g==", - "dev": true, - "dependencies": { - "foreground-child": "^3.1.0", - "jackspeak": "^2.3.5", - "minimatch": "^9.0.1", - "minipass": "^5.0.0 || ^6.0.2 || ^7.0.0", - "path-scurry": "^1.10.1" - }, - "bin": { - "glob": "dist/esm/bin.mjs" - }, - "engines": { - "node": ">=16 || 14 >=14.17" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, - "node_modules/cacache/node_modules/minimatch": { - "version": "9.0.3", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.3.tgz", - "integrity": "sha512-RHiac9mvaRw0x3AYRgDC1CxAP7HTcNrrECeA8YYJeWnpo+2Q5CegtZjaotWTWxDG3UeGA1coE05iH1mPjT/2mg==", - "dev": true, - "dependencies": { - "brace-expansion": "^2.0.1" - }, - "engines": { - "node": ">=16 || 14 >=14.17" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, "node_modules/cacache/node_modules/minipass": { "version": "7.0.4", "resolved": "https://registry.npmjs.org/minipass/-/minipass-7.0.4.tgz", @@ -1211,6 +1160,35 @@ "node": ">=12.20.0" } }, + "node_modules/elm-test/node_modules/glob": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/glob/-/glob-8.1.0.tgz", + "integrity": "sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ==", + "dependencies": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^5.0.1", + "once": "^1.3.0" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/elm-test/node_modules/minimatch": { + "version": "5.1.6", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.6.tgz", + "integrity": "sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==", + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/emoji-regex": { "version": "8.0.0", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", @@ -1457,18 +1435,21 @@ } }, "node_modules/glob": { - "version": "8.1.0", - "resolved": "https://registry.npmjs.org/glob/-/glob-8.1.0.tgz", - "integrity": "sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ==", + "version": "10.3.10", + "resolved": "https://registry.npmjs.org/glob/-/glob-10.3.10.tgz", + "integrity": "sha512-fa46+tv1Ak0UPK1TOy/pZrIybNNt4HCv7SDzwyfiOZkvZLEbjsZkJBPtDHVshZjbecAoAGSC20MjLDG/qr679g==", "dependencies": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^5.0.1", - "once": "^1.3.0" + "foreground-child": "^3.1.0", + "jackspeak": "^2.3.5", + "minimatch": "^9.0.1", + "minipass": "^5.0.0 || ^6.0.2 || ^7.0.0", + "path-scurry": "^1.10.1" + }, + "bin": { + "glob": "dist/esm/bin.mjs" }, "engines": { - "node": ">=12" + "node": ">=16 || 14 >=14.17" }, "funding": { "url": "https://github.com/sponsors/isaacs" @@ -1695,21 +1676,6 @@ "node": "^14.17.0 || ^16.13.0 || >=18.0.0" } }, - "node_modules/ignore-walk/node_modules/minimatch": { - "version": "9.0.3", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.3.tgz", - "integrity": "sha512-RHiac9mvaRw0x3AYRgDC1CxAP7HTcNrrECeA8YYJeWnpo+2Q5CegtZjaotWTWxDG3UeGA1coE05iH1mPjT/2mg==", - "dev": true, - "dependencies": { - "brace-expansion": "^2.0.1" - }, - "engines": { - "node": ">=16 || 14 >=14.17" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, "node_modules/import-lazy": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/import-lazy/-/import-lazy-4.0.0.tgz", @@ -2126,14 +2092,17 @@ } }, "node_modules/minimatch": { - "version": "5.1.6", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.6.tgz", - "integrity": "sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==", + "version": "9.0.3", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.3.tgz", + "integrity": "sha512-RHiac9mvaRw0x3AYRgDC1CxAP7HTcNrrECeA8YYJeWnpo+2Q5CegtZjaotWTWxDG3UeGA1coE05iH1mPjT/2mg==", "dependencies": { "brace-expansion": "^2.0.1" }, "engines": { - "node": ">=10" + "node": ">=16 || 14 >=14.17" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" } }, "node_modules/minimist": { @@ -2618,21 +2587,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/npm-check-updates/node_modules/minimatch": { - "version": "9.0.3", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.3.tgz", - "integrity": "sha512-RHiac9mvaRw0x3AYRgDC1CxAP7HTcNrrECeA8YYJeWnpo+2Q5CegtZjaotWTWxDG3UeGA1coE05iH1mPjT/2mg==", - "dev": true, - "dependencies": { - "brace-expansion": "^2.0.1" - }, - "engines": { - "node": ">=16 || 14 >=14.17" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, "node_modules/npm-check-updates/node_modules/p-limit": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz", @@ -3122,43 +3076,6 @@ "node": "^14.17.0 || ^16.13.0 || >=18.0.0" } }, - "node_modules/read-package-json/node_modules/glob": { - "version": "10.3.10", - "resolved": "https://registry.npmjs.org/glob/-/glob-10.3.10.tgz", - "integrity": "sha512-fa46+tv1Ak0UPK1TOy/pZrIybNNt4HCv7SDzwyfiOZkvZLEbjsZkJBPtDHVshZjbecAoAGSC20MjLDG/qr679g==", - "dev": true, - "dependencies": { - "foreground-child": "^3.1.0", - "jackspeak": "^2.3.5", - "minimatch": "^9.0.1", - "minipass": "^5.0.0 || ^6.0.2 || ^7.0.0", - "path-scurry": "^1.10.1" - }, - "bin": { - "glob": "dist/esm/bin.mjs" - }, - "engines": { - "node": ">=16 || 14 >=14.17" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, - "node_modules/read-package-json/node_modules/minimatch": { - "version": "9.0.3", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.3.tgz", - "integrity": "sha512-RHiac9mvaRw0x3AYRgDC1CxAP7HTcNrrECeA8YYJeWnpo+2Q5CegtZjaotWTWxDG3UeGA1coE05iH1mPjT/2mg==", - "dev": true, - "dependencies": { - "brace-expansion": "^2.0.1" - }, - "engines": { - "node": ">=16 || 14 >=14.17" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, "node_modules/readable-stream": { "version": "3.6.2", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", @@ -3294,41 +3211,6 @@ "url": "https://github.com/sponsors/isaacs" } }, - "node_modules/rimraf/node_modules/glob": { - "version": "10.3.10", - "resolved": "https://registry.npmjs.org/glob/-/glob-10.3.10.tgz", - "integrity": "sha512-fa46+tv1Ak0UPK1TOy/pZrIybNNt4HCv7SDzwyfiOZkvZLEbjsZkJBPtDHVshZjbecAoAGSC20MjLDG/qr679g==", - "dependencies": { - "foreground-child": "^3.1.0", - "jackspeak": "^2.3.5", - "minimatch": "^9.0.1", - "minipass": "^5.0.0 || ^6.0.2 || ^7.0.0", - "path-scurry": "^1.10.1" - }, - "bin": { - "glob": "dist/esm/bin.mjs" - }, - "engines": { - "node": ">=16 || 14 >=14.17" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, - "node_modules/rimraf/node_modules/minimatch": { - "version": "9.0.3", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.3.tgz", - "integrity": "sha512-RHiac9mvaRw0x3AYRgDC1CxAP7HTcNrrECeA8YYJeWnpo+2Q5CegtZjaotWTWxDG3UeGA1coE05iH1mPjT/2mg==", - "dependencies": { - "brace-expansion": "^2.0.1" - }, - "engines": { - "node": ">=16 || 14 >=14.17" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, "node_modules/run-parallel": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz", diff --git a/package.json b/package.json index bc6db86..5dd7e53 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "chalk": "^4.1.2", "elm-test": "^0.19.1-revision7", "fs-extra": "^11.1.1", + "glob": "^10.3.10", "mkdirp": "^3.0.1", "rimraf": "^5.0.5", "yargs": "^17.7.2" diff --git a/run-tests.sh b/run-tests.sh index 4a091ab..8c5ab5c 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash -PASSED_COUNT=34 -FAILED_COUNT=3 +PASSED_COUNT=35 +FAILED_COUNT=5 TODO_COUNT=1 pushd example diff --git a/src/VerifyExamples.elm b/src/VerifyExamples.elm index 3044af4..f4446cb 100644 --- a/src/VerifyExamples.elm +++ b/src/VerifyExamples.elm @@ -89,7 +89,7 @@ generateTests : List Compiler.Result -> Cmd Msg generateTests tests = case tests of [] -> - Cmd.none + noExamples () _ -> tests @@ -137,6 +137,9 @@ port readFile : String -> Cmd msg port writeFiles : Value -> Cmd msg +port noExamples : () -> Cmd msg + + port generateModuleVerifyExamples : (Value -> msg) -> Sub msg From 099e458a4a8aebdec1db1816ed830b00535964e3 Mon Sep 17 00:00:00 2001 From: Christoph Hermann Date: Mon, 15 Jan 2024 12:03:20 +0100 Subject: [PATCH 8/9] fix typo Co-authored-by: Johannes Emerich --- Readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index 1f300f7..fe7a35a 100644 --- a/Readme.md +++ b/Readme.md @@ -16,7 +16,7 @@ $ elm-test init ## Setup -There is no need for any configuration. elm-verify-examples will run on all elm files in the specified `source-directories` (`elm.json`). It's possible to create a config file if you want to run it on only a supset of files or on additional markdown files. +There is no need for any configuration. elm-verify-examples will run on all elm files in the specified `source-directories` (`elm.json`). It's possible to create a config file if you want to run it on only a subset of files or on additional markdown files. ```bash $ touch tests/elm-verify-examples.json From daeeaff3229b80052bcf72a2c7a3abc7fb44f583 Mon Sep 17 00:00:00 2001 From: Stoeffel Date: Mon, 15 Jan 2024 13:44:09 +0100 Subject: [PATCH 9/9] Warn about removed config --- bin/cli-helpers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/cli-helpers.js b/bin/cli-helpers.js index c453c42..0e1595c 100644 --- a/bin/cli-helpers.js +++ b/bin/cli-helpers.js @@ -13,7 +13,7 @@ function loadVerifyExamplesConfig(configPath) { try { verifyExamples = require(configPath); if (verifyExamples["root"] !== undefined) { - throw new Error( + console.warn( "elm-verify-examples.json: 'root' is no longer a valid key. It defaults to point one directory up from `/tests`." ); }