|
| 1 | +/** |
| 2 | + * @author: @AngularClass |
| 3 | + */ |
| 4 | + |
| 5 | +/* |
| 6 | + * When testing with webpack and ES6, we have to do some extra |
| 7 | + * things to get testing to work right. Because we are gonna write tests |
| 8 | + * in ES6 too, we have to compile those as well. That's handled in |
| 9 | + * karma.conf.js with the karma-webpack plugin. This is the entry |
| 10 | + * file for webpack test. Just like webpack will create a bundle.js |
| 11 | + * file for our client, when we run test, it will compile and bundle them |
| 12 | + * all here! Crazy huh. So we need to do some setup |
| 13 | + */ |
| 14 | +Error.stackTraceLimit = Infinity; |
| 15 | + |
| 16 | +require('core-js/es6'); |
| 17 | +require('core-js/es7/reflect'); |
| 18 | + |
| 19 | +// Typescript emit helpers polyfill |
| 20 | +require('ts-helpers'); |
| 21 | + |
| 22 | +require('zone.js/dist/zone'); |
| 23 | +require('zone.js/dist/long-stack-trace-zone'); |
| 24 | +require('zone.js/dist/proxy'); // since zone.js 0.6.15 |
| 25 | +require('zone.js/dist/sync-test'); |
| 26 | +require('zone.js/dist/jasmine-patch'); // put here since zone.js 0.6.14 |
| 27 | +require('zone.js/dist/async-test'); |
| 28 | +require('zone.js/dist/fake-async-test'); |
| 29 | + |
| 30 | +// RxJS |
| 31 | +require('rxjs/Rx'); |
| 32 | + |
| 33 | +var testing = require('@angular/core/testing'); |
| 34 | +var browser = require('@angular/platform-browser-dynamic/testing'); |
| 35 | + |
| 36 | +testing.TestBed.initTestEnvironment( |
| 37 | + browser.BrowserDynamicTestingModule, |
| 38 | + browser.platformBrowserDynamicTesting() |
| 39 | +); |
| 40 | + |
| 41 | +/* |
| 42 | + * Ok, this is kinda crazy. We can use the context method on |
| 43 | + * require that webpack created in order to tell webpack |
| 44 | + * what files we actually want to require or import. |
| 45 | + * Below, context will be a function/object with file names as keys. |
| 46 | + * Using that regex we are saying look in ../src then find |
| 47 | + * any file that ends with spec.ts and get its path. By passing in true |
| 48 | + * we say do this recursively |
| 49 | + */ |
| 50 | +var testContext = require.context('../src', true, /\.spec\.ts/); |
| 51 | + |
| 52 | +/* |
| 53 | + * get all the files, for each file, call the context function |
| 54 | + * that will require the file and load it up here. Context will |
| 55 | + * loop and require those spec files here |
| 56 | + */ |
| 57 | +function requireAll(requireContext) { |
| 58 | + return requireContext.keys().map(requireContext); |
| 59 | +} |
| 60 | + |
| 61 | +// requires and returns all modules that match |
| 62 | +var modules = requireAll(testContext); |
0 commit comments