Skip to content

Commit

Permalink
Allow us to run our unit test on differents jquery version
Browse files Browse the repository at this point in the history
  • Loading branch information
Johann-S authored and XhmikosR committed Nov 23, 2017
1 parent cdab56d commit e8ba371
Show file tree
Hide file tree
Showing 6 changed files with 1,067 additions and 212 deletions.
19 changes: 13 additions & 6 deletions js/tests/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,19 @@
<title>Bootstrap Plugin Test Suite</title>

<!-- jQuery -->
<script src="../../assets/js/vendor/jquery-slim.min.js"></script>
<script>
(function () {
var path = '../../assets/js/vendor/jquery-slim.min.js'
// get jquery param from the query string.
var jQueryVersion = location.search.match(/[?&]jquery=(.*?)(?=&|$)/)

// If a version was specified, use that version from our vendor folder
if (jQueryVersion) {
path = 'vendor/jquery-' + jQueryVersion[1] + '.min.js'
}
document.write('<script src="' + path + '"><\/script>')
}())
</script>
<script src="../../assets/js/vendor/popper.min.js"></script>

<!-- QUnit -->
Expand Down Expand Up @@ -77,11 +89,6 @@
})
})

// Cleanup
QUnit.testDone(function () {
$('#modal-test, .modal-backdrop').remove()
})

// Display fixture on-screen on iOS to avoid false positives
// See https://github.com/twbs/bootstrap/pull/15955
if (/iPhone|iPad|iPod/.test(navigator.userAgent)) {
Expand Down
55 changes: 55 additions & 0 deletions js/tests/karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* eslint-env node */

'use strict'

module.exports = (config) => {
const jqueryFile = process.env.USE_OLD_JQUERY ? 'js/tests/vendor/jquery-1.9.1.min.js' : 'assets/js/vendor/jquery-slim.min.js'

config.set({
basePath: '../..',
frameworks: ['qunit', 'detectBrowsers'],
plugins: [
'karma-chrome-launcher',
'karma-firefox-launcher',
'karma-qunit',
'karma-detect-browsers'
],
// list of files / patterns to load in the browser
files: [
jqueryFile,
'assets/js/vendor/popper.min.js',
'js/dist/util.js',
'js/dist/tooltip.js',
'js/dist/!(util|index|tooltip).js', // include all of our js/dist files except util.js, index.js and tooltip.js
'js/tests/unit/*.js'
],
reporters: ['dots'],
port: 9876,
colors: true,
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_ERROR || config.LOG_WARN,
autoWatch: false,
customLaunchers: {
FirefoxHeadless: {
base: 'Firefox',
flags: ['-headless']
}
},
singleRun: true,
concurrency: Infinity,
detectBrowsers: {
usePhantomJS: false,
postDetection(availableBrowser) {
if (typeof process.env.TRAVIS_JOB_ID !== 'undefined' || availableBrowser.includes('Chrome')) {
return ['ChromeHeadless']
}

if (availableBrowser.includes('Firefox')) {
return ['FirefoxHeadless']
}

throw new Error('Please install Firefox or Chrome')
}
}
})
}
2 changes: 2 additions & 0 deletions js/tests/unit/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ $(function () {
$.fn.bootstrapModal = $.fn.modal.noConflict()
},
afterEach: function () {
$('.modal-backdrop, #modal-test').remove()
$(document.body).removeClass('modal-open')
$.fn.modal = $.fn.bootstrapModal
delete $.fn.bootstrapModal
}
Expand Down
5 changes: 5 additions & 0 deletions js/tests/vendor/jquery-1.9.1.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit e8ba371

Please sign in to comment.