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

Added option to filter tests #212

Merged
merged 8 commits into from
Jan 13, 2022
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 69 additions & 53 deletions csstest.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,73 @@ function passclass(info) {
return classes[index];
}

function resetOutput() {
mainScore = new Score();

// Output current score
ele('score').textContent = '';
ele('passedTests').textContent = '';
ele('totalTests').textContent = '';
ele('total').textContent = '';
ele('specsTested').textContent = '';
ele('all').textContent = '';

// Display time taken
ele('timeTaken').textContent = '';
}

function runTests(filter = '') {
let specs = [];
Copy link
Collaborator

Choose a reason for hiding this comment

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

I see you replaced some var keywords by let.
Do we want to embrace ES6-style javascript now? or still being somehow compatible with old browsers?

Copy link
Collaborator

Choose a reason for hiding this comment

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

IE isn't really dead yet. For me, it would be necessary to wait until it's definitely dead (removal of Windows). I let you decide.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

According to caniuse.com, IE has (partial) support for let. The biggest percentage of a non-supporting browser is Opera Mini with ~1%. And the overall support is at ~95%, which seems pretty stable to me.

Personally, I prefer to use ES6+ features as long as there is good browser support for them. If you two believe we should strive for full backwards compatibility, I could change it back to var.
Though I have to admit, I never tried to call the site in a very old browser so far. I assume there are other pieces of code that might be unsupported in older browsers.

Having said that, I am also planning to push #57 forward which requires a good browser coverage. So maybe that requires the JS part to be backwards compatible.

Sebastian

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

For me, it would be necessary to wait until it's definitely dead (removal of Windows).

For what it's worth, IE is removed in Windows 11 and finally will be gone in June this year, though it will surely still take many years until nobody uses IE anymore.
According to statcounter IE still has a market share of 0.46%.

Sebastian

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Because there's a mixture of var and let after that patch, I decided to roll back to var again for now.

I'll file a follow-up issue on refactoring the code base, instead.

Sebastian

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've filed #216 now to discuss whether and which ES6+ features we want to use. Feel free to comment there!

Sebastian

Copy link
Collaborator

Choose a reason for hiding this comment

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

Could this line also be reverted to var?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done. Thank's for the hint!

let timeBefore = +new Date;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Also this one?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.


var removedWords = / *(?:\([^)]*\)|:.*|\b(?:CSS|Module)\b)( *)/g;

for (var spec in Specs) {
// Filter list of specifications
if (filter === 'stable' && Specs[spec].status && Specs[spec].status.stability !== 'stable') {
continue;
} else if (filter === 'experimental' && Specs[spec].status && Specs[spec].status.stability === 'stable') {
continue;
} else if (Number(filter) > 0) {
if (!Specs[spec].status || Specs[spec].status['first-snapshot'] === undefined) {
continue;
}

const snapshot = Number(filter);
if (
Specs[spec].status['first-snapshot'] > snapshot ||
(Specs[spec].status && Specs[spec].status['last-snapshot'] < snapshot)
) {
continue;
}
}

specs.push({
id: spec,
// Shorten the title by removing parentheticals,
// subheadings, CSS and Module words
title: Specs[spec].title.replace(removedWords, "$1").trim(),
tests: Specs[spec]
});
}

specs.sort(function (a, b) {
return a.title.localeCompare(b.title);
});

// Run tests
specs.forEach(spec => new Test(spec));

// Output score
ele('score').textContent = mainScore + '';
ele('passedTests').textContent = ~~mainScore.passedTests;
ele('totalTests').textContent = mainScore.totalTests;
ele('total').textContent = mainScore.total;

// Display time taken
ele('timeTaken').textContent = +new Date - timeBefore + 'ms';
}

Array.prototype.and = function (arr2, separator) {
separator = separator || ' ';

Expand Down Expand Up @@ -440,57 +507,6 @@ Array.prototype.times = function (min, max, separator) {
};

onload = function () {
var timeBefore = +new Date,
duration = 0,
specs = [];

var removedWords = / *(?:\([^)]*\)|:.*|\b(?:CSS|Module)\b)( *)/g;

for (var spec in Specs) {
specs.push({
id: spec,
// Shorten the title by removing parentheticals,
// subheadings, CSS and Module words
title: Specs[spec].title.replace(removedWords, "$1").trim(),
tests: Specs[spec]
});
}

specs.sort(function (a, b) {
return a.title.localeCompare(b.title);
});


(function () {
if (specs.length) {
// Get spec id
var spec = specs.shift();

// Run tests
var test = new Test(spec);

// Count test duration
duration += +new Date - timeBefore;
timeBefore = +new Date;

// Output current score
ele('score').textContent = mainScore + '';
ele('passedTests').textContent = ~~mainScore.passedTests;
ele('totalTests').textContent = mainScore.totalTests;
ele('total').textContent = mainScore.total;

// Schedule next test
setTimeout(arguments.callee, 50)
}
else {
// Done!

// Display time taken
ele('timeTaken').textContent = +new Date - timeBefore + 'ms';
}
})();




ele('filter').value = localStorage.getItem('filter') || '';
runTests(localStorage.getItem('filter') || '');
}
7 changes: 7 additions & 0 deletions filter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(function() {
ele('filter').addEventListener('change', evt => {
PolariTOON marked this conversation as resolved.
Show resolved Hide resolved
localStorage.setItem('filter', evt.target.value);
resetOutput();
runTests(evt.target.value);
});
})();
21 changes: 21 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,26 @@ <h2>Determined by passing <strong id="passedTests"></strong> tests out of <stron
<script async type="text/javascript" src="//cdn.carbonads.com/carbon.js?zoneid=1673&serve=C6AILKT&placement=css3testcom" id="_carbonads_js"></script>
</section>

<section>
<h1>Filter:</h1>
<form>
<select id="filter">
<option value="" title="All specifications including experimental ones">All</option>
<option value="stable" title="All specifications listed in the latest CSS snapshot, their predecessors and others that won't change much anymore">Stable</option>
<option value="experimental" title="All specifications not listed in the latest CSS snapshot">Experimental</option>
<optgroup label="CSS snapshots">
<option value="2007" title="All specifications marked as official part of the CSS 2007 snapshot">CSS 2007</option>
<option value="2010" title="All specifications marked as official part of the CSS 2010 snapshot">CSS 2010</option>
<option value="2015" title="All specifications marked as official part of the CSS 2015 snapshot">CSS 2015</option>
<option value="2017" title="All specifications marked as official part of the CSS 2017 snapshot">CSS 2017</option>
<option value="2018" title="All specifications marked as official part of the CSS 2018 snapshot">CSS 2018</option>
<option value="2020" title="All specifications marked as official part of the CSS 2020 snapshot">CSS 2020</option>
<option value="2021" title="All specifications marked as official part of the CSS 2021 snapshot">CSS 2021</option>
</optgroup>
</select>
</form>
</section>

<section>
<h1>Specs tested:</h1>
<ul id="specsTested"></ul>
Expand Down Expand Up @@ -62,6 +82,7 @@ <h1>Cheaters</h1>
<script src="supports.js"></script>
<script src="csstest.js"></script>
<script src="tests.js"></script>
<script src="filter.js"></script>

</body>
</html>
Loading