2019-12-16 10:02:29 -05:00
|
|
|
/* global chai */
|
|
|
|
|
|
|
|
// Allow for mocking of Angular
|
|
|
|
import 'angular'
|
|
|
|
import 'angular-mocks'
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add chai assertion for comparing CodeMirror Pos objects.
|
|
|
|
* A deep comparison will fail because CodeMirror inserts additional properties
|
|
|
|
* that we want to ignore.
|
|
|
|
*/
|
2021-04-14 09:17:21 -04:00
|
|
|
chai.Assertion.addMethod('equalPos', function (expectedPos) {
|
2019-12-16 10:02:29 -05:00
|
|
|
const { line: actualLine, ch: actualCh } = this._obj
|
|
|
|
const { line: expectedLine, ch: expectedCh } = expectedPos
|
|
|
|
|
|
|
|
this.assert(
|
|
|
|
actualLine === expectedLine && actualCh === expectedCh,
|
|
|
|
`expected #{exp} to equal #{act}`,
|
|
|
|
`expected #{exp} to not equal #{act}`,
|
|
|
|
`Pos({ line: ${expectedLine}, ch: ${expectedCh} })`,
|
|
|
|
`Pos({ line: ${actualLine}, ch: ${actualCh} })`
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
// Mock ExposedSettings
|
|
|
|
window.ExposedSettings = {}
|
|
|
|
|
2019-10-16 06:10:54 -04:00
|
|
|
/*
|
|
|
|
* Bundle all test files together into a single bundle, and run tests against
|
|
|
|
* this single bundle.
|
|
|
|
* We are using karma-webpack to bundle our tests and the 'default' strategy is
|
|
|
|
* to create a bundle for each test file. This isolates the tests better, but
|
|
|
|
* causes a problem with Angular. The issue with Angular tests is because we
|
|
|
|
* load a single global copy of Angular (see karma.conf.js) but
|
2019-11-05 09:00:13 -05:00
|
|
|
* frontend/js/base.js is included in each bundle, meaning the Angular app is
|
2019-10-16 06:10:54 -04:00
|
|
|
* initialised for each bundle when it is loaded onto the page when Karma
|
|
|
|
* starts. This means that only the last bundle will have controllers/directives
|
|
|
|
* registered against it, ultimately meaning that all other bundles will fail
|
|
|
|
* because Angular cannot find the controller/directive under test.
|
|
|
|
*/
|
|
|
|
|
2020-07-09 09:56:33 -04:00
|
|
|
// Import from the top-level any JS files within a test/karma
|
2019-10-16 06:10:54 -04:00
|
|
|
// directory
|
2020-07-09 09:56:33 -04:00
|
|
|
const context = require.context('../../', true, /test\/karma\/.*\.js$/)
|
2019-10-16 06:10:54 -04:00
|
|
|
context.keys().forEach(context)
|