JavaScript tests share required files / window object
Summary
When running the JavaScript tests using Karma, require('~/something')
statements and changes to the window
object are still present for test files running later.
Steps to reproduce
echo "window.Something = 'something';" > app/assets/javascripts/something.js
echo "console.log('1 Something is: ' + window.Something);" > spec/javascripts/1_spec.js
echo "require('~/something');" > spec/javascripts/2_spec.js
echo "console.log('3 Something is: ' + window.Something);" > spec/javascripts/3_spec.js
Expected output
1 Something is: undefined
3 Something is: undefined
Actual output
1 Something is: undefined
3 Something is: something
Implications
- Tests may depend on other test files to set up an environment in which they pass, so order in which test files are executed is important.
- Tests may only pass because other tests have run before.
Possible fixes
#20983 (closed) would be a workaround