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 all 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 = '') {
var specs = [];
var timeBefore = +new Date;

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