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