refactor: re-organize and "modernize" cjs-jasmine scripts (#19904)

PR Close #19904
This commit is contained in:
George Kalpakas 2018-07-06 09:10:16 +03:00 committed by Miško Hevery
parent c0e2dba07b
commit 19544060d3
2 changed files with 86 additions and 95 deletions

View File

@ -6,14 +6,12 @@
* found in the LICENSE file at https://angular.io/license * found in the LICENSE file at https://angular.io/license
*/ */
/* tslint:disable:no-var-keyword */
'use strict'; 'use strict';
var glob = require('glob'); const glob = require('glob');
require('zone.js/dist/zone-node.js'); require('zone.js/dist/zone-node.js');
var JasmineRunner = require('jasmine'); const JasmineRunner = require('jasmine');
var path = require('path'); const path = require('path');
require('zone.js/dist/long-stack-trace-zone.js'); require('zone.js/dist/long-stack-trace-zone.js');
require('zone.js/dist/task-tracking.js'); require('zone.js/dist/task-tracking.js');
require('zone.js/dist/proxy.js'); require('zone.js/dist/proxy.js');
@ -21,34 +19,34 @@ require('zone.js/dist/sync-test.js');
require('zone.js/dist/async-test.js'); require('zone.js/dist/async-test.js');
require('zone.js/dist/fake-async-test.js'); require('zone.js/dist/fake-async-test.js');
var jrunner = new JasmineRunner(); // Let TypeScript know this is a module
export {};
const jrunner = new JasmineRunner({projectBaseDir: path.resolve(__dirname, '../../')});
(global as any)['jasmine'] = jrunner.jasmine; (global as any)['jasmine'] = jrunner.jasmine;
require('zone.js/dist/jasmine-patch.js'); require('zone.js/dist/jasmine-patch.js');
var rootDir = process.cwd();
function rootDirRequire(moduleId: string) {
return require(path.join(rootDir, moduleId));
}
// Tun on full stack traces in errors to help debugging // Turn on full stack traces in errors to help debugging
(<any>Error)['stackTraceLimit'] = Infinity; (<any>Error)['stackTraceLimit'] = Infinity;
// Support passing multiple globs // Config the test runner
var globsIndex = process.argv.indexOf('--'); jrunner.jasmine.DEFAULT_TIMEOUT_INTERVAL = 100;
var args: string[]; jrunner.loadConfig({
if (globsIndex < 0) { spec_dir: '',
args = [process.argv[2]]; });
} else {
args = process.argv.slice(globsIndex + 1);
}
var specFiles = args.map(function(globstr: string) { return glob.sync(globstr, {cwd: rootDir}); })
.reduce((specFiles: string[], paths: string[]) => specFiles.concat(paths), []);
jasmine.DEFAULT_TIMEOUT_INTERVAL = 100;
jrunner.configureDefaultReporter({showColors: process.argv.indexOf('--no-color') === -1}); jrunner.configureDefaultReporter({showColors: process.argv.indexOf('--no-color') === -1});
jrunner.onComplete((passed: boolean) => process.exit(passed ? 0 : 1));
jrunner.onComplete(function(passed: boolean) { process.exit(passed ? 0 : 1); }); // Support passing multiple globs
jrunner.projectBaseDir = path.resolve(__dirname, '../../'); const rootDir = process.cwd();
jrunner.specDir = ''; const globsIndex = process.argv.indexOf('--');
specFiles.forEach((file: string) => { rootDirRequire(file); }); const globs = (globsIndex === -1) ? [process.argv[2]] : process.argv.slice(globsIndex + 1);
const specFiles = globs.map(globstr => glob.sync(globstr, {cwd: rootDir}) as string[])
.reduce((allPaths, paths) => allPaths.concat(paths), []);
// Load helpers and spec files
const rootDirRequire = (relativePath: string) => require(path.join(rootDir, relativePath));
specFiles.forEach(rootDirRequire);
// Run the tests
jrunner.execute(); jrunner.execute();

View File

@ -6,14 +6,12 @@
* found in the LICENSE file at https://angular.io/license * found in the LICENSE file at https://angular.io/license
*/ */
/* tslint:disable:no-var-keyword */
'use strict'; 'use strict';
var glob = require('glob'); const glob = require('glob');
require('zone.js/dist/zone-node.js'); require('zone.js/dist/zone-node.js');
var JasmineRunner = require('jasmine'); const JasmineRunner = require('jasmine');
var path = require('path'); const path = require('path');
require('source-map-support').install(); require('source-map-support').install();
require('zone.js/dist/long-stack-trace-zone.js'); require('zone.js/dist/long-stack-trace-zone.js');
require('zone.js/dist/task-tracking.js'); require('zone.js/dist/task-tracking.js');
@ -22,83 +20,78 @@ require('zone.js/dist/sync-test.js');
require('zone.js/dist/async-test.js'); require('zone.js/dist/async-test.js');
require('zone.js/dist/fake-async-test.js'); require('zone.js/dist/fake-async-test.js');
require('reflect-metadata/Reflect'); require('reflect-metadata/Reflect');
var jrunner = new JasmineRunner();
// Let TypeScript know this is a module
export {};
const jrunner = new JasmineRunner({projectBaseDir: path.resolve(__dirname, '../../')});
(global as any)['jasmine'] = jrunner.jasmine; (global as any)['jasmine'] = jrunner.jasmine;
require('zone.js/dist/jasmine-patch.js'); require('zone.js/dist/jasmine-patch.js');
var distAll: string = process.cwd() + '/dist/all'; (global as any).isBrowser = false;
function distAllRequire(moduleId: string) { (global as any).isNode = true;
return require(path.join(distAll, moduleId));
}
// Turn on full stack traces in errors to help debugging
// Tun on full stack traces in errors to help debugging
(<any>Error)['stackTraceLimit'] = Infinity; (<any>Error)['stackTraceLimit'] = Infinity;
// Config the test runner
jrunner.jasmine.DEFAULT_TIMEOUT_INTERVAL = 100; jrunner.jasmine.DEFAULT_TIMEOUT_INTERVAL = 100;
jrunner.loadConfig({
spec_dir: '',
});
jrunner.configureDefaultReporter({showColors: process.argv.indexOf('--no-color') === -1});
jrunner.onComplete((passed: boolean) => process.exit(passed ? 0 : 1));
// Support passing multiple globs // Support passing multiple globs
var globsIndex = process.argv.indexOf('--'); const distAll = process.cwd() + '/dist/all';
var args: string[]; const globsIndex = process.argv.indexOf('--');
if (globsIndex < 0) { const globs = (globsIndex === -1) ? [process.argv[2]] : process.argv.slice(globsIndex + 1);
args = [process.argv[2]]; const specFiles =
} else { globs
args = process.argv.slice(globsIndex + 1); .map(globstr => glob.sync(globstr, {
} cwd: distAll,
ignore: [
(global as any).isNode = true; // the following code and tests are not compatible with CJS/node environment
(global as any).isBrowser = false; '@angular/_testing_init/**',
'@angular/compiler/test/aot/**',
var specFiles: any = '@angular/compiler/test/render3/**',
args.map(function(globstr: string): '@angular/core/test/bundling/**',
string[] { '@angular/core/test/fake_async_spec.*',
return glob.sync(globstr, { '@angular/core/test/render3/**',
cwd: distAll, '@angular/core/test/zone/**',
ignore: [ '@angular/elements/**',
// the following code and tests are not compatible with CJS/node environment '@angular/examples/**',
'@angular/_testing_init/**', '@angular/forms/test/**',
'@angular/examples/**', '@angular/integration_test/symbol_inspector/**',
'@angular/platform-browser/**', '@angular/platform-browser/**',
'@angular/platform-browser-dynamic/**', '@angular/platform-browser-dynamic/**',
'@angular/compiler/test/aot/**', '@angular/router/test/integration/bootstrap_spec.*',
'@angular/compiler/test/render3/**', '@angular/router/test/route_config/route_config_spec.*',
'@angular/core/test/bundling/**', '@angular/upgrade/**',
'@angular/core/test/zone/**', '@angular/**/e2e_test/**',
'@angular/core/test/render3/**', 'angular1_router/**',
'@angular/core/test/fake_async_spec.*', 'payload_tests/**',
'@angular/forms/test/**', ],
'@angular/router/test/route_config/route_config_spec.*', }) as string[])
'@angular/router/test/integration/bootstrap_spec.*',
'@angular/integration_test/symbol_inspector/**',
'@angular/upgrade/**',
'@angular/elements/**',
'@angular/**/e2e_test/**',
'angular1_router/**',
'payload_tests/**',
]
});
})
// Run relevant subset of browser tests for features reused on the server side. // Run relevant subset of browser tests for features reused on the server side.
// Make sure the security spec works on the server side! // Make sure the security spec works on the server side!
.concat(glob.sync('@angular/platform-browser/test/security/**/*_spec.js', {cwd: distAll})) .concat(glob.sync('@angular/platform-browser/test/security/**/*_spec.js', {cwd: distAll}))
.concat(['/@angular/platform-browser/test/browser/meta_spec.js']) .concat(['/@angular/platform-browser/test/browser/meta_spec.js'])
.concat(['/@angular/platform-browser/test/browser/title_spec.js']) .concat(['/@angular/platform-browser/test/browser/title_spec.js'])
.concat(['/@angular/platform-browser/test/browser/transfer_state_spec.js']) .concat(['/@angular/platform-browser/test/browser/transfer_state_spec.js'])
.reduce((specFiles: string[], paths: string[]) => specFiles.concat(paths), <string[]>[]); .reduce((allPaths, paths) => allPaths.concat(paths), []);
jasmine.DEFAULT_TIMEOUT_INTERVAL = 100; // Load helpers and spec files
const distAllRequire = (relativePath: string) => {
jrunner.configureDefaultReporter({showColors: process.argv.indexOf('--no-color') === -1}); const mod = require(path.join(distAll, relativePath));
if (mod.main) {
jrunner.onComplete(function(passed: boolean) { process.exit(passed ? 0 : 1); }); mod.main();
jrunner.projectBaseDir = path.resolve(__dirname, '../../');
jrunner.specDir = '';
require('./test-cjs-main.js');
distAllRequire('@angular/platform-server/src/domino_adapter.js').DominoAdapter.makeCurrent();
specFiles.forEach((file: string) => {
const r = distAllRequire(file);
if (r.main) {
r.main();
} }
}); return mod;
};
require('./test-cjs-main');
distAllRequire('@angular/platform-server/src/domino_adapter').DominoAdapter.makeCurrent();
specFiles.forEach(distAllRequire);
// Run the tests
jrunner.execute(); jrunner.execute();