-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests(smoke): support full chrome version for pruning (#13896)
- Loading branch information
1 parent
1daf915
commit 2a8058a
Showing
14 changed files
with
127 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* @license Copyright 2022 The Lighthouse Authors. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
import {chromiumVersionCheck, compareVersions} from './version-check.js'; | ||
|
||
/* eslint-env jest */ | ||
|
||
describe('version check', () => { | ||
it('compareVersions', async () => { | ||
expect(compareVersions([100, 0, 0, 0], [100, 0, 0, 0])).toBe(0); | ||
expect(compareVersions([101, 0, 0, 0], [100, 0, 0, 0])).toBe(1); | ||
expect(compareVersions([99, 0, 0, 0], [100, 0, 0, 0])).toBe(-1); | ||
|
||
expect(compareVersions([100, 0, 10, 0], [100, 0, 10, 0])).toBe(0); | ||
expect(compareVersions([100, 0, 11, 0], [100, 0, 10, 0])).toBe(1); | ||
expect(compareVersions([100, 0, 9, 0], [100, 0, 10, 0])).toBe(-1); | ||
|
||
expect(compareVersions([100, 0, 0, 0], [100])).toBe(0); | ||
expect(compareVersions([100, 0, 0, 1], [100])).toBe(1); | ||
expect(compareVersions([99, 0, 0, 0], [100])).toBe(-1); | ||
}); | ||
|
||
it('chromiumVersionCheck', async () => { | ||
expect(chromiumVersionCheck({version: '100'})).toBe(true); | ||
expect(chromiumVersionCheck({version: '100', min: '100'})).toBe(true); | ||
expect(chromiumVersionCheck({version: '100', max: '100'})).toBe(true); | ||
expect(chromiumVersionCheck({version: '100', min: '101'})).toBe(false); | ||
expect(chromiumVersionCheck({version: '100', max: '99'})).toBe(false); | ||
|
||
expect(chromiumVersionCheck({version: '100.0.2331.3'})).toBe(true); | ||
expect(chromiumVersionCheck({version: '100.0.2331.3', min: '100.0.2331.3'})).toBe(true); | ||
expect(chromiumVersionCheck({version: '100.0.2331.3', min: '100.0.0.0'})).toBe(true); | ||
expect(chromiumVersionCheck({version: '100.0.2331.3', max: '100.0.3333.3'})).toBe(true); | ||
expect(chromiumVersionCheck({version: '100.0.2331.3', min: '100.0.2331.2'})).toBe(true); | ||
expect(chromiumVersionCheck({version: '100.0.2331.3', max: '99'})).toBe(false); | ||
|
||
expect(chromiumVersionCheck({ | ||
version: '100.0.2331.3', min: '100.0.2331.0', max: '100.0.2331.10'})).toBe(true); | ||
expect(chromiumVersionCheck({ | ||
version: '100.3.2331.3', min: '100.0.2331.0', max: '100.0.2331.10'})).toBe(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* @license Copyright 2022 The Lighthouse Authors. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
/** | ||
* @fileoverview Compares chromium version strings: 103.0.5017.0 | ||
*/ | ||
|
||
/** | ||
* @param {string} versionString | ||
* @return {number[]} | ||
*/ | ||
function parseVersion(versionString) { | ||
const versionParts = versionString.split('.'); | ||
return versionParts.map(Number); | ||
} | ||
|
||
/** | ||
* @param {number[]} versionA | ||
* @param {number[]} versionB | ||
*/ | ||
function compareVersions(versionA, versionB) { | ||
for (let i = 0; i < versionA.length; i++) { | ||
if ((versionA[i] ?? 0) > (versionB[i] ?? 0)) return 1; | ||
if ((versionA[i] ?? 0) < (versionB[i] ?? 0)) return -1; | ||
} | ||
return 0; | ||
} | ||
|
||
/** | ||
* Returns false if fails check. | ||
* @param {{version: string, min?: string, max?: string}} opts | ||
*/ | ||
function chromiumVersionCheck(opts) { | ||
const version = parseVersion(opts.version); | ||
const min = opts.min && parseVersion(opts.min); | ||
const max = opts.max && parseVersion(opts.max); | ||
if (min && compareVersions(version, min) === -1) return false; | ||
if (max && compareVersions(version, max) === 1) return false; | ||
return true; | ||
} | ||
|
||
export { | ||
chromiumVersionCheck, | ||
compareVersions, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters