|
| 1 | +const {playwrightLauncher} = require('@web/test-runner-playwright'); |
| 2 | +const {createSauceLabsLauncher} = require('@web/test-runner-saucelabs'); |
| 3 | +const {compileJSPlugin} = require('./compile-js-plugin.js'); |
| 4 | + |
| 5 | +const generateLocalBrowserLaunchers = () => { |
| 6 | + const defaultBrowsers = [ |
| 7 | + playwrightLauncher({product: 'chromium'}), |
| 8 | + playwrightLauncher({product: 'webkit'}), |
| 9 | + playwrightLauncher({product: 'firefox', concurrency: 1}), |
| 10 | + ]; |
| 11 | + |
| 12 | + const envBrowsers = process.env.BROWSERS?.split(',').map((product) => |
| 13 | + playwrightLauncher({product}) |
| 14 | + ); |
| 15 | + |
| 16 | + return envBrowsers ?? defaultBrowsers; |
| 17 | +}; |
| 18 | + |
| 19 | +const generateSauceBrowserLaunchers = () => { |
| 20 | + const sauceLabsLauncher = createSauceLabsLauncher( |
| 21 | + { |
| 22 | + user: process.env.SAUCE_USERNAME, |
| 23 | + key: process.env.SAUCE_ACCESS_KEY, |
| 24 | + }, |
| 25 | + { |
| 26 | + name: 'Polyfills tests', |
| 27 | + build: process.env.GITHUB_REF ?? 'local', |
| 28 | + } |
| 29 | + ); |
| 30 | + |
| 31 | + const defaultBrowsers = [ |
| 32 | + // These browsers support the standard W3C WebDriver protocol. |
| 33 | + |
| 34 | + sauceLabsLauncher({ |
| 35 | + platformName: 'windows 10', |
| 36 | + browserName: 'microsoftedge', |
| 37 | + browserVersion: '17', |
| 38 | + }), |
| 39 | + sauceLabsLauncher({ |
| 40 | + platformName: 'windows 10', |
| 41 | + browserName: 'microsoftedge', |
| 42 | + browserVersion: '15', |
| 43 | + }), |
| 44 | + sauceLabsLauncher({ |
| 45 | + platformName: 'windows 8.1', |
| 46 | + browserName: 'internet explorer', |
| 47 | + browserVersion: '11', |
| 48 | + }), |
| 49 | + sauceLabsLauncher({ |
| 50 | + platformName: 'macos 10.13', |
| 51 | + browserName: 'safari', |
| 52 | + browserVersion: '12', |
| 53 | + }), |
| 54 | + |
| 55 | + // These browsers only support the older JWP protocol. |
| 56 | + // |
| 57 | + // Sauce Labs determines which protocol to use to talk to the launched |
| 58 | + // browser based on whether or not an option called `sauce:options` exists |
| 59 | + // in the given configuration. If this key is passed, the newer W3C standard |
| 60 | + // WebDriver protocol is used; otherwise, JWP is used.[^1] |
| 61 | + // `@web/test-runner-saucelabs` adds the `sauce:options` key if it sees the |
| 62 | + // `browserVersion` key, which is only supported by Sauce Labs with the |
| 63 | + // standard WebDriver protocol.[^2] So, we use the older key names here so |
| 64 | + // that JWP will be used with these browsers. |
| 65 | + // |
| 66 | + // [^1]: https://docs.saucelabs.com/dev/w3c-webdriver-capabilities/#use-sauceoptions |
| 67 | + // [^2]: https://github.com/modernweb-dev/web/blob/db4949ece675d9c6e4bb722bb9700347258b7e96/packages/test-runner-saucelabs/src/createSauceLabsLauncher.ts#L51-L72 |
| 68 | + |
| 69 | + sauceLabsLauncher({ |
| 70 | + platform: 'macos 10.13', |
| 71 | + browserName: 'safari', |
| 72 | + version: '11', |
| 73 | + }), |
| 74 | + sauceLabsLauncher({ |
| 75 | + platform: 'os x 10.11', |
| 76 | + browserName: 'safari', |
| 77 | + version: '10', |
| 78 | + }), |
| 79 | + sauceLabsLauncher({ |
| 80 | + platform: 'os x 10.11', |
| 81 | + browserName: 'safari', |
| 82 | + version: '9', |
| 83 | + }), |
| 84 | + sauceLabsLauncher({ |
| 85 | + platform: 'Linux', |
| 86 | + browserName: 'chrome', |
| 87 | + version: '41', |
| 88 | + }), |
| 89 | + ]; |
| 90 | + |
| 91 | + /** |
| 92 | + * Parses a string representing a browser and platform combination into an |
| 93 | + * object with `platformName`, `browserName`, and `browserVersion` properties. |
| 94 | + */ |
| 95 | + const parseCapabilities = (capabilities) => { |
| 96 | + const [platformName, rest] = capabilities.split('/'); |
| 97 | + const [browserName, browserVersion] = rest.split('@'); |
| 98 | + return { |
| 99 | + platformName, |
| 100 | + browserName, |
| 101 | + browserVersion, |
| 102 | + }; |
| 103 | + }; |
| 104 | + |
| 105 | + // If set, the `BROWSERS` environment variable overrides browsers in the |
| 106 | + // `defaultBrowsers` object. Add `;protocol=w3c` or `;protocol=jwp` to a |
| 107 | + // browser to explicitly control which protocol is used to control that |
| 108 | + // browser. |
| 109 | + const envBrowsers = process.env.BROWSERS?.split(',').map((browser) => { |
| 110 | + const [capabilities, paramStr] = browser.split(';'); |
| 111 | + const params = new URLSearchParams(paramStr); |
| 112 | + const {platformName, browserName, browserVersion} = parseCapabilities( |
| 113 | + capabilities |
| 114 | + ); |
| 115 | + |
| 116 | + const protocol = params.get('protocol'); |
| 117 | + if (!protocol || protocol === 'w3c') { |
| 118 | + return sauceLabsLauncher({ |
| 119 | + platformName, |
| 120 | + browserName, |
| 121 | + browserVersion, |
| 122 | + }); |
| 123 | + } else if (protocol === 'jwp') { |
| 124 | + return sauceLabsLauncher({ |
| 125 | + platform: platformName, |
| 126 | + browserName, |
| 127 | + version: browserVersion, |
| 128 | + }); |
| 129 | + } else { |
| 130 | + console.error('`protocol` must be either undefined, "w3c", or "jwp".'); |
| 131 | + process.exit(1); |
| 132 | + } |
| 133 | + }); |
| 134 | + |
| 135 | + return envBrowsers ?? defaultBrowsers; |
| 136 | +}; |
| 137 | + |
| 138 | +module.exports = { |
| 139 | + files: ['custom-elements/html/**/*.test.(js|html)'], |
| 140 | + rootDir: '../..', |
| 141 | + nodeResolve: true, |
| 142 | + groups: [ |
| 143 | + { |
| 144 | + name: 'local', |
| 145 | + get browsers() { |
| 146 | + return generateLocalBrowserLaunchers(); |
| 147 | + }, |
| 148 | + }, |
| 149 | + { |
| 150 | + name: 'sauce', |
| 151 | + concurrency: 1, |
| 152 | + concurrentBrowsers: 1, |
| 153 | + get browsers() { |
| 154 | + return generateSauceBrowserLaunchers(); |
| 155 | + }, |
| 156 | + plugins: [compileJSPlugin()], |
| 157 | + }, |
| 158 | + ], |
| 159 | +}; |
0 commit comments