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

feat: return more data from getSuggestedQuery to support tooling #608

Merged
merged 3 commits into from Jun 8, 2020
Merged

Conversation

smeijer
Copy link
Member

@smeijer smeijer commented Jun 7, 2020

What:

1. Return rich data from getSuggestedQuery

I've added more data to the object that getSuggestedQuery returns. Before this change, the returned value would be something like:

{
  queryName: 'Role',
}

By calling the toString method, the caller would get more information, but formatted as string: (the full expression statement)

getByRole('button', { name: /submit/i })

With this change, the caller gets rich data, upon which he can build tooling.

Example result:

{
  queryName: 'Role',
  queryMethod: 'getByRole',
  queryArgs: ['button', { name: /submit/i }],
  variant: 'get'
}

2. Change formatting of the suggested query

Before this change, queries were returned with double quotes and without spacing. I've updated the toString() method to match the style that's being used throughout the docs.

// before
getByRole("button", {name: /submit/i});

// after
getByRole('button', { name: /submit/i });

3. Fix a small bug

The variant now defaults to get, to fix a bug that was causing suggestions like undefinedByRole(…) to be generated.

// before
getSuggestedQuery('button').toString() // » undefinedByRole("button")
 
// after
getSuggestedQuery('button').toString() // » getByRole('button') 

Why:

To support the development of tools around query suggestions.

How:

Checklist:

This PR fixes 3 related things. Let me know if you want me to break things up in separate branches.

Also, if you're not comfortable with the suggestion style change (single quotes and spaces in expression arguments), let me know, and I can undo that part.

I've added more data to the returned object, to support the development of tooling. Before this change, the returned value would be something like `{ queryName: 'Role' }`, and only by calling the `toString` method, the caller would get more information (the full formatted expression).

With this change, the caller gets more useful data, to build tooling around. Example result:

```
{
  queryName: 'Role',
  queryMethod: 'getByRole',
  queryArgs: ['button', { name: /submit/i }],
  variant: 'get'
}
```

The variant now defaults to `get`, to fix a bug that was causing suggestions like `undefinedByRole(…)` to be generated.
@codesandbox-ci
Copy link

codesandbox-ci bot commented Jun 7, 2020

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit fcdf49b:

Sandbox Source
dreamy-franklin-8eq2k Configuration

@smeijer
Copy link
Member Author

smeijer commented Jun 7, 2020

@kentcdodds , I'm not sure how to make travis happy. It's failing on The command "npm run validate" exited with 1., but npm run validate doesn't work locally either.

Is something off in kcd-scripts? Or am I missing something in my setup?

dom-testing-library on  patch-1 is 📦 v0.0.0-semantically-released 
➜ npm run validate

> @testing-library/dom@0.0.0-semantically-released validate /home/smeijer/dev/dom-testing-library
> kcd-scripts validate

[typecheck] internal/modules/cjs/loader.js:985
[typecheck]   throw err;
[typecheck]   ^
[typecheck] 
[typecheck] Error: Cannot find module 'typescript'

@timdeschryver
Copy link
Member

@smeijer this is probably because the code coverage doesn't reach 100%

image

@smeijer
Copy link
Member Author

smeijer commented Jun 7, 2020

@timdeschryver, thanks! That makes sense. A more descriptive error would have helped.

I'll take a look at it tomorrow, see if I can bump it back to 💯

*edit, I see now. I should have read the log better.

[test] Jest: "global" coverage threshold for branches (100%) not met: 99.72%
[test] 
[test] Test Suites: 28 passed, 28 total
[test] Tests:       538 passed, 538 total
[test] Snapshots:   123 passed, 123 total
[test] Time:        82.1 s
[test] Ran all test suites in 2 projects.
[test] npm run test --silent -- --coverage exited with code 1

@codecov
Copy link

codecov bot commented Jun 8, 2020

Codecov Report

Merging #608 into master will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #608   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           24        24           
  Lines          550       555    +5     
  Branches       137       138    +1     
=========================================
+ Hits           550       555    +5     
Impacted Files Coverage Δ
src/suggestions.js 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fb012de...fcdf49b. Read the comment docs.

@smeijer
Copy link
Member Author

smeijer commented Jun 8, 2020

Awesome. I'm ready 🎉

Copy link
Member

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

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

Super 👍

@kentcdodds kentcdodds merged commit a029772 into testing-library:master Jun 8, 2020
@kentcdodds
Copy link
Member

@all-contributors please add @smeijer for code and tests

@allcontributors
Copy link
Contributor

@kentcdodds

I've put up a pull request to add @smeijer! 🎉

@kentcdodds
Copy link
Member

🎉 This PR is included in version 7.11.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@kentcdodds
Copy link
Member

Thanks so much for your help! I've added you as a collaborator on the project. Please make sure that you review the other/MAINTAINING.md and CONTRIBUTING.md files (specifically the bit about the commit messages and the git hooks) and familiarize yourself with the code of conduct (we're using the contributor covenant). You might also want to watch the repo to be notified when someone files an issue/PR. Please continue to make PRs as you feel the need (you can make your branches directly on the repo rather than your fork if you want). Thanks! And welcome to the team :)

@smeijer
Copy link
Member Author

smeijer commented Jun 8, 2020

Thank you so much @kentcdodds! I'll make sure to read the docs. 😇

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

Successfully merging this pull request may close these issues.

None yet

3 participants