diff --git a/README.md b/README.md index 39d1446..0f98ee4 100644 --- a/README.md +++ b/README.md @@ -185,9 +185,9 @@ module.exports = require("@jsdevtools/karma-config")({ |`browsers` |`object` | |This object allows you to specify which browsers to test on |`browsers.chrome` |`boolean` |`true` for Linux
`false` on other platforms |Whether to test on Chrome. |`browsers.firefox`|`boolean` |`true` for Linux
`false` on other platforms |Whether to test on Firefox. -|`browsers.safari` |`boolean` |`true` for Mac
`false` on other platforms |Whether to test on Safari.
Can use [SauceLabs](#saucelabs) if configured. -|`browsers.edge` |`boolean` |`true` for Windows
`false` on other platforms |Whether to test on Edge (the EdgeHTML engine, not Chromium).
Can use [SauceLabs](#saucelabs) if configured. -|`browsers.ie` |`boolean` |`false` |Whether to test on Internet Explorer.
Can use [SauceLabs](#saucelabs) if configured. +|`browsers.safari` |`boolean` |`true` for Mac
`false` on other platforms |Whether to test on Safari. +|`browsers.edge` |`boolean` |`true` for Windows
`false` on other platforms |Whether to test on Edge (the EdgeHTML engine, not Chromium). +|`browsers.ie` |`boolean` |`false` |Whether to test on Internet Explorer. |`sourceDir` |`string` |`src` |The relative path of the source directory. |`testDir` |`string` |`test` |The relative path of the test directory. |`tests` |`string` `string[]` `object` `object[]`|`${testDir}/**/*.spec.js` `${testDir}/**/*.test.js` `${testDir}/**/*.spec.jsx` `${testDir}/**/*.test.jsx` `${testDir}/**/*.spec.mjs` `${testDir}/**/*.test.mjs`|One or more [file patterns](https://karma-runner.github.io/3.0/config/files.html) that specify your test files. These are the files that will be bundled by Webpack and run by Karma. @@ -200,30 +200,6 @@ module.exports = require("@jsdevtools/karma-config")({ |`config` |`object` |`{}` |Explicit Karma configuration settings. This is useful for adding additional settings that aren't normally set by Karma Config, or for overriding Karma Config's settings. - -SauceLabs --------------------------- -Safari, Edge, and Internet Explorer aren't supported on some CI/CD services. Karma Config allows you to use [SauceLabs](https://saucelabs.com) to test on these browsers. - -Karma Config uses the [Sauce Connect proxy](https://wiki.saucelabs.com/display/DOCS/Sauce+Connect+Proxy) to open a secure channel to SauceLabs. Sauce Connect is **only supported on Linux** and requires the `SAUCE_USERNAME` and `SAUCE_ACCESS_KEY` environment variables to be set. - -```javascript -module.exports = require("@jsdevtools/karma-config")({ - browsers: { - // No need to explicitly set these, since they are tested by default on Linux - // firefox: true, - // chrome: true, - - // Test these browsers using SauceLabs - ie: true, - edge: true, - safari: true, - } -}); -``` - - - Contributing -------------------------- Contributions, enhancements, and bug-fixes are welcome! [Open an issue](https://github.com/JS-DevTools/karma-config/issues) on GitHub and [submit a pull request](https://github.com/JS-DevTools/karma-config/pulls). @@ -260,5 +236,3 @@ Thanks to these awesome companies for their support of Open Source developers [![GitHub](https://jstools.dev/img/badges/github.svg)](https://github.com/open-source) [![NPM](https://jstools.dev/img/badges/npm.svg)](https://www.npmjs.com/) [![Coveralls](https://jstools.dev/img/badges/coveralls.svg)](https://coveralls.io) -[![Travis CI](https://jstools.dev/img/badges/travis-ci.svg)](https://travis-ci.com) -[![SauceLabs](https://jstools.dev/img/badges/sauce-labs.svg)](https://saucelabs.com) diff --git a/package.json b/package.json index ce29ee7..d616251 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,6 @@ "karma-ie-launcher": "^1.0.0", "karma-mocha": "^2.0.1", "karma-safari-launcher": "^1.0.0", - "karma-sauce-launcher": "^4.3.6", "karma-verbose-reporter": "^0.0.8", "karma-webpack": "^4.0.2", "webpack": "^4.43.0" diff --git a/src/configure-browsers.ts b/src/configure-browsers.ts index c529796..8bd33a7 100644 --- a/src/configure-browsers.ts +++ b/src/configure-browsers.ts @@ -31,109 +31,9 @@ export function configureBrowsers(config: ConfigOptions, options: NormalizedOpti firefox && browsers.push("Firefox"); } - if (canRunSauceConnect(options)) { - configureSauceLabs(config, options); - } - else { - safari && browsers.push("Safari"); - edge && browsers.push("Edge"); - ie && browsers.push("IE"); - } - - return config; -} - -/** - * Determines whether the system meets the requirements for running the Sauce Connect proxy. - * - * @see https://github.com/karma-runner/karma-sauce-launcher - */ -function canRunSauceConnect(options: NormalizedOptions): boolean { - let username = process.env.SAUCE_USERNAME; - let accessKey = process.env.SAUCE_ACCESS_KEY; - - return Boolean(options.linux && username && accessKey); -} - -/** - * Configures Karma to use Sauce Labs for Windows browser testing. - * Returns `false` if Sauce Labs credentials are not present. - * - * @see https://github.com/karma-runner/karma-sauce-launcher - */ -function configureSauceLabs(config: ConfigOptions, options: NormalizedOptions): ConfigOptions { - let { browsers: { safari, edge, ie }} = options; - let browsers = config.browsers!; - - if (!(safari || edge || ie)) { - // No need to run tests on Sauce Labs - return config; - } - - addPlugin(config, "karma-sauce-launcher"); - - let buildNumber = - process.env.BUILD_NUMBER || - process.env.BUILD_TAG || - process.env.CI_BUILD_NUMBER || - process.env.CI_BUILD_TAG || - process.env.TRAVIS_BUILD_NUMBER || - process.env.CIRCLE_BUILD_NUM || - process.env.DRONE_BUILD_NUMBER || - process.env.GITHUB_RUN_NUMBER || - Date.now(); - - let pkg = readPackageJson(); - - config.reporters!.push("saucelabs"); - - config = mergeConfig(config, { - logLevel: "debug", - // concurrency: 1, - captureTimeout: 60000, - browserDisconnectTolerance: 5, - browserDisconnectTimeout: 60000, - browserNoActivityTimeout: 60000, - }); - - config.sauceLabs = mergeConfig(config.sauceLabs, { - build: `${pkg.name} v${pkg.version} Build #${buildNumber}`, - testName: `${pkg.name} v${pkg.version}`, - tags: [pkg.name], - }); - - config.customLaunchers = config.customLaunchers || {}; - - if (safari) { - browsers.push("Safari_SauceLabs"); - // eslint-disable-next-line camelcase - config.customLaunchers.Safari_SauceLabs = mergeConfig(config.customLaunchers.Safari_SauceLabs, { - base: "SauceLabs", - platform: "MacOS 10.15", // Catalina - browserName: "safari", - }); - } - - if (edge) { - browsers.push("Edge_SauceLabs"); - // eslint-disable-next-line camelcase - config.customLaunchers.Edge_SauceLabs = mergeConfig(config.customLaunchers.Edge_SauceLabs, { - base: "SauceLabs", - platform: "Windows 10", - browserName: "microsoftedge", - version: "18.17763", // The last version of EdgeHTML, before the switch to Chromium - }); - } - - if (ie) { - browsers.push("IE_SauceLabs"); - // eslint-disable-next-line camelcase - config.customLaunchers.IE_SauceLabs = mergeConfig(config.customLaunchers.IE_SauceLabs, { - base: "SauceLabs", - platform: "Windows 10", - browserName: "internet explorer" - }); - } + safari && browsers.push("Safari"); + edge && browsers.push("Edge"); + ie && browsers.push("IE"); return config; } diff --git a/src/types/karma-sauce-launcher/index.d.ts b/src/types/karma-sauce-launcher/index.d.ts deleted file mode 100644 index f2b4853..0000000 --- a/src/types/karma-sauce-launcher/index.d.ts +++ /dev/null @@ -1,32 +0,0 @@ -import "karma"; - -/** - * @see https://github.com/karma-runner/karma-sauce-launcher#saucelabs-config-properties-shared-across-all-browsers - */ -interface SauceLabsConfig { - username?: string; - accessKey?: string; - proxy?: string; - startConnect?: boolean; - connectOptions?: object; - connectLocationForSERelay?: string; - connectPortForSERelay?: number; - build?: string; - testName?: string; - tunnelIdentifier?: string; - tags?: string[]; - recordVideo?: boolean; - recordScreenshots?: boolean; - public?: string; - customData?: object; -} - -declare module "karma" { - interface ConfigOptions { - sauceLabs: SauceLabsConfig; - } - - interface CustomLauncher { - deviceOrientation?: "portrait" | "landscape"; - } -} diff --git a/test/fixtures/mocha-hooks.js b/test/fixtures/mocha-hooks.js index 6ddb0d2..f64e63e 100644 --- a/test/fixtures/mocha-hooks.js +++ b/test/fixtures/mocha-hooks.js @@ -9,8 +9,6 @@ let envDefaults = { KARMA_CI: "", CI: "", CI_BUILD_NUMBER: "", - SAUCE_USERNAME: "", - SAUCE_ACCESS_KEY: "", GITHUB_ACTIONS: "", }; diff --git a/test/specs/browsers.spec.js b/test/specs/browsers.spec.js index e20fae2..1d3398f 100644 --- a/test/specs/browsers.spec.js +++ b/test/specs/browsers.spec.js @@ -17,98 +17,6 @@ describe("Browser config", () => { expect(config.browsers).to.deep.equal(["Opera"]); }); - it("should not override SauceLabs options that are specified by the user", () => { - process.env.SAUCE_USERNAME = "my-username"; - process.env.SAUCE_ACCESS_KEY = "my-access-key"; - process.env.CI_BUILD_NUMBER = "1.23"; - - let config = buildConfig({ - platform: "linux", - browsers: { - safari: true, - edge: true, - ie: true, - }, - config: { - captureTimeout: 999, - browserDisconnectTolerance: 999, - sauceLabs: { - tags: ["tag1", "tag2"], - }, - customLaunchers: { - // eslint-disable-next-line camelcase - IE_SauceLabs: { - version: "7" - } - } - } - }); - - expect(config).to.satisfy(compareConfig({ - plugins: [ - "framework:host-environment", - "framework:mocha", - "reporter:verbose", - "preprocessor:webpack", - "launcher:Chrome", - "launcher:Firefox", - "launcher:Safari", - "launcher:Edge", - "launcher:IE", - "launcher:SauceLabs", - ], - reporters: ["verbose", "saucelabs"], - browsers: ["Chrome", "Firefox", "Safari_SauceLabs", "Edge_SauceLabs", "IE_SauceLabs"], - logLevel: "debug", - captureTimeout: 999, - browserDisconnectTolerance: 999, - browserDisconnectTimeout: 60000, - browserNoActivityTimeout: 60000, - sauceLabs: { - build: `@jsdevtools/karma-config v${pkg.version} Build #1.23`, - testName: `@jsdevtools/karma-config v${pkg.version}`, - tags: ["tag1", "tag2"], - }, - customLaunchers: { - /* eslint-disable camelcase */ - Safari_SauceLabs: { - base: "SauceLabs", - platform: "MacOS 10.15", - browserName: "safari", - }, - Edge_SauceLabs: { - base: "SauceLabs", - platform: "Windows 10", - browserName: "microsoftedge", - version: "18.17763" - }, - IE_SauceLabs: { - base: "SauceLabs", - platform: "Windows 10", - browserName: "internet explorer", - version: "7" - }, - }, - webpack: { - mode: "development", - devtool: "inline-source-map", - module: { - rules: [ - { - test: /\.(js|jsx|mjs)$/, - use: { - loader: "babel-loader", - options: { - presets: ["@babel/preset-env"] - } - } - } - ] - } - } - })); - }); - it("should use sensible default browsers per platform", () => { let config = buildConfig(); @@ -163,168 +71,4 @@ describe("Browser config", () => { expect(config.browsers).to.deep.equal(["ChromeHeadless", "FirefoxHeadless", "IE"]); } }); - - it("should not use SauceLabs if credentials don't exist", () => { - let config = buildConfig({ - platform: "linux", - browsers: { - safari: true, - edge: true, - ie: true, - } - }); - - expect(config.browsers).to.deep.equal(["Chrome", "Firefox", "Safari", "Edge", "IE"]); - expect(config).not.to.have.property("sauceLabs"); - expect(config).not.to.have.property("customLaunchers"); - }); - - it("should not use SauceLabs on Linux by default", () => { - process.env.SAUCE_USERNAME = "my-username"; - process.env.SAUCE_ACCESS_KEY = "my-access-key"; - process.env.CI_BUILD_NUMBER = "1.23"; - - let config = buildConfig({ - platform: "linux", - }); - - expect(config).to.satisfy(compareConfig({ - plugins: [ - "framework:host-environment", - "framework:mocha", - "reporter:verbose", - "preprocessor:webpack", - "launcher:Chrome", - "launcher:Firefox", - ], - reporters: ["verbose"], - browsers: ["Chrome", "Firefox"], - })); - }); - - it("should prefer SauceLabs on Linux", () => { - process.env.SAUCE_USERNAME = "my-username"; - process.env.SAUCE_ACCESS_KEY = "my-access-key"; - process.env.CI_BUILD_NUMBER = "1.23"; - - let config = buildConfig({ - platform: "linux", - browsers: { - safari: true, - edge: true, - } - }); - - expect(config).to.satisfy(compareConfig({ - plugins: [ - "framework:host-environment", - "framework:mocha", - "reporter:verbose", - "preprocessor:webpack", - "launcher:Chrome", - "launcher:Firefox", - "launcher:Safari", - "launcher:Edge", - "launcher:SauceLabs", - ], - reporters: ["verbose", "saucelabs"], - browsers: ["Chrome", "Firefox", "Safari_SauceLabs", "Edge_SauceLabs"], - logLevel: "debug", - captureTimeout: 60000, - browserDisconnectTolerance: 5, - browserDisconnectTimeout: 60000, - browserNoActivityTimeout: 60000, - sauceLabs: { - build: `@jsdevtools/karma-config v${pkg.version} Build #1.23`, - testName: `@jsdevtools/karma-config v${pkg.version}`, - tags: ["@jsdevtools/karma-config"], - }, - customLaunchers: { - /* eslint-disable camelcase */ - Safari_SauceLabs: { - base: "SauceLabs", - platform: "MacOS 10.15", - browserName: "safari", - }, - Edge_SauceLabs: { - base: "SauceLabs", - platform: "Windows 10", - browserName: "microsoftedge", - version: "18.17763" - }, - } - })); - }); - - it("should use headless browsers and SauceLabs on Linux CI", () => { - process.env.SAUCE_USERNAME = "my-username"; - process.env.SAUCE_ACCESS_KEY = "my-access-key"; - process.env.CI_BUILD_NUMBER = "1.23"; - - let config = buildConfig({ - CI: true, - platform: "linux", - browsers: { - ie: true, - safari: true, - } - }); - - expect(config).to.satisfy(compareConfig({ - plugins: [ - "framework:host-environment", - "framework:mocha", - "reporter:verbose", - "preprocessor:webpack", - "launcher:Chrome", - "launcher:Firefox", - "launcher:Safari", - "launcher:IE", - "launcher:SauceLabs", - ], - reporters: ["verbose", "saucelabs"], - browsers: ["ChromeHeadless", "FirefoxHeadless", "Safari_SauceLabs", "IE_SauceLabs"], - logLevel: "debug", - captureTimeout: 60000, - browserDisconnectTolerance: 5, - browserDisconnectTimeout: 60000, - browserNoActivityTimeout: 60000, - sauceLabs: { - build: `@jsdevtools/karma-config v${pkg.version} Build #1.23`, - testName: `@jsdevtools/karma-config v${pkg.version}`, - tags: ["@jsdevtools/karma-config"], - }, - customLaunchers: { - /* eslint-disable camelcase */ - Safari_SauceLabs: { - base: "SauceLabs", - platform: "MacOS 10.15", - browserName: "safari", - }, - IE_SauceLabs: { - base: "SauceLabs", - platform: "Windows 10", - browserName: "internet explorer", - }, - }, - webpack: { - mode: "development", - devtool: "inline-source-map", - module: { - rules: [ - { - test: /\.(js|jsx|mjs)$/, - use: { - loader: "babel-loader", - options: { - presets: ["@babel/preset-env"] - } - } - } - ] - } - } - })); - }); - });