Skip to content

Commit

Permalink
Verify all elm files
Browse files Browse the repository at this point in the history
  • Loading branch information
stoeffel committed Jan 10, 2024
1 parent 55680ab commit fa9034e
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 208 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## 6.0.0

- 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 [#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`.
Expand Down
16 changes: 16 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,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,
Expand Down
31 changes: 20 additions & 11 deletions bin/cli-helpers.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 {
Expand All @@ -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;
}

Expand All @@ -59,6 +64,10 @@ function findParentElmJson(p) {
}
}

function elmPathToModuleName(pathName) {
return pathName.slice(0, -4).replace(/\//g, ".");
}

module.exports = {
loadVerifyExamplesConfig: loadVerifyExamplesConfig,
};
9 changes: 8 additions & 1 deletion bin/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
Expand Down
3 changes: 0 additions & 3 deletions bin/templates/elm-verify-examples.json

This file was deleted.

23 changes: 0 additions & 23 deletions example/tests/elm-verify-examples.json

This file was deleted.

Loading

0 comments on commit fa9034e

Please sign in to comment.