-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace reading .elmi files with a faster and less hacky approach #442
Conversation
Thanks @lydell, this is really exciting! A couple of thoughts up front: Realistically we will merge the elm-json PR before this (#356) so you will (after rebasing) be able to drop the dependency here. This PR touches quite a bit of the test runners nasty internal machinery so we will have to be careful and also strike the right balance between not changing too much too reduce the risk of breakage and not changing enough that the existing troublesome parts of the test runner cause issues! (For example, we have had complaints that process.exiting causes corrupted output because the stream doesn't get time to flush, I see this PR adds more process.exit -- not a bad thing -- so we need to be careful that we don't make the problem worse.) I will endeavour to review soon! Tagging @mpizenberg as I think this may be interesting to you :) |
This comment has been minimized.
This comment has been minimized.
Interesting indeed! |
This comment has been minimized.
This comment has been minimized.
Ah, I see! 2 of the added The remaining 2 are in places where we used to exit with “UnhandledPromiseRejection”. It’s unclear what happened before in those cases. But if anything I’d guess the new behavior is the same or at least not worse. Better handling with cleanup and stuff could be added in another PR. |
That makes sense! Consider the process.exit concern resolved 👍 |
Bad news 😟 With this PR, we only find a fraction of the number of tests as without it. (I am testing on my copy of https://github.com/elm-in-elm/compiler/). Will investigate futher! |
For reference this is my original sketch of this idea: https://gist.github.com/harrysarson/08acee2e8d8ffb0185b4b1020c08d756 |
Conflicts: lib/elm-test.js package.json tests/runner.js
Just like the no files found error.
Marking as “Ready for review” since I have no further ideas on things to improve (other than possibly adding a test for something – I’m all ears)! 🎉 |
model = | ||
{ available = Dict.empty | ||
, runInfo = | ||
{ testCount = 0 | ||
, globs = [] | ||
, paths = [] | ||
, fuzzRuns = 0 | ||
, initialSeed = 0 | ||
} | ||
, processes = 0 | ||
, nextTestToRun = 0 | ||
, results = [] | ||
, testReporter = createReporter report | ||
, autoFail = Nothing | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m not super happy about having to create an empty model that is never going to be used here, but it was the best I could come up with.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some quick comments/questions. On the whole is very solid :)
I need to have a proper look through the parser still.
Co-authored-by: Harry Sarson <[email protected]>
Instead we use the approach of <rtfeldman/node-test-runner#442> from which I have taken a lot of inspiration for this commit.
Fixes #211 Addresses #442 (comment) This PR makes a bunch of improvements to elm-test.js: - Properly validate CLI arguments: - Error on unknown flags. - Validate flag values early (seed and fuzz must be numbers, report must be console/json/junit). - Default flag values early, instead of in code generation or even in Elm. - elm-test.js is now 100% definitions, except the last line which is `main();` to kick things off. Previously, it was difficult to understand in what order things executed. There was some top-level code, a bunch of function definitions, some more top-level code, more functions, and so on. Now, you can follow the call stack from `main()`. Also, this means that there are way fewer global variables – functions now get passed what they depend on. - Use async/await where it helps (in preparation for merge conflicts with #464 – it should be possible to just pick this PR’s code for every conflict in elm-test.js). - Improved help message. Also, add some aliases, such as `-h`, for showing help. I find it super annoying when CLI tools make it difficult to find the help – which is the key to all other commands and flags. - Various cleanups. Help before: ``` Usage: elm-test init # Create example tests Usage: elm-test install PACKAGE # Like `elm install PACKAGE`, except it installs to "test-dependencies" in your elm.json Usage: elm-test TESTFILES # Run TESTFILES, for example tests/**/*.elm Usage: elm-test [--compiler /path/to/compiler] # Run tests Usage: elm-test [--seed integer] # Run with initial fuzzer seed Usage: elm-test [--fuzz integer] # Run with each fuzz test performing this many iterations Usage: elm-test [--report json, junit, or console (default)] # Print results to stdout in given format Usage: elm-test [--version] # Print version string and exit Usage: elm-test [--watch] # Run tests on file changes ``` Intermediate help (outdated): ``` elm-test init Create example tests elm-test Run tests in the tests/ folder elm-test TESTFILES Run TESTFILES, for example "src/**/*Tests.elm" elm-test install PACKAGE Like `elm install PACKAGE`, except it installs to "test-dependencies" in your elm.json Options: --compiler /path/to/compiler Use a custom path to an Elm executable. Default: elm --seed INT Run with a previous fuzzer seed. Default: A random seed --fuzz INT Run with each fuzz test performing this many iterations. Default: 100 --report json --report junit --report console Print results to stdout in the given format. Default: console --version Print version and exit --watch Run tests on file changes ``` [commander](https://github.com/tj/commander.js) help: ``` Usage: elm-test [options] [globs...] elm-test Run tests in the tests/ folder elm-test "src/**/*Tests.elm" Run tests in files matching the glob Options: --compiler <path> Use a custom path to an Elm executable (default: elm) --seed <int> Run with a previous fuzzer seed (default: 68917302767402) --fuzz <int> Run with each fuzz test performing this many iterations (default: 100) --report <json|junit|console> Print results to stdout in the given format (default: "console") --watch Run tests on file changes (default: false) --version Print version and exit -h, --help Show help Commands: init Create example tests install <package> Like `elm install package`, except it installs to "test-dependencies" in your elm.json make [globs...] Check files matching the globs for compilation errors help [command] Show help ```
elmi-to-json
binary. No longer need to rely on undocumented, internal binary formats.More about speed:
elm-test 'src/**/*Test.elm'
is used rather thantests/
. https://discourse.elm-lang.org/t/do-you-put-tests-outside-the-tests-folder/6386/11elm-test src/
, this PR results in a much bigger JS file (since we don’t know until runtime what is and isn’t aTest
). In this uncommon case, the wins from faster compilation time is eaten by slower execution time. Can be improved by improving parallelization in the future.Post merge follow up:
Original PR description (outdated)
This is a proof of concept for @harrysarson’s idea to determine what exposed values are tests at runtime (using JavaScript) instead of at compile time (using elmi-to-json).
Pros:
Cons:
TODO:
Notes:
elm-json solve
. Leverageelm-json solve
#356 adds elm-json, but not yet for finding exact dependencies of package projects.