Skip to content
This repository has been archived by the owner on Sep 26, 2023. It is now read-only.

Commit

Permalink
Stop using CSS.supports for CSS property tests
Browse files Browse the repository at this point in the history
Instead generate both forms for the document.body.style tests where
appropriate, to deal with odd -apple- and -epub-prefixed properties.

Fixes #12.
  • Loading branch information
foolip committed Apr 29, 2021
1 parent 6076d30 commit ed9565f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 22 deletions.
24 changes: 14 additions & 10 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,6 @@ const compileTestCode = (test) => {
if (test.property.startsWith('constructor')) {
return `bcd.testConstructor("${property}");`;
}
if (test.owner === 'CSS.supports') {
return `CSS.supports("${test.property}", "inherit")`;
}
if (test.property.startsWith('Symbol.')) {
return `"Symbol" in self && "${test.property.replace('Symbol.', '')}" in Symbol && ${test.property} in ${test.owner}.prototype`;
}
Expand Down Expand Up @@ -608,15 +605,22 @@ const buildCSS = (webrefCSS, customCSS) => {
const tests = {};

for (const name of Array.from(propertySet).sort()) {
const customTest = getCustomTestCSS(name);
if (customTest) {
tests[`css.properties.${name}`] = compileTest({
raw: {code: customTest},
exposure: ['Window']
});
continue;
}

const attrName = cssPropertyToIDLAttribute(name, name.startsWith('-'));
const code = [{property: attrName, owner: 'document.body.style'}];
if (name !== attrName) {
code.push({property: name, owner: 'document.body.style'});
}
tests[`css.properties.${name}`] = compileTest({
raw: {
code: getCustomTestCSS(name) || [
{property: attrName, owner: 'document.body.style'},
{property: name, owner: 'CSS.supports'}
],
combinator: '||'
},
raw: {code, combinator: '||'},
exposure: ['Window']
});
}
Expand Down
17 changes: 6 additions & 11 deletions unittest/unit/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -438,11 +438,6 @@ describe('build', () => {
assert.equal(compileTestCode(test), 'bcd.testConstructor("AudioContext");');
});

it('CSS.supports', () => {
const test = {property: 'font-weight', owner: 'CSS.supports'};
assert.equal(compileTestCode(test), 'CSS.supports("font-weight", "inherit")');
});

it('Symbol', () => {
const test = {property: 'Symbol.iterator', owner: 'DOMMatrixReadOnly'};
assert.equal(compileTestCode(test), '"Symbol" in self && "iterator" in Symbol && Symbol.iterator in DOMMatrixReadOnly.prototype');
Expand Down Expand Up @@ -561,7 +556,7 @@ describe('build', () => {
raw: {
code: [
{property: 'fontFamily', owner: 'document.body.style'},
{property: 'font-family', owner: 'CSS.supports'}
{property: 'font-family', owner: 'document.body.style'}
],
combinator: '||'
},
Expand All @@ -570,7 +565,7 @@ describe('build', () => {
};

assert.deepEqual(compileTest(rawTest), {
code: '"fontFamily" in document.body.style || CSS.supports("font-family", "inherit")',
code: '"fontFamily" in document.body.style || "font-family" in document.body.style',
exposure: ['Window']
});
});
Expand Down Expand Up @@ -1313,19 +1308,19 @@ describe('build', () => {

assert.deepEqual(buildCSS(webrefCSS, customCSS), {
'css.properties.font-family': {
code: '"fontFamily" in document.body.style || CSS.supports("font-family", "inherit")',
code: '"fontFamily" in document.body.style || "font-family" in document.body.style',
exposure: ['Window']
},
'css.properties.font-weight': {
code: '"fontWeight" in document.body.style || CSS.supports("font-weight", "inherit")',
code: '"fontWeight" in document.body.style || "font-weight" in document.body.style',
exposure: ['Window']
},
'css.properties.grid': {
code: '"grid" in document.body.style || CSS.supports("grid", "inherit")',
code: '"grid" in document.body.style',
exposure: ['Window']
},
'css.properties.zoom': {
code: '"zoom" in document.body.style || CSS.supports("zoom", "inherit")',
code: '"zoom" in document.body.style',
exposure: ['Window']
}
});
Expand Down
2 changes: 1 addition & 1 deletion unittest/unit/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const testDatabase = {
exposure: ['Window', 'Worker']
},
'css.properties.font-family': {
code: '"fontFamily" in document.body.style || CSS.supports("font-family", "inherit")',
code: '"fontFamily" in document.body.style || "font-family" in document.body.style',
exposure: ['Window']
},
'javascript.builtins.array': {
Expand Down

0 comments on commit ed9565f

Please sign in to comment.