philipwalton / easy-sauce

Easily run JavaScript unit tests on the Sauce Labs cloud.
ISC License
74 stars 9 forks source link

Use flexible syntax to specify browsers #10

Open lpinca opened 7 years ago

lpinca commented 7 years ago

Would you be interested in adding a more flexible syntax to specify the platforms/browsers/versions? For example:

{
  "platforms": [
    {
      "name": "internet explorer",
      "version": "oldest..latest"
    },
    {
      "name": "chrome",
      "version": ["oldest", "latest"]
    }
  ]
}

What I'm thinking is the same syntax used in zuul. The advantage is that you don't have to update the config if a new version of a browser is added in SauceLabs. The same applies for removed versions.

Converting this syntax to the required format is easy (the code can be extracted from zuul) and can be done in a separate npm module.

The only problem I see is that it isn't backward compatible.

Thoughts?

philipwalton commented 7 years ago

Sure, that would be cool. Out of curiosity, why do you say it wouldn't be backwards compatible? Presumably if it didn't find a .., it would just assume a single version, no?

Also, I assume this technique would need to query the Sauce Labs API to see what versions/platforms are available. Is that what zuul does?

lpinca commented 7 years ago

Well currently you have an array of arrays. The new config will be an array of objects. Maybe we can check if the first element is an array and determine how to handle the config based on this info.

Yes zuul get all browsers from https://saucelabs.com/rest/v1/info/browsers/webdriver, see https://github.com/defunctzombie/zuul/blob/8f8adf0ae0c4ebf196a65b92173dfcacd0c7a64b/lib/scout_browser.js.

lpinca commented 7 years ago

I published sauce-browsers. It works like this:

const browsers = [
  { name: 'firefox', version: 50, platform: 'Mac 10.9'},
  { name: 'chrome', version: ['oldest', 'latest'] },
  { name: 'safari', version: 'oldest..latest' }
];

sauceBrowsers(browsers).then((platforms) => {
  platforms = browsers.map((el) => [el.os, el.api_name, el.short_version]);
  // `platforms` can now be used in `easy-sauce`.
}).catch((err) => console.error(err.stack));
rtsao commented 7 years ago

Support for https://github.com/ai/browserslist would be great. Tools such as https://github.com/babel/babel-preset-env use it.

lpinca commented 7 years ago

@rtsao yeah I thought that but afaik there is no way to specify the OS in browserlist and it doesn't query Sauce Labs to actually know what browsers are available.