-
-
Notifications
You must be signed in to change notification settings - Fork 389
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
prettify linked tests : Fixes #1374 #1487
prettify linked tests : Fixes #1374 #1487
Conversation
@marcoscaceres I have pushed in some new changes. Please review. |
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 changes... I'm unsure about your usage of hyperHTML there also, but we can look at that after this round of fixes.
src/core/data-tests.js
Outdated
<a href="${href}"> | ||
${href.split("/").pop()} | ||
${modifiedHref.split('-').join(' ')} |
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.
Upon reflection, I think I'd like us to keep the "-".
src/core/data-tests.js
Outdated
@@ -23,11 +23,34 @@ export const name = "core/data-tests"; | |||
const lang = defaultLang in l10n ? defaultLang : "en"; | |||
|
|||
function toListItem(href) { | |||
return hyperHTML.bind(document.createElement("li"))` | |||
|
|||
let modifiedHref = href.split("/").pop().split(".html")[0]; |
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.
nit:
const [modifiedHref] = href.split("/").pop().split(".html");
Also, might be worth checking if the tests always end with ".html"... Some might end with just ".htm", but double check in the web platform test repository.
src/core/data-tests.js
Outdated
|
||
let emojiList = document.createElement('i'); | ||
|
||
let requiresConnectionEmoji = hyperHTML.bind(document.createElement("i"))` 🔒 `; |
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.
Any reason you chose i
element in particular? I would figure maybe a span
might be better here?
src/core/data-tests.js
Outdated
let emojiList = document.createElement('i'); | ||
|
||
let requiresConnectionEmoji = hyperHTML.bind(document.createElement("i"))` 🔒 `; | ||
requiresConnectionEmoji.setAttribute('aria-label','require-secure-connection'); |
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.
Note that aria-label is read out by a screen reader, so we want to make this as friendly as possible. I would suggest instead: "requires a secure connection".
We have quite a few users with visual impairments, so we do our best to support their needs.
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 really appreciate that 👏
src/core/data-tests.js
Outdated
let requiresConnectionEmoji = hyperHTML.bind(document.createElement("i"))` 🔒 `; | ||
requiresConnectionEmoji.setAttribute('aria-label','require-secure-connection'); | ||
|
||
let manualPerformEmoji = hyperHTML.bind(document.createElement("i"))` 💪 `; |
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.
As above, and aria label "the test must be run manually"
src/core/data-tests.js
Outdated
|
||
let emojiList = document.createElement('i'); | ||
|
||
let requiresConnectionEmoji = hyperHTML.bind(document.createElement("i"))` 🔒 `; |
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.
These elements should only be created inside the if statements below. Otherwise, they are getting created unnecessarily if not needed (and then thrown away).
src/core/data-tests.js
Outdated
|
||
let modifiedHref = href.split("/").pop().split(".html")[0]; | ||
|
||
let emojiList = document.createElement('i'); |
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.
Nit: all the let
should be const
, as we are not reassigning them.
Just a general note that in the project we are using double quotes 😉 To pretty up the code, I've been using (prettier.js)[https://github.com/prettier/prettier] via Visual Studio Code... but also works in the command line. |
@shikhar-scs, if you are unsure about any JS syntax stuff (e.g., when should I use |
Thank you for the review . I'll post the corrected changes soon👍 |
Thanks for continuing to hack in this. I’m just on my way home, so will take a look first thing tomorrow. |
Thankyou for your suggestions and though I do l know the differences between I've pushed some new changes. And as of now, please ignore the changes made to
No problem |
72a519e
to
67a9747
Compare
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.
The logic is mostly there, but a bit of refactoring needed here to keep this code easy to work with.
We can also do some optimizations, but trying to do the least amount of work possible.
examples/basic.html
Outdated
@@ -3,8 +3,8 @@ | |||
<head> | |||
<meta charset='utf-8'> | |||
<title>Replace me with a real title</title> | |||
<script src='../js/deps/require.js' data-main='../js/profile-w3c-common' | |||
async class='remove'></script> | |||
<script src='../js/deps/require.js' data-main='../js/profile-w3c-common' |
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.
Please revert changes to this file.
src/core/data-tests.js
Outdated
|
||
// const modifiedHref = href.split("/").pop().split(".")[0]; | ||
|
||
if ( href.split("/").pop().split(".").includes("html") || href.split("/").pop().split(".").includes("htm") ) { |
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.
Nit: make this two steps, and combine the search (otherwise, you are doing things twice):
// the last item will be the filename
const [testFile] = new URL(href).pathname.split("/").reverse();
// next we want to work out the type
const testParts = testFile.split(".");
const [testFile] = testParts; // the first item
const isSecureTest = testParts.find(part => part === "https");
// this is probably incorrect, but find "manual" like this:
const isManualTest = testFile.split("-").find(part => part === "manual");
// then
if(isSecure){
// add secure emoji...
}
if(isManualTest) {
// add manual emoji
}
src/core/data-tests.js
Outdated
@@ -24,34 +24,37 @@ const lang = defaultLang in l10n ? defaultLang : "en"; | |||
|
|||
function toListItem(href) { | |||
|
|||
// const modifiedHref = href.split("/").pop().split(".")[0]; | |||
var [testFile] = new URL(href).pathname.split("/").reverse(); |
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.
nit: rename this to something else, don't reassign it below (otherwise it's confusing to know what this actually is)
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.
Getting there 👍
src/core/data-tests.js
Outdated
@@ -23,11 +23,42 @@ export const name = "core/data-tests"; | |||
const lang = defaultLang in l10n ? defaultLang : "en"; | |||
|
|||
function toListItem(href) { | |||
return hyperHTML.bind(document.createElement("li"))` | |||
|
|||
var [testFile] = new URL(href).pathname.split("/").reverse(); |
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.
ok, call this something else and don't reassign it... otherwise, its confusing to know what this actually is.
src/core/data-tests.js
Outdated
const requiresConnectionEmoji = hyperHTML.bind(document.createElement("span"))` 🔒 `; | ||
requiresConnectionEmoji.setAttribute("aria-label","requires a secure connection"); | ||
|
||
console.log(testFile) |
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.
nit: remove console.log
src/core/data-tests.js
Outdated
requiresConnectionEmoji.setAttribute("aria-label","requires a secure connection"); | ||
|
||
console.log(testFile) | ||
testFile.split(".https").join(""); |
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.
this line doesn't do anything :)
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.
It does. It removes the .https parts from the end
cea10e8
to
24a229c
Compare
Please review now @marcoscaceres . I've also squashed all my commits |
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.
Fixed up style and a few small bugs. Make sure you git pull the changes.
src/core/data-tests.js
Outdated
const isSecureTest = testParts.find(part => part === "https"); | ||
const isManualTest = testFileName.split(".").join("-").split("-").find(part => part === "manual"); | ||
|
||
let emojiList = document.createElement("span"); |
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.
nit: this should be a const
, as it's not being reassigned, right?
src/core/data-tests.js
Outdated
|
||
const isSecureTest = testParts.find(part => part === "https"); | ||
if (isSecureTest) { | ||
const requiresConnectionEmoji = hyperHTML.bind( |
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.
It seems unnecessary to use hyperHTML here, and same in the isManualTest
block below. Just create spans here, and don't bind them.
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.
ok thanx for that 👍
src/core/data-tests.js
Outdated
.split("-") | ||
.find(part => part === "manual"); | ||
if (isManualTest) { | ||
const manualPerformEmoji = hyperHTML.bind( |
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.
As above.
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.
sure 👍
src/core/data-tests.js
Outdated
</a> | ||
`; | ||
testList.append(emojiList); |
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.
Here, I think testList should "render" like this:
<a href="${href}">
${testFileName}
</a> ${emojiList}
src/core/data-tests.js
Outdated
@@ -23,11 +23,50 @@ export const name = "core/data-tests"; | |||
const lang = defaultLang in l10n ? defaultLang : "en"; | |||
|
|||
function toListItem(href) { | |||
return hyperHTML.bind(document.createElement("li"))` | |||
const emojiList = document.createElement("span"); |
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.
Note, this should be an array really... otherwise, this could end up with either and empty span or with a nested set of spans:
<a href="...">name-of-test</a>
<!-- nested span are not great -->
<span>
<span>💪</span>
</span>
We want to end up with markup like this:
<li>
<a href="...">name-of-test</a> <span>💪</span> <span>🔒</span>
</li>
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.
This is still remaining to be fixed, right? (i.e., const emojiList = [];
, instead of using a span)
src/core/data-tests.js
Outdated
if (isManualTest) { | ||
const manualPerformEmoji = hyperHTML.bind( | ||
document.createElement("span") | ||
)` 💪 `; |
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.
nit: we probably don't need the whitespace. We should add that between the spans. If we then want them to have more padding, we should add that using CSS.
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.
ok I'll keep all of that in mind 👍
src/core/data-tests.js
Outdated
)` 💪 `; | ||
manualPerformEmoji.setAttribute( | ||
const manualPerformEmoji = document.createElement("span") | ||
manualPerformEmoji.innerHTML = `💪`; |
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.
Nit: note that the indentation will get reset by prettier.js
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.
oh completely forgot about that. Apart from that any more changes you would like to see ?
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.
Lastly, we would need to add tests to tests/spec/core/data-tests-spec.js, that check all the new changes we've made.
So, pretty close to being done here! Thanks for hanging in there!
@Marcos I've written the tests related to my code and pushed them here. Please review 😅 |
@shikhar-scs, just stepping out, but promise to review first thing tomorrow! Thanks for putting in the work. |
@marcoscaceres Not an issue at all. I'll wait for tomorrow 👍 |
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.
Just a couple of small things. Nearly there however!
src/core/data-tests.js
Outdated
@@ -23,11 +23,50 @@ export const name = "core/data-tests"; | |||
const lang = defaultLang in l10n ? defaultLang : "en"; | |||
|
|||
function toListItem(href) { | |||
return hyperHTML.bind(document.createElement("li"))` | |||
const emojiList = document.createElement("span"); |
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.
This is still remaining to be fixed, right? (i.e., const emojiList = [];
, instead of using a span)
tests/spec/core/data-tests-spec.js
Outdated
@@ -17,6 +17,11 @@ describe("Core — data-tests attribute", () => { | |||
<a id="t1" data-cite="#test">a</a> | |||
<dfn id="t2" data-cite="#test">a</dfn> | |||
</p> | |||
<p id="metadata-tests" | |||
data-tests="this-is-secure.https.html, | |||
this-is-manual.html, this-is-secure-and-manual.https.html"> |
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.
Nit: put "this-is-secure-and-manual.https.html" on a new line, so it's visually distinct from the other two. Basically, we want:
data-tests="
this-is-secure.https.html,
this-is-manual.html,
this-is-secure-and-manual.https.html"
tests/spec/core/data-tests-spec.js
Outdated
@@ -63,5 +68,33 @@ describe("Core — data-tests attribute", () => { | |||
expect(pathname.endsWith(`test${i}.html`)).toBe(true); | |||
}); | |||
}); | |||
it(`adds emojis for manual and https related tests`, () => { | |||
|
|||
let test = doc.querySelector("#metadata-tests ul").querySelectorAll("li") |
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.
As you have the tests here, we should split the tests into three separate it()
statements:
it("adds emojis for secure tests", () => {
const li = doc.querySelector("#metadata-tests ul>li:nth-child(1)");
// other stuff
});
it("adds emojis for manual tests", () => {
const li = doc.querySelector("#metadata-tests ul>li:nth-child(2)");
// other stuff
});
it("adds emojis for secure manual tests", () => {
const li = doc.querySelector("#metadata-tests ul>li:nth-child(3)");
// other stuff
});
tests/spec/core/data-tests-spec.js
Outdated
let test = doc.querySelector("#metadata-tests ul").querySelectorAll("li") | ||
|
||
// for test 1 | ||
expect(test[0].children[0].innerText.trim()).toEqual("this-is-secure"); // filename |
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.
might be better here:
const filename = li.innerText.trim();
expect(filename).toEqual("this-is-secure");
Then it's much more clear exactly what you are testing, same applies to the ones below. Basically, if you find that you have to leave a comment, e.g., // filename
, that's a strong sign you should be using a variable.
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.
note also here, the fact that you are calling .trim()
seems like it might be a bug in the implementation. You shouldn't need to call trim, as the implementation should have trimmed it.
Fixed js style to match project.
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.
🕺Awesome work! I ran the code through prettier, so no to bother you with nits.
Last little question and one small change, and we should be all good to go.
tests/spec/core/data-tests-spec.js
Outdated
it(`adds emojis for secure tests`, () => { | ||
const li = doc.querySelector("#metadata-tests ul>li:nth-child(1)"); | ||
|
||
const fileName = li.children[0].innerText.trim(); |
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.
So, having to do "li.children[0]" and "li.children[1]" is not ideal here, because it's not clear what element you are working with. Can you please destructure the array into named variables, like (you can probably come up with better names):
const [fileElement, secureIconElement] = li.children;
Similarly for the ones below...
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.
typo above, I mean "is not ideal"
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.
Yeah Sure 👍
tests/spec/core/data-tests-spec.js
Outdated
); | ||
expect(spanAriaLabel2).toEqual("the test must be run manually"); | ||
|
||
const spanTitle2 = li.children[1].children[1].getAttribute("title"); |
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.
Seems odd that they are nested? I think this might be a bug. The tree structure should be:
<span>file-name</span> <span>emoji</span> <span>emoji</span>
Or am I reading this wrong?
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.
Its something like
<li><a>fileName</a><span>emoji</span><span>emoji</span></li>
So, yeah roughly the same
@marcoscaceres I've refactored the code, removing all Please review the code now. |
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.
Perfect! Looking forward to trying this out!
Ready for merge ?? |
yep, was just waiting for green light from TravisCI. |
* develop: v19.6.0 feat: add icons to describe tests (#1487) nit(headers-spec): use %20 instead of space
respec@19.6.0 going live now. Great work @shikhar-scs! |
Looking hella nice in a real spec (make sure you shift-refresh) https://w3c.github.io/payment-request/ 😻 |
Thanks a lot @marcoscaceres . My first contribution to respec 🎉🎉🎉 |
As suggested by @marcoscaceres , the required changes mentioned at #1374 have been made. Here's a preview
Please preview