-
Notifications
You must be signed in to change notification settings - Fork 470
Make screen.logTestingPlaygroundURL() work with document.head #824
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
Comments
A problem I can see with this is we have a hard limit on the amount of stuff we can include in that URL (URLs have a limited length). So if we include the Perhaps we could do: |
Wondering if using something like this https://pieroxy.net/blog/pages/lz-string/index.html would make it a bit shorter? |
I'm writing some tests for a project I'm working on that mounts essentially the whole app, which results in the body alone being quite heavy, This from the Chromium docs seems to suggest that if there is a limit, it's pretty huge, at least for modern browsers:
There does seem to be some advice out there on the internet that advises you stick to URLs / GET requests of 2,048 characters or shorter. I'm wondering if this is informed by limitations of specific browsers, or maybe even SEO concerns? If so, we should be able to ignore this.
Looks like that's already being used: dom-testing-library/src/screen.js Line 1 in f627ade
|
Interesting, I didn't see that it could already accept an element. Maybe the issue in this repo isn't neccessary, and only changes in testing-playground are needed. Maybe it could attempt to detect if head and body are present in the decoded markup, and handle things differently if so. |
cc @smeijer |
We indeed already use Regarding that length, if the issue is indeed a legacy thing, then we could ignore it. As most developers use the latest version of Chrome and/or Firefox anyway. I don't ignore it for testing-playground itself. But the devs that use dom-testing-library to print the playground url, are a different audience. So I don't foresee issues there if it's really a legacy thing. We would need to confirm and decide if we want to ignore legacy browsers (sounds acceptable to me). About including the styling, this doesn't require any changes in Testing-Playground itself. The This same thing would be possible for included Back to the URL length, an alternative option is to use a POST request and submit the markup to the server in return for a shorter url. This has some benefits (shorter url, no max url length problems), but you'd need to realize that it means that your code is stored on a server. We could also make that optional instead. (Data is saved as github gist). screen.createPlayground(); An example request to make such an url: await fetch('https://testing-playground.com/api/gist', {
method: 'POST',
headers: {
'content-type': 'application/json',
},
body: JSON.stringify({
files: {
'playground.json': { content: JSON.stringify({}, null, 2) },
'source.html': { content: '<!-- markup here -->' },
'source.js': { content: '// query here' },
},
}),
}); All three files are required, even if they're empty. That's simply because this api is currently only internally used. I can make them optional if it's an issue. The request above returns: {
"id": "8e1abf322151eae15e67fb5567f651f4",
"version": "b417598b466be9f77cbb992b3d690ab151f43cd7",
"url": "https://testing-playground.com/gist/8e1abf322151eae15e67fb5567f651f4/b417598b466be9f77cbb992b3d690ab151f43cd7"
} So that playground is available under: https://testing-playground.com/gist/8e1abf322151eae15e67fb5567f651f4/b417598b466be9f77cbb992b3d690ab151f43cd7 And that's the URL that should then be logged to the terminal, and/or automatically opened. In other words, there is currently no reason why testing-playground.com wouldn't be able to render styles. That being said, I have my concerns about automatically extracting styles.
|
this is working for me. |
Uh oh!
There was an error while loading. Please reload this page.
Describe the feature you'd like:
Following on from #780, I think it would be helpful if
screen.logTestingPlaygroundURL()
created a URL that also contains the markup from the document head. This would allow a better debugging experience for CSS-in-JSS solutions, but I imagine it would also improve the behaviour for any styling that isn't defined inline.Suggested implementation:
Looks like https://testing-playground.com itself would need to change, maybe accepting a hash along the lines of
#body-markup=<encoded-body-markup>&head-markup=<encoded-head-markup>
. I'll have a look through the code there and possibly open an issue in that repo too.I've spent a little time exploring if this approach would be possible, using with the code below:
This outputs this url - which unfortunately does not have the beautiful colours I have defined. However, if I set a breakpoint on the line
screen.logTestingPlaygroundURL();
and runwindow.document.head.innerHTML
I get the output'<style data-styled="active" data-styled-version="5.2.1">.fUmfxz{background:#f0f;color:#0f0;}</style>'
. So I am assuming it would be a matter of amendinggetPlaygroundUrl
to output both the markup for the body and the head.Describe alternatives you've considered:
I haven't considered any alternatives.
Teachability, Documentation, Adoption, Migration Strategy:
I am assuming no teaching or documentation would be required, as the usage would remain the same.
The text was updated successfully, but these errors were encountered: