|
16 | 16 | */
|
17 | 17 |
|
18 | 18 | const argv = require('yargs').argv;
|
19 |
| -const glob = require('glob'); |
20 |
| -const karma = require('karma'); |
21 | 19 | const path = require('path');
|
22 | 20 | const karmaBase = require('./karma.base');
|
23 | 21 |
|
| 22 | +// karma.conf.js test configuration file to run. |
| 23 | +const testConfigFile = argv['testConfigFile']; |
| 24 | +if (!testConfigFile) { |
| 25 | + console.error('No test file path provided.'); |
| 26 | + process.exit(1); |
| 27 | +} |
| 28 | + |
| 29 | +/** |
| 30 | + * Custom SauceLabs Launchers |
| 31 | + */ |
| 32 | +const browserMap = { |
| 33 | + // Desktop |
| 34 | + Chrome_Windows: seleniumLauncher('chrome', 'Windows 10', 'latest'), |
| 35 | + Firefox_Windows: seleniumLauncher('firefox', 'Windows 10', 'latest'), |
| 36 | + Safari_macOS: seleniumLauncher('safari', 'macOS 10.13', 'latest'), |
| 37 | + Edge_Windows: seleniumLauncher('MicrosoftEdge', 'Windows 10', 'latest'), |
| 38 | + IE_Windows: seleniumLauncher('internet explorer', 'Windows 10', 'latest') |
| 39 | + |
| 40 | + // Mobile |
| 41 | + // Safari_iOS: appiumLauncher('Safari', 'iPhone Simulator', 'iOS', '11.2'), |
| 42 | + // Chrome_Android: appiumLauncher('Chrome', 'Android Emulator', 'Android', '6.0') |
| 43 | +}; |
| 44 | + |
| 45 | +/** |
| 46 | + * Any special options per package. |
| 47 | + */ |
| 48 | +const packageConfigs = { |
| 49 | + messaging: { |
| 50 | + // Messaging currently only supports these browsers. |
| 51 | + browsers: ['Chrome_Windows', 'Firefox_Windows', 'Edge_Windows'] |
| 52 | + } |
| 53 | +}; |
| 54 | + |
| 55 | +/** |
| 56 | + * Gets the browser/launcher map for this package. |
| 57 | + * |
| 58 | + * @param {string} packageName Name of package being tested (e.g., "firestore") |
| 59 | + */ |
| 60 | +function getSauceLabsBrowsers(packageName) { |
| 61 | + if (packageConfigs[packageName]) { |
| 62 | + const filteredBrowserMap = {}; |
| 63 | + for (const browserKey in browserMap) { |
| 64 | + if (packageConfigs[packageName].browsers.includes(browserKey)) { |
| 65 | + filteredBrowserMap[browserKey] = browserMap[browserKey]; |
| 66 | + } |
| 67 | + } |
| 68 | + return filteredBrowserMap; |
| 69 | + } else { |
| 70 | + return browserMap; |
| 71 | + } |
| 72 | +} |
| 73 | + |
| 74 | +/** |
| 75 | + * Get package name from package path command line arg. |
| 76 | + */ |
| 77 | +function getPackageLabels() { |
| 78 | + const match = testConfigFile.match( |
| 79 | + /([a-zA-Z]+)\/([a-zA-Z]+)\/karma\.conf\.js/ |
| 80 | + ); |
| 81 | + return { |
| 82 | + type: match[1], |
| 83 | + name: match[2] |
| 84 | + }; |
| 85 | +} |
| 86 | + |
24 | 87 | /**
|
25 | 88 | * Gets a list of file patterns for test, defined individually
|
26 | 89 | * in karma.conf.js in each package under worksapce packages or
|
27 | 90 | * integration.
|
28 | 91 | */
|
29 | 92 | function getTestFiles() {
|
30 | 93 | let root = path.resolve(__dirname, '..');
|
31 |
| - configs = argv['database-firestore-only'] |
32 |
| - ? glob.sync('packages/{database,firestore}/karma.conf.js') |
33 |
| - : glob.sync('{packages,integration}/*/karma.conf.js', { |
34 |
| - // Excluded due to flakiness or long run time. |
35 |
| - ignore: [ |
36 |
| - 'packages/database/*', |
37 |
| - 'packages/firestore/*', |
38 |
| - 'integration/firestore/*', |
39 |
| - 'integration/messaging/*' |
40 |
| - ] |
41 |
| - }); |
42 |
| - files = configs.map(x => { |
43 |
| - let patterns = require(path.join(root, x)).files; |
44 |
| - let dirname = path.dirname(x); |
45 |
| - return patterns.map(p => path.join(dirname, p)); |
46 |
| - }); |
47 |
| - return [].concat(...files); |
| 94 | + const { name: packageName } = getPackageLabels(); |
| 95 | + let patterns = require(path.join(root, testConfigFile)).files; |
| 96 | + let dirname = path.dirname(testConfigFile); |
| 97 | + return { packageName, files: patterns.map(p => path.join(dirname, p)) }; |
48 | 98 | }
|
49 | 99 |
|
50 | 100 | function seleniumLauncher(browserName, platform, version) {
|
| 101 | + const { name, type } = getPackageLabels(); |
| 102 | + const testName = |
| 103 | + type === 'integration' |
| 104 | + ? `${type}-${name}-${browserName}` |
| 105 | + : `${name}-${browserName}`; |
51 | 106 | return {
|
52 | 107 | base: 'SauceLabs',
|
53 | 108 | browserName: browserName,
|
54 | 109 | extendedDebugging: 'true',
|
| 110 | + name: testName, |
55 | 111 | recordLogs: 'true',
|
56 | 112 | recordVideo: 'true',
|
57 | 113 | recordScreenshots: 'true',
|
@@ -81,27 +137,32 @@ function appiumLauncher(
|
81 | 137 | };
|
82 | 138 | }
|
83 | 139 |
|
84 |
| -/** |
85 |
| - * Custom SauceLabs Launchers |
86 |
| - */ |
87 |
| -const sauceLabsBrowsers = { |
88 |
| - // Desktop |
89 |
| - Chrome_Windows: seleniumLauncher('chrome', 'Windows 10', 'latest'), |
90 |
| - Firefox_Windows: seleniumLauncher('firefox', 'Windows 10', 'latest'), |
91 |
| - Safari_macOS: seleniumLauncher('safari', 'macOS 10.13', 'latest'), |
92 |
| - Edge_Windows: seleniumLauncher('MicrosoftEdge', 'Windows 10', 'latest'), |
93 |
| - IE_Windows: seleniumLauncher('internet explorer', 'Windows 10', 'latest') |
94 |
| - |
95 |
| - // Mobile |
96 |
| - // Safari_iOS: appiumLauncher('Safari', 'iPhone Simulator', 'iOS', '11.2'), |
97 |
| - // Chrome_Android: appiumLauncher('Chrome', 'Android Emulator', 'Android', '6.0') |
98 |
| -}; |
99 |
| - |
100 | 140 | module.exports = function(config) {
|
| 141 | + const { packageName, files: testFiles } = getTestFiles(); |
| 142 | + const sauceLabsBrowsers = getSauceLabsBrowsers(packageName); |
| 143 | + |
| 144 | + const sauceLabsConfig = { |
| 145 | + tunnelIdentifier: process.env.TRAVIS_JOB_NUMBER + '-' + packageName, |
| 146 | + build: process.env.TRAVIS_BUILD_NUMBER || argv['buildNumber'], |
| 147 | + username: process.env.SAUCE_USERNAME, |
| 148 | + accessKey: process.env.SAUCE_ACCESS_KEY, |
| 149 | + startConnect: true, |
| 150 | + connectOptions: { |
| 151 | + // Realtime Database uses WebSockets to connect to firebaseio.com |
| 152 | + // so we have to set noSslBumpDomains. Theoretically SSL Bumping |
| 153 | + // only needs to be disabled for 'firebaseio.com'. However, we are |
| 154 | + // seeing much longer test time with that configuration, so leave |
| 155 | + // it as 'all' for now. |
| 156 | + // See https://wiki.saucelabs.com/display/DOCS/Troubleshooting+Sauce+Connect |
| 157 | + // for more details. |
| 158 | + noSslBumpDomains: 'all' |
| 159 | + } |
| 160 | + }; |
| 161 | + |
101 | 162 | const karmaConfig = Object.assign({}, karmaBase, {
|
102 | 163 | basePath: '../',
|
103 | 164 |
|
104 |
| - files: ['packages/polyfill/index.ts', ...getTestFiles()], |
| 165 | + files: ['packages/polyfill/index.ts', ...testFiles], |
105 | 166 |
|
106 | 167 | logLevel: config.LOG_INFO,
|
107 | 168 |
|
@@ -151,22 +212,7 @@ module.exports = function(config) {
|
151 | 212 | overviewColumn: false
|
152 | 213 | },
|
153 | 214 |
|
154 |
| - sauceLabs: { |
155 |
| - tunnelIdentifier: process.env.TRAVIS_JOB_NUMBER, |
156 |
| - username: process.env.SAUCE_USERNAME, |
157 |
| - accessKey: process.env.SAUCE_ACCESS_KEY, |
158 |
| - startConnect: true, |
159 |
| - connectOptions: { |
160 |
| - // Realtime Database uses WebSockets to connect to firebaseio.com |
161 |
| - // so we have to set noSslBumpDomains. Theoretically SSL Bumping |
162 |
| - // only needs to be disabled for 'firebaseio.com'. However, we are |
163 |
| - // seeing much longer test time with that configuration, so leave |
164 |
| - // it as 'all' for now. |
165 |
| - // See https://wiki.saucelabs.com/display/DOCS/Troubleshooting+Sauce+Connect |
166 |
| - // for more details. |
167 |
| - noSslBumpDomains: 'all' |
168 |
| - } |
169 |
| - } |
| 215 | + sauceLabs: sauceLabsConfig |
170 | 216 | });
|
171 | 217 |
|
172 | 218 | config.set(karmaConfig);
|
|
0 commit comments