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

Enforce browser order in compatibility tables [MERGE #2889 FIRST] #2890

Closed
wants to merge 1 commit into from
Closed
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
28 changes: 14 additions & 14 deletions test/sample-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@
"__compat": {
"description": "Tests for various notes",
"support": {
"webview_android": {
"version_added": "4",
"notes": [
"First note",
"Second note"
]
},
"chrome": {
"version_added": "1",
"notes": [
Expand Down Expand Up @@ -57,6 +50,13 @@
},
"samsunginternet_android": {
"version_added": "5.0"
},
"webview_android": {
"version_added": "4",
"notes": [
"First note",
"Second note"
]
}
},
"status": {
Expand All @@ -69,9 +69,6 @@
"featureWithSubfeatures": {
"__compat": {
"support": {
"webview_android": {
"version_added": "4"
},
"chrome": {
"version_added": "1",
"notes": [
Expand Down Expand Up @@ -115,6 +112,9 @@
},
"samsunginternet_android": {
"version_added": "5.0"
},
"webview_android": {
"version_added": "4"
}
},
"status": {
Expand All @@ -127,9 +127,6 @@
"__compat": {
"description": "This is a sub feature with complex support statements",
"support": {
"webview_android": {
"version_added": "4"
},
"chrome": [
{
"version_added": "35",
Expand Down Expand Up @@ -233,6 +230,9 @@
},
"samsunginternet_android": {
"version_added": "5.0"
},
"webview_android": {
"version_added": "4"
}
},
"status": {
Expand All @@ -245,4 +245,4 @@
}
}
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Please, stop breaking the last newline.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I honestly don't know why the newline keeps trying to get removed. It might be the JSON editor I'm using (which is out of date anyways). :/

22 changes: 21 additions & 1 deletion test/test-style.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,26 @@
const fs = require('fs');
const path = require('path');

function orderSupportBlock(name, val) {
if (name == 'support') {
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ WARNING! ⚠️ This will break any value named support, eg. test.support:

"test": {
  "support": {
    "property": {},
    "method": {}
  }
}

would be made invalid, whereas:

"test": {
  "other": {
    "property": {},
    "method": {}
  }
}

would remain valid.

Copy link
Contributor

@ExE-Boss ExE-Boss Oct 1, 2018

Choose a reason for hiding this comment

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

Also, wrong indentation.

/*
Return a new "support_block" object whose first-level properties
(browser names) have been ordered according to Array.prototype.sort,
and so will be stringified in that order as well. This relies on
guaranteed "own" property ordering, which is insertion order for
non-integer keys (which is our case). See:

http://2ality.com/2015/10/property-traversal-order-es6.html
http://node.green/#ES2015-misc-own-property-order
*/
return Object.keys(val).sort().reduce(function(result, key) {
result[key] = val[key];
return result;
}, {});
}
return val;
}

function jsonDiff(actual, expected) {
var actualLines = actual.split(/\n/);
var expectedLines = expected.split(/\n/);
Expand All @@ -20,7 +40,7 @@ function jsonDiff(actual, expected) {
function testStyle(filename) {
let hasErrors = false;
let actual = fs.readFileSync(filename, 'utf-8').trim();
let expected = JSON.stringify(JSON.parse(actual), null, 2);
let expected = JSON.stringify(JSON.parse(actual), orderSupportBlock, 2);

const {platform} = require("os");
if (platform() === "win32") { // prevent false positives from git.core.autocrlf on Windows
Expand Down