UNPKG

2.07 kBJavaScriptView Raw
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 */
10Error.stackTraceLimit = Infinity;
11
12require('core-js/es6');
13require('core-js/es7/reflect');
14
15// Typescript emit helpers polyfill
16require('ts-helpers');
17
18require('zone.js/dist/zone');
19require('zone.js/dist/long-stack-trace-zone');
20require('zone.js/dist/async-test');
21require('zone.js/dist/fake-async-test');
22require('zone.js/dist/sync-test');
23require('zone.js/dist/proxy'); // since zone.js 0.6.15
24require('zone.js/dist/jasmine-patch'); // put here since zone.js 0.6.14
25
26// RxJS
27require('rxjs/Rx');
28
29var testing = require('@angular/core/testing');
30var browser = require('@angular/platform-browser-dynamic/testing');
31
32testing.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 */
46var testContext = require.context('../src', true, /\.spec\.ts/);
47console.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 */
54function requireAll(requireContext) {
55 return requireContext.keys().map(requireContext);
56}
57
58// requires and returns all modules that match
59var modules = requireAll(testContext);