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

Correct support for mirroring #2280

Merged
merged 11 commits into from
Sep 20, 2022
211 changes: 211 additions & 0 deletions unittest/unit/update-bcd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -861,5 +861,216 @@ describe('BCD updater', () => {
version_added: null
});
});

describe('mirror', () => {
const chromeAndroid86UaString =
'Mozilla/5.0 (Linux; Android 10; SM-G960U) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.5112.97 Mobile Safari/537.36';
const browsers: any = {
chrome: {name: 'Chrome', releases: {85: {}, 86: {}}},
chrome_android: {
name: 'Chrome Android',
upstream: 'chrome',
releases: {86: {}}
}
};

const bcdFromSupport = (support) => ({
api: {FakeInterface: {__compat: {support}}}
});

/**
* Create a BCD data structure for an arbitrary web platform feature
* based on support data for Chrome and Chrome Android and test result
* data for Chrome Android. This utility invokes the `update` function
* and is designed to observe the behavior of the "mirror" support value.
*
* @return {BCD}
*/
const mirroringCase = ({support, downstreamResult}) => {
jugglinmike marked this conversation as resolved.
Show resolved Hide resolved
const reports: Report[] = [
{
__version: '0.3.1',
results: {
'https://mdn-bcd-collector.appspot.com/tests/': [
{
name: 'api.FakeInterface',
exposure: 'Window',
result: downstreamResult
}
]
},
userAgent: chromeAndroid86UaString
}
];
const supportMatrix = getSupportMatrix(reports, browsers, []);
const bcd = bcdFromSupport(support);
update(bcd, supportMatrix, {});
return bcd;
};

describe('supported upstream (without flags)', () => {
it('supported in downstream test results', () => {
const actual = mirroringCase({
support: {
chrome: {version_added: '85'},
chrome_android: 'mirror'
},
downstreamResult: true
});
assert.deepEqual(
actual,
bcdFromSupport({
chrome: {version_added: '85'},
chrome_android: 'mirror'
})
);
});

it('unsupported in downstream test results', () => {
const actual = mirroringCase({
support: {
chrome: {version_added: '85'},
chrome_android: 'mirror'
},
downstreamResult: false
});
assert.deepEqual(
actual,
bcdFromSupport({
chrome: {version_added: '85'},
chrome_android: false
jugglinmike marked this conversation as resolved.
Show resolved Hide resolved
})
);
});

it('omitted from downstream test results', () => {
const actual = mirroringCase({
support: {
chrome: {version_added: '85'},
chrome_android: 'mirror'
},
downstreamResult: null
});
assert.deepEqual(
actual,
bcdFromSupport({
chrome: {version_added: '85'},
chrome_android: 'mirror'
jugglinmike marked this conversation as resolved.
Show resolved Hide resolved
})
);
});
});

describe('supported upstream (with flags)', () => {
it('supported in downstream test results', () => {
const actual = mirroringCase({
support: {
chrome: {version_added: '85', flags: [{}]},
chrome_android: 'mirror'
},
downstreamResult: true
});
assert.deepEqual(
actual,
bcdFromSupport({
chrome: {version_added: '85', flags: [{}]},
chrome_android: [
// TODO: Remove flag data when adding enabled-by-default data.
// See https://github.com/mdn/browser-compat-data/pull/16637.
{version_added: '86'},
{flags: [{}], version_added: '85'}
jugglinmike marked this conversation as resolved.
Show resolved Hide resolved
]
})
);
});

it('unsupported in downstream test results', () => {
const actual = mirroringCase({
support: {
chrome: {version_added: '85', flags: [{}]},
chrome_android: 'mirror'
},
downstreamResult: false
});
assert.deepEqual(
actual,
bcdFromSupport({
chrome: {version_added: '85', flags: [{}]},
chrome_android: false
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also here: a "support statement" is either "mirror" or a "simple support statement", and a "simple support statement" must be an Object value. So this expected value ought to be expressed with chrome_android: {version_added: false}.

})
);
});

it('omitted from downstream test results', () => {
const actual = mirroringCase({
support: {
chrome: {version_added: '85', flags: [{}]},
chrome_android: 'mirror'
},
downstreamResult: null
});
assert.deepEqual(
actual,
bcdFromSupport({
chrome: {version_added: '85', flags: [{}]},
chrome_android: 'mirror'
})
);
});
});

describe('unsupported upstream', () => {
it('supported in downstream test results', () => {
const actual = mirroringCase({
support: {
chrome: {version_added: false},
chrome_android: 'mirror'
},
downstreamResult: true
});
assert.deepEqual(
actual,
bcdFromSupport({
chrome: {version_added: false},
chrome_android: {version_added: '≤86'}
})
);
});

it('unsupported in downstream test results', () => {
const actual = mirroringCase({
support: {
chrome: {version_added: false},
chrome_android: 'mirror'
},
downstreamResult: false
});
assert.deepEqual(
actual,
bcdFromSupport({
chrome: {version_added: false},
chrome_android: 'mirror'
})
);
});

it('omitted from downstream test results', () => {
const actual = mirroringCase({
support: {
chrome: {version_added: false},
chrome_android: 'mirror'
},
downstreamResult: null
});
assert.deepEqual(
actual,
bcdFromSupport({
chrome: {version_added: false},
chrome_android: 'mirror'
})
);
});
});
});
});
});