perf(aio): improve unit test rebuild time

This commit is contained in:
Filipe Silva 2017-04-21 20:20:02 +01:00 committed by Pete Bacon Darwin
parent 54e587a46d
commit d7719aa0f5
4 changed files with 29 additions and 7 deletions

View File

@ -10,7 +10,7 @@
"start": "yarn check-env && ng serve", "start": "yarn check-env && ng serve",
"build": "yarn check-env && yarn setup && ng build -prod -sm", "build": "yarn check-env && yarn setup && ng build -prod -sm",
"lint": "yarn check-env && yarn docs-lint && ng lint", "lint": "yarn check-env && yarn docs-lint && ng lint",
"test": "yarn check-env && ng test --sourcemap=false", "test": "yarn check-env && ng test",
"pree2e": "yarn ~~update-webdriver", "pree2e": "yarn ~~update-webdriver",
"e2e": "yarn check-env && ng e2e --no-webdriver-update", "e2e": "yarn check-env && ng e2e --no-webdriver-update",
"setup": "yarn && yarn boilerplate:add && yarn docs && yarn generate-plunkers && yarn generate-zips", "setup": "yarn && yarn boilerplate:add && yarn docs && yarn generate-plunkers && yarn generate-zips",

4
aio/src/test-specs.ts Normal file
View File

@ -0,0 +1,4 @@
// Find all the tests.
const context = (<any>require).context('./', true, /\.spec\.ts$/);
// And load the modules.
context.keys().map(context);

View File

@ -1,5 +1,6 @@
// This file is required by karma.conf.js and loads recursively all the .spec and framework files // This file is required by karma.conf.js and loads recursively all the .spec and framework files
// Test dependencies.
import 'zone.js/dist/long-stack-trace-zone'; import 'zone.js/dist/long-stack-trace-zone';
import 'zone.js/dist/proxy.js'; import 'zone.js/dist/proxy.js';
import 'zone.js/dist/sync-test'; import 'zone.js/dist/sync-test';
@ -12,9 +13,25 @@ import {
platformBrowserDynamicTesting platformBrowserDynamicTesting
} from '@angular/platform-browser-dynamic/testing'; } from '@angular/platform-browser-dynamic/testing';
// List vendors here to increase test rebuild performance.
import '@angular/common';
import '@angular/common/testing';
import '@angular/core/';
import '@angular/core/testing';
import '@angular/platform-browser';
import '@angular/platform-browser/testing';
import '@angular/platform-browser/animations';
import '@angular/platform-browser-dynamic';
import '@angular/platform-browser-dynamic/testing';
import '@angular/http';
import '@angular/http/testing';
import '@angular/animations';
import '@angular/material';
import '@angular/service-worker';
import 'rxjs'; // tslint:disable-line
// Unfortunately there's no typing for the `__karma__` variable. Just declare it as any. // Unfortunately there's no typing for the `__karma__` variable. Just declare it as any.
declare var __karma__: any; declare var __karma__: any;
declare var require: any;
// Prevent Karma from running prematurely. // Prevent Karma from running prematurely.
__karma__.loaded = function () {}; __karma__.loaded = function () {};
@ -24,9 +41,9 @@ getTestBed().initTestEnvironment(
BrowserDynamicTestingModule, BrowserDynamicTestingModule,
platformBrowserDynamicTesting() platformBrowserDynamicTesting()
); );
declare var System: any;
// Then we find all the tests. // Then we find all the tests.
const context = require.context('./', true, /\.spec\.ts$/); System.import('./test-specs.ts')
// And load the modules. // Finally, start Karma to run the tests.
context.keys().map(context); .then(() => __karma__.start());
// Finally, start Karma to run the tests.
__karma__.start();

View File

@ -9,6 +9,7 @@
"exclude": [ "exclude": [
"testing/**/*", "testing/**/*",
"test.ts", "test.ts",
"test-specs.ts",
"**/*.spec.ts" "**/*.spec.ts"
] ]
} }