Skip to content
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

Allow Multiple Glob/Path Arguments from CLI #47

Merged
merged 41 commits into from
Jan 10, 2020
Merged

Conversation

cpruitt
Copy link
Contributor

@cpruitt cpruitt commented Sep 17, 2019

Addresses:

I this is a PR to allow Multiple glob pattern arguments from the CLI. This will allow either multiple globs to be passed or will allow the shell to perform the expansion and pass multiple file path arguments. Each glob argument can have it's own # or : filter which is applied to any files matched by the glob. The same glob can be supplied multiple times with different filters. There is also an --example option which can be provided multiple times to specify global name filters which apply to all matched files.

Internally, the glob expansion step has been moved into the process of configuration criteria which happens very early on in the execution of the test runner (basically it's the first thing that happens). Instead of a single glob pattern, the configuration now holds an array of objects. Each object represents one unique file path (after glob expansion) along with any filters that have been provided for that path.

Criteria is now processed so that:

  • A single string or an array can be provided
  • Array elements are always expanded as globs by JavaScript, even if the shell already expanded them (See CLI should take multiple paths and not a glob pattern #44 (comment))
  • A Line number or function name filter suffix can be supplied as part of any glob in the array and it will only apply to files matching that glob pattern.
  • A global example (name) filter can also be provided as a string or array which will apply to all files (I'm open to changing the name of this property/flag)
  • After glob expansion duplicate files are removed with filters consolidated. Duplicate filters of the same type (line/name) are removed.
  • If a test name and a line number filter both resolve to the same test, that duplicate is not currently handled

As an example, given the arguments:

'./test/path/file-*.js#testOne' \
'./test/path/file-one.js#testOne' \
'./test/path/file-one.js#testTwo' \
'./test/path/file-two.js#testThree' \
'./test/path/file-two.js:56' \
'./test/path/file-two.js:78'

config.criteria.testFiles would be built as:

[
    {
        file: './test/path/file-one.js',
        name: ['testOne', 'testTwo']
    },
    {
        file: './test/path/file-two.js',
        name: ['testOne', 'testThree'],
        lineNumber: ['56', '78']
    },
]

Unit tests have been added for configure but they only cover the test criteria, not other aspects of the config.

Changes outside of configure have been made so that the existing SAFE tests are passing with these changes. (i.e. the criteria change doesn't break the world).

Bats tests have been added for the new CLI behavior. Bats tests are located in /safe along with other tests.

Readme has been updated with some additional information on multiple globs, name/line filters, and the global --example option.

CC: @searls @jasonkarns

agent-0028 and others added 6 commits September 4, 2019 17:50
TODO: Check with Justin to see what LTSrelease he wants to suggest for
developing teenytest.
This allows `criteria()` to accept either a single string or an array of test locator globs. It also accepts a second `userOptions` argument which is used to provide `userOptions.example` as a globally applied `name` filter.

The return value is an array of objects, each with a `.file` property and, possibly, a `.name` and `.lineNumber` property, each of which is an array of filters that should be applied to that file.
@cpruitt
Copy link
Contributor Author

cpruitt commented Sep 17, 2019

Oops, looks like CI is saying let declarations are a problem. I'll clean that up shortly.

cpruitt and others added 4 commits September 17, 2019 19:29
I avoid committing developer tool dotfiles to libraries, because they
typically support multiple versions of Node at a time (package.json 
engines being a more appropriate place to lock version ranges)
@searls
Copy link
Member

searls commented Sep 19, 2019

Made two small commits after cursory review. Basically tests pass and the tests seem to say what you want teenytest to do! I didn't have time to scrutinize the additions to criteria.js etc

/me ducks out and lets you look at the CLI

@cpruitt
Copy link
Contributor Author

cpruitt commented Sep 19, 2019

Thanks for the commits. I worked on some CLI tests a bit today. I'm going to finish those up and then plan to go back and refactor the config a bit. Would like (🤞🏼) to have it at least working and pretty solid by the end of the week.

@jasonkarns
Copy link
Member

We should probably combine the two bats "suites". Before this PR, we have a single bats test living under safe/example.bats (which is just a bats variant of the old example tests).

Strictly speaking, we could keep the bats tests under safe/ since it only runs .bats files but eh... @searls opinions on where the full e2e/cli tests should go in this project?

I'm somewhat tempted to just drop all the bats tests under safe/ since that's what they are. And we could rewrite the existing safe JS tests into bats, since they're already asserting on the CLI and TAP output.

@searls
Copy link
Member

searls commented Sep 19, 2019

@jasonkarns you're closer to both bats and this project than I've been for a while so I am glad to defer to you. Consolidation sounds like a good word to me

@cpruitt
Copy link
Contributor Author

cpruitt commented Sep 19, 2019

My initial thought (like @jasonkarns) was that the existing safe tests could be switched over to bats tests exercising the CLI and everything could be consolidated. While working on this PR, however, it seemed practical to just keep them separated as a mental "here's a bucket for the stuff I'm working with" and then consolidate afterward when I have a better grasp of what's being consolidated. While working on this I wanted to leave the existing JS SAFE tests in place as a check to be sure noting changed (or at least, if it did that it was appropriately handled).

Also, just as a minor status update: As I'm writing the CLI tests, the behavior of dealing with multiple per-file filters isn't turning out to be correct out of the box. The config is being set up the way we want but the tests look like they are being run with the named filters combined as "matches all of" instead of "matches any of" so the end result is that something like teenytest './test-file.js#test_aaa' './test-file.js#test_bbb' will result in zero tests being run.

- Remove unnecessary helper file
- Clean up and rename test_helper.bash
- Rename Bats CLI test file to teenytest.bats
Moves ./bats tests and fixtures into ./safe
Changes test:bats to test:safe:bats
Removes test:example (now run as part of test:safe:bats)
@cpruitt
Copy link
Contributor Author

cpruitt commented Oct 1, 2019

I've got teenytest working now with multiple glob/path args and have combined the ./bats tests into ./safe. The JS needs refactoring and docs need updating.

@searls
Copy link
Member

searls commented Oct 2, 2019

The JS needs refactoring and docs need updating.

Are you tackling that or are you suggesting someone else do?

@cpruitt
Copy link
Contributor Author

cpruitt commented Oct 2, 2019

@searls Sorry, that wasn’t very clear. Yes, I intend to do both of those. I wanted to leave an update on the PR that the multi-glob feature was working but that I still had some cleanup work to do.

@cpruitt cpruitt force-pushed the multiple-glob-args branch from ddabd97 to fa8f1ca Compare October 8, 2019 21:12
cpruitt and others added 15 commits November 25, 2019 14:06
This allows `criteria()` to accept either a single string or an array of test locator globs. It also accepts a second `userOptions` argument which is used to provide `userOptions.example` as a globally applied `name` filter.

The return value is an array of objects, each with a `.file` property and, possibly, a `.name` and `.lineNumber` property, each of which is an array of filters that should be applied to that file.
I avoid committing developer tool dotfiles to libraries, because they
typically support multiple versions of Node at a time (package.json 
engines being a more appropriate place to lock version ranges)
- Remove unnecessary helper file
- Clean up and rename test_helper.bash
- Rename Bats CLI test file to teenytest.bats
Moves ./bats tests and fixtures into ./safe
Changes test:bats to test:safe:bats
Removes test:example (now run as part of test:safe:bats)
@searls searls force-pushed the multiple-glob-args branch from 0e0f502 to 3d227cf Compare November 25, 2019 05:06
Copy link
Member

@searls searls left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, didn't read all the criteria changes very closely. I'm cool merging if we can rename the --example flag ❤️

README.md Outdated
The above will run tests named `red` and `blue` in the file `test/foo-test.js`
and tests on lines 14 and 28 in the file `test/bar-test.js`.

#### Locating with the `--example` option
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to re-read the PR a couple times to understand what was meant by --example, assuming this is a BDD/rspecism that leaked from the code. Would --name be more predictable and consistent with other tools like minitest?

If you agree, I'd ask you to change the name of this option to --name or similar before we merge

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@searls This has been changed to --name


// Consolidate criteria with duplicate file paths into a single criterion
// file paths with arrays of collected line / name filter values
testCriteria = consolidatedPathCriteria(testCriteria)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you be open to refactoring this so we're not re-assigning the same var over and over in the same function? Seems like the sort of thing that'd best(be(several(calls())))) to named functions, hopefully obviating the comments

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@searls I've refactored https://github.com/testdouble/teenytest/blob/92ce2b86d66845e4c0dbd5df59127b548cff2809/lib/configure/criteria.js. If anything still seems like it should be changed (or just rubs you the wrong way) let me know.

@cpruitt
Copy link
Contributor Author

cpruitt commented Nov 25, 2019

@searls If I recall, the --example naming came from a conversation with @jasonkarns about taking cues from rspec. I don't recall if that was explicit or if I was just taking the discussion too literally but, in any case, I don't disagree with changing it to --name.

I also don't disagree with the refactor to use nested functions. The variable reassignment was a decision of personal preference that I thought might not mesh well with the rest of the codebase. I personally still find nested(function_calls(to_be(harder_to(parse_quickly())))) and the way I had it made it easier for me to follow what I was doing, but I expect that I'm the exception, not the rule in that case. I'm happy to make the change. 🙂

@cpruitt cpruitt force-pushed the multiple-glob-args branch from 58eb467 to 62b3336 Compare January 9, 2020 15:41
@cpruitt cpruitt force-pushed the multiple-glob-args branch from 62b3336 to 92ce2b8 Compare January 9, 2020 16:19
@cpruitt
Copy link
Contributor Author

cpruitt commented Jan 9, 2020

@searls Sorry for the delay on the changes. Time has been a scarce resource lately. I added a few commits to address your change requests. If there’s anything else you’d like to see let me know.

@searls
Copy link
Member

searls commented Jan 10, 2020

Nice, looks fantastic! Good README, left the code better-factored and better-tested than you found it. I know it took a lot of calendar time to see to completion but I think this is a really great feature that sets teenytest apart from a lot of other runners, big and small. Thanks, Cliff!

@searls searls merged commit 22dfc47 into master Jan 10, 2020
@searls searls deleted the multiple-glob-args branch January 10, 2020 03:19
@searls
Copy link
Member

searls commented Jan 10, 2020

Landed in 5.3.0 👏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants