Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 2k
Shard gl jasmine tests#2933
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Shard gl jasmine tests #2933
Changes from all commits
635b64353657e702308d0094e06dc9a4eb5e23ee6e6d8da96ba753c481709007712507bdf468e689671bc88bdbb6c292906daf432006d5d1File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| var fs = require('fs'); | ||
| var path = require('path'); | ||
| var falafel = require('falafel'); | ||
| var glob = require('glob'); | ||
| var minimist = require('minimist'); | ||
| var pathToJasmineTests = require('./util/constants').pathToJasmineTests; | ||
| var isJasmineTestIt = require('./util/common').isJasmineTestIt; | ||
| var argv = minimist(process.argv.slice(2), { | ||
| string: ['tag', 'limit'], | ||
| alias: { | ||
| tag: ['t'], | ||
| limit: ['l'], | ||
| }, | ||
| default: { | ||
| limit: 20 | ||
| } | ||
| }); | ||
| var tag = argv.tag; | ||
| var limit = argv.limit; | ||
| glob(path.join(pathToJasmineTests, '*.js'), function(err, files) { | ||
| if(err) throw err; | ||
| var file2cnt = {}; | ||
ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to note, with | ||
| files.forEach(function(file) { | ||
| var code = fs.readFileSync(file, 'utf-8'); | ||
| var bn = path.basename(file); | ||
| falafel(code, function(node) { | ||
| if(isJasmineTestIt(node, tag)) { | ||
| if(file2cnt[bn]) { | ||
| file2cnt[bn]++; | ||
| } else { | ||
| file2cnt[bn] = 1; | ||
| } | ||
| } | ||
| }); | ||
| }); | ||
| var ranking = Object.keys(file2cnt); | ||
| var runs = []; | ||
| // if 'it' count in file greater than threshold, | ||
| // run only this file separately, | ||
| // don't try to shard within file | ||
| Object.keys(file2cnt).forEach(function(f) { | ||
| if(file2cnt[f] > limit) { | ||
| runs.push(f); | ||
| ranking.splice(ranking.indexOf(f), 1); | ||
| } | ||
| }); | ||
| // sort ranking in decreasing order | ||
| ranking.sort(function(a, b) { return file2cnt[b] - file2cnt[a]; }); | ||
| var runi; | ||
| var cnt; | ||
| function newRun() { | ||
| var r0 = ranking[0]; | ||
| runi = [r0]; | ||
| cnt = file2cnt[r0]; | ||
| ranking.shift(); | ||
| } | ||
| function concat() { | ||
| runs.push(runi.join(',')); | ||
| } | ||
| // try to match files with many tests with files not-that-many, | ||
| // by matching first rank with one or multiple trailing ranks. | ||
| newRun(); | ||
| while(ranking.length) { | ||
| var rn = ranking[ranking.length - 1]; | ||
| if((cnt + file2cnt[rn]) > limit) { | ||
| concat(); | ||
| newRun(); | ||
| } else { | ||
| runi.push(rn); | ||
| cnt += file2cnt[rn]; | ||
| ranking.pop(); | ||
| } | ||
| } | ||
| concat(); | ||
| // print result to stdout | ||
| console.log(runs.join('\n')); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -7,16 +7,18 @@ var constants = require('../../tasks/util/constants'); | ||
| var isCI = !!process.env.CIRCLECI; | ||
| var argv = minimist(process.argv.slice(4), { | ||
| string: ['bundleTest', 'width', 'height'], | ||
| 'boolean': ['info', 'nowatch', 'verbose', 'Chrome', 'Firefox'], | ||
| 'boolean': ['info', 'nowatch', 'failFast', 'verbose', 'Chrome', 'Firefox'], | ||
| alias: { | ||
| 'Chrome': 'chrome', | ||
| 'Firefox': ['firefox', 'FF'], | ||
| 'bundleTest': ['bundletest', 'bundle_test'], | ||
| 'nowatch': 'no-watch' | ||
| 'nowatch': 'no-watch', | ||
| 'failFast': 'fail-fast' | ||
| }, | ||
| 'default': { | ||
| info: false, | ||
| nowatch: isCI, | ||
| failFast: false, | ||
| verbose: false, | ||
| width: '1035', | ||
| height: '617' | ||
| @@ -53,6 +55,7 @@ if(argv.info) { | ||
| ' - `--Chrome` (alias `--chrome`): run test in (our custom) Chrome browser', | ||
| ' - `--Firefox` (alias `--FF`, `--firefox`): run test in (our custom) Firefox browser', | ||
| ' - `--nowatch (dflt: `false`, `true` on CI)`: run karma w/o `autoWatch` / multiple run mode', | ||
| ' - `--failFast` (dflt: `false`): exit karma upon first test failure', | ||
| ' - `--verbose` (dflt: `false`): show test result using verbose reporter', | ||
| ' - `--tags`: run only test with given tags (using the `jasmine-spec-tags` framework)', | ||
| ' - `--width`(dflt: 1035): set width of the browser window', | ||
| @@ -100,11 +103,14 @@ if(isFullSuite) { | ||
| var pathToShortcutPath = path.join(__dirname, '..', '..', 'tasks', 'util', 'shortcut_paths.js'); | ||
| var pathToStrictD3 = path.join(__dirname, '..', '..', 'tasks', 'util', 'strict_d3.js'); | ||
| var pathToMain = path.join(__dirname, '..', '..', 'lib', 'index.js'); | ||
| var pathToJQuery = path.join(__dirname, 'assets', 'jquery-1.8.3.min.js'); | ||
| var pathToIE9mock = path.join(__dirname, 'assets', 'ie9_mock.js'); | ||
| var pathToCustomMatchers = path.join(__dirname, 'assets', 'custom_matchers.js'); | ||
| var reporters = (isFullSuite && !argv.tags) ? ['dots', 'spec'] : ['progress']; | ||
| if(argv.failFast) reporters.push('fail-fast'); | ||
| if(argv.verbose) reporters.push('verbose'); | ||
| function func(config) { | ||
| // level of logging | ||
| // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG | ||
| @@ -118,7 +124,7 @@ function func(config) { | ||
| // | ||
| // See https://github.com/karma-runner/karma/commit/89a7a1c#commitcomment-21009216 | ||
| func.defaultConfig.browserConsoleLogOptions = { | ||
| level: 'log' | ||
| level: 'debug' | ||
| }; | ||
| config.set(func.defaultConfig); | ||
| @@ -154,7 +160,7 @@ func.defaultConfig = { | ||
| // See note in CONTRIBUTING.md about more verbose reporting via karma-verbose-reporter: | ||
| // https://www.npmjs.com/package/karma-verbose-reporter ('verbose') | ||
| // | ||
| reporters: (isFullSuite && !argv.tags) ? ['dots', 'spec'] : ['progress'], | ||
| reporters: reporters, | ||
| // web server port | ||
| port: 9876, | ||
| @@ -235,16 +241,18 @@ func.defaultConfig = { | ||
| suppressPassed: true, | ||
| suppressSkipped: false, | ||
| showSpecTiming: false, | ||
| // use 'karma-fail-fast-reporter' to fail fast w/o conflicting | ||
| // with other karma plugins | ||
| failFast: false | ||
Collaborator There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So this ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Setting it to ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. More on this topic: to make When doing so, it conflicts with There might be a way, to list them (order dependent?) so that they don't conflict, but using | ||
| } | ||
| }, | ||
| // e.g. when a test file does not container a given spec tags | ||
| failOnEmptyTestSuite: false | ||
| }; | ||
| func.defaultConfig.preprocessors[pathToCustomMatchers] = ['browserify']; | ||
| if(isFullSuite) { | ||
| func.defaultConfig.files.push(pathToJQuery); | ||
| func.defaultConfig.preprocessors[testFileGlob] = ['browserify']; | ||
| } else if(isBundleTest) { | ||
| if(isBundleTest) { | ||
| switch(basename(testFileGlob)) { | ||
| case 'requirejs': | ||
| // browserified custom_matchers doesn't work with this route | ||
| @@ -271,14 +279,7 @@ if(isFullSuite) { | ||
| break; | ||
| } | ||
| } else { | ||
| // Add lib/index.js to non-full-suite runs, | ||
| // to make sure the registry is set-up correctly. | ||
| func.defaultConfig.files.push( | ||
| pathToJQuery, | ||
| pathToMain | ||
| ); | ||
| func.defaultConfig.preprocessors[pathToMain] = ['browserify']; | ||
| func.defaultConfig.files.push(pathToJQuery); | ||
| func.defaultConfig.preprocessors[testFileGlob] = ['browserify']; | ||
| } | ||
| @@ -291,9 +292,4 @@ if(argv.Chrome) browsers.push('_Chrome'); | ||
| if(argv.Firefox) browsers.push('_Firefox'); | ||
| if(browsers.length === 0) browsers.push('_Chrome'); | ||
| // add verbose reporter if specified | ||
| if(argv.verbose) { | ||
| func.defaultConfig.reporters.push('verbose'); | ||
| } | ||
| module.exports = func; | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
man, shell scripts are ugly... that said, very nicely done 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was the cleanest solution I could think of 😑