import_tests.js 998 B

12345678910111213141516171819202122
  1. /*
  2. * Bundle all test files together into a single bundle, and run tests against
  3. * this single bundle.
  4. * We are using karma-webpack to bundle our tests and the 'default' strategy is
  5. * to create a bundle for each test file. This isolates the tests better, but
  6. * causes a problem with Angular. The issue with Angular tests is because we
  7. * load a single global copy of Angular (see karma.conf.js) but
  8. * public/src/base.js is included in each bundle, meaning the Angular app is
  9. * initialised for each bundle when it is loaded onto the page when Karma
  10. * starts. This means that only the last bundle will have controllers/directives
  11. * registered against it, ultimately meaning that all other bundles will fail
  12. * because Angular cannot find the controller/directive under test.
  13. */
  14. // Import from the top-level any JS files within a test/unit_frontend/src
  15. // directory
  16. const context = require.context(
  17. '../../',
  18. true,
  19. /test\/unit_frontend\/src\/.*\.js$/
  20. )
  21. context.keys().forEach(context)