Skip to content

Commit dee991c

Browse files
committed
feat(ui-karma-config,ui-scripts): --randomize test order flag
Change-Id: Iba9dbce33e002c8a2ab59391bd40cc0373d5e4b6 Reviewed-on: https://gerrit.instructure.com/184677 Tested-by: Jenkins Reviewed-by: Jennifer Stern <jstern@instructure.com> QA-Review: Jennifer Stern <jstern@instructure.com> Product-Review: Jennifer Stern <jstern@instructure.com>
1 parent 127d329 commit dee991c

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

packages/ui-karma-config/lib/index.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@
2323
*/
2424
const path = require('path')
2525
const constants = require('karma').constants
26+
const choma = require.resolve('choma')
2627

2728
const noLaunchers = process.argv.some((arg) => arg === '--no-launch')
2829
const noHeadless = process.argv.some((arg) => arg === '--no-headless')
30+
const randomizeTestOrder = process.argv.some((arg) => arg === '--randomize')
2931

3032
const baseWebpackConfig = require('@instructure/ui-webpack-config')
3133

@@ -94,9 +96,10 @@ module.exports = function makeConfig ({
9496

9597
frameworks: ['mocha', 'viewport'],
9698

97-
files: [bundle],
99+
files: randomizeTestOrder ? [choma, bundle] : [bundle],
98100

99101
preprocessors: {
102+
[choma]: ['webpack'],
100103
[bundle]: ['webpack', 'sourcemap']
101104
},
102105

@@ -156,7 +159,12 @@ module.exports = function makeConfig ({
156159
externals: {
157160
'react/lib/ExecutionEnvironment': true,
158161
'react/lib/ReactContext': true,
159-
'react/addons': true
162+
'react/addons': true,
163+
// The karma webpack plugin exposes a mocha instance as
164+
// `window.mocha`, but the mocha npm package exports the mocha
165+
// contructor function. The choma script needs access to the mocha
166+
// constructor so it can monkey-patch it for random test ordering.
167+
'mocha': 'mocha.constructor'
160168
},
161169
resolveLoader: {
162170
alias: {

packages/ui-karma-config/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"dependencies": {
1919
"@instructure/config-loader": "^5",
2020
"@instructure/ui-webpack-config": "^5",
21+
"choma": "^1",
2122
"globby": "^9.0.0",
2223
"karma": "^4.0.0",
2324
"karma-chrome-launcher": "^2.2.0",

packages/ui-scripts/lib/test/karma.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ if (argv.includes('--no-headless')) {
4444
args.push('--no-headless')
4545
}
4646

47+
if (argv.includes('--randomize')) {
48+
args.push('--randomize')
49+
}
50+
4751
const browsersArgIndex = argv.findIndex(arg => arg.startsWith('--browsers='))
4852

4953
if (browsersArgIndex) {

yarn.lock

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4019,7 +4019,7 @@ chalk@2.4.1:
40194019
escape-string-regexp "^1.0.5"
40204020
supports-color "^5.3.0"
40214021

4022-
chalk@2.4.2, chalk@^2.0.0, chalk@^2.0.1, chalk@^2.1.0, chalk@^2.3.0, chalk@^2.3.1, chalk@^2.4.1, chalk@^2.4.2:
4022+
chalk@2.4.2, chalk@^2.0.0, chalk@^2.0.1, chalk@^2.1.0, chalk@^2.3.0, chalk@^2.3.1, chalk@^2.3.2, chalk@^2.4.1, chalk@^2.4.2:
40234023
version "2.4.2"
40244024
resolved "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz#cd42541677a54333cf541a49108c1432b44c9424"
40254025
integrity sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==
@@ -4130,6 +4130,14 @@ chokidar@^2.0.0, chokidar@^2.0.2, chokidar@^2.0.3:
41304130
optionalDependencies:
41314131
fsevents "^1.2.7"
41324132

4133+
choma@^1:
4134+
version "1.2.1"
4135+
resolved "https://registry.npmjs.org/choma/-/choma-1.2.1.tgz#3467e5e1095ece975c48b74ded33ab771e2faaf4"
4136+
integrity sha512-4KwEouEHt6SfG8vYnN2gSJfq/cGmnY2gubnUgsgkRXzHoSRAgluX2YXQgDg6bTDWuOmUrTb/cfwMpNlvnnPZCg==
4137+
dependencies:
4138+
chalk "^2.3.2"
4139+
seedrandom "^2.4.3"
4140+
41334141
chownr@^1.1.1:
41344142
version "1.1.1"
41354143
resolved "https://registry.npmjs.org/chownr/-/chownr-1.1.1.tgz#54726b8b8fff4df053c42187e801fb4412df1494"
@@ -14528,6 +14536,11 @@ script-ext-html-webpack-plugin@^2.1.3:
1452814536
dependencies:
1452914537
debug "^4.1.0"
1453014538

14539+
seedrandom@^2.4.3:
14540+
version "2.4.4"
14541+
resolved "https://registry.npmjs.org/seedrandom/-/seedrandom-2.4.4.tgz#b25ea98632c73e45f58b77cfaa931678df01f9ba"
14542+
integrity sha512-9A+PDmgm+2du77B5i0Ip2cxOqqHjgNxnBgglxLcX78A2D6c2rTo61z4jnVABpF4cKeDMDG+cmXXvdnqse2VqMA==
14543+
1453114544
seekout@^1.0.1:
1453214545
version "1.0.2"
1453314546
resolved "https://registry.npmjs.org/seekout/-/seekout-1.0.2.tgz#09ba9f1bd5b46fbb134718eb19a68382cbb1b9c9"

0 commit comments

Comments
 (0)