browser_capabilities.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Copyright 2018 The Closure Library Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS-IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. var sauceBrowsers = require('./sauce_browsers.json');
  15. /**
  16. * Returns a versioned name for the given capability object.
  17. * @param {!Object} browserCap
  18. * @return {string}
  19. */
  20. function getBrowserName(browserCap) {
  21. var name = browserCap.browserName == 'internet explorer' ?
  22. 'ie' :
  23. browserCap.browserName;
  24. var version = browserCap.version || '-latest';
  25. return name + version;
  26. }
  27. /**
  28. * Returns the travis job name for the given capability object.
  29. * @param {!Object} browserCap
  30. * @return {string}
  31. */
  32. function getJobName(browserCap) {
  33. var browserName = getBrowserName(browserCap);
  34. return process.env.TRAVIS_PULL_REQUEST == 'false' ?
  35. 'CO-' + process.env.TRAVIS_BRANCH + '-' + browserName :
  36. 'PR-' + process.env.TRAVIS_PULL_REQUEST + '-' + browserName + '-' +
  37. process.env.TRAVIS_BRANCH;
  38. }
  39. /**
  40. * Adds 'name', 'build', and 'tunnel-identifier' properties to all elements,
  41. * based on runtime information from the environment.
  42. * @param {!Array<!Object>} browsers
  43. * @return {!Array<!Object>} The original array, whose objects are augmented.
  44. */
  45. function getBrowserCapabilities(browsers) {
  46. for (var i = 0; i < browsers.length; i++) {
  47. var b = browsers[i];
  48. b['tunnel-identifier'] = process.env.TRAVIS_JOB_NUMBER;
  49. b['build'] = process.env.TRAVIS_BUILD_NUMBER;
  50. b['name'] = getJobName(b);
  51. }
  52. return browsers;
  53. }
  54. module.exports = getBrowserCapabilities(sauceBrowsers);