Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit 5defa04

Browse files
fix(tests): performance improvements and fixes to jasmine testing
Refactor internal test utils to angular-material-spec.js Publish material mocks `angular-material-mocks.js` to work with angular-mocks.js for 3rd party unit testing. Removed module wrappers around all components - now only has a single module wrapper protecting all the angular material code Replaced use of `Function.bind( )` with `angular.bind()` Fixed tests runs with uncompiled source **or** compiled, deployed `angular-material.js` Use angular-material-mocks.js to decorate $$rAF.throttle(), force $mdAria.expectWithText() to be synchronous, and disable the generation of Theme CSS rules. Major testing speed improvements by disabling Theme CSS generation. Theme improvements: test existence of Theme CSS rule before regenerating. Now works with Safari, Firefox, PhantomJS, and Chrome browser testing.
1 parent dcb12a7 commit 5defa04

31 files changed

+382
-324
lines changed

config/karma.conf.js

Lines changed: 57 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,59 @@
11

22
module.exports = function(config) {
3-
3+
44
var UNCOMPILED_SRC = [
5-
'config/test-utils.js',
6-
'src/core/**/*.js',
7-
8-
// Test utilities, source, and specifications.
9-
// We are explicit like this because we don't want to put
10-
// demos in the tests, and Karma doesn't support advanced
11-
// globbing.
12-
'src/components/*/*.js',
13-
'src/components/*/js/*.js'
5+
6+
// To enabled use of `gulp karma-watch`,
7+
// don't use the dist/angular-material.js
8+
//
9+
//'dist/angular-material.js', // Un-minified source
10+
11+
12+
// Test utilities, source, and specifications.
13+
// We are explicit like this because we don't want to put
14+
// demos in the tests, and Karma doesn't support advanced
15+
// globbing.
16+
17+
'src/core/**/*.js',
18+
'src/components/*/*.js',
19+
'src/components/*/js/*.js',
20+
21+
'src/**/*.spec.js'
22+
1423
];
1524

1625
var COMPILED_SRC = [
17-
// Minified source
18-
'dist/angular-material.min.js',
19-
20-
// Test utilties and specifications
21-
'config/test-utils.js',
26+
'dist/angular-material.min.js', // Minified source
2227
'src/**/*.spec.js'
2328
];
24-
25-
// releaseMode is a custom configuration option.
26-
var testSrc = process.env.KARMA_TEST_COMPRESSED ? COMPILED_SRC : UNCOMPILED_SRC;
27-
var dependencies = process.env.KARMA_TEST_JQUERY ?
28-
['node_modules/jquery/dist/jquery.js'] : [];
2929

30-
dependencies = dependencies.concat([
31-
'node_modules/angular/angular.js',
32-
'node_modules/angular-animate/angular-animate.js',
33-
'node_modules/angular-aria/angular-aria.js',
34-
'node_modules/angular-mocks/angular-mocks.js',
35-
'config/test-utils.js'
36-
]);
30+
var dependencies = process.env.KARMA_TEST_JQUERY ? ['node_modules/jquery/dist/jquery.js'] : [];
31+
dependencies = dependencies.concat([
32+
'node_modules/angular/angular.js',
33+
'node_modules/angular-animate/angular-animate.js',
34+
'node_modules/angular-aria/angular-aria.js',
35+
'node_modules/angular-mocks/angular-mocks.js',
36+
'src/spec/angular-material-mocks.js',
37+
'src/spec/angular-material-spec.js'
38+
]);
39+
40+
var testSrc = process.env.KARMA_TEST_COMPRESSED ? COMPILED_SRC : UNCOMPILED_SRC;
3741

3842
config.set({
3943

4044
basePath: __dirname + '/..',
4145
frameworks: ['jasmine'],
4246
files: dependencies.concat(testSrc),
4347

48+
logLevel:'warn',
4449
port: 9876,
4550
reporters: ['progress'],
4651
colors: true,
4752

4853
// Continuous Integration mode
4954
// enable / disable watching file and executing tests whenever any file changes
5055
autoWatch: false,
51-
singleRun: false,
56+
singleRun: true,
5257

5358
// Start these browsers, currently available:
5459
// - Chrome
@@ -58,7 +63,30 @@ module.exports = function(config) {
5863
// - Safari (only Mac; has to be installed with `npm install karma-safari-launcher`)
5964
// - PhantomJS
6065
// - IE (only Windows; has to be installed with `npm install karma-ie-launcher`)
61-
browsers: ['Chrome']
66+
browsers: ['Chrome'],
67+
68+
// you can define custom flags
69+
customLaunchers: {
70+
Chrome_without_security: {
71+
base: 'Chrome',
72+
flags: ['--disable-web-security']
73+
},
74+
PhantomJS_without_security: {
75+
base: 'PhantomJS',
76+
options : {
77+
onResourceRequested : function (request) {
78+
console.log('Request ' + JSON.stringify(request, undefined, 4));
79+
},
80+
onError : function (msg, trace) {
81+
console.log(msg);
82+
trace.forEach(function(item) {
83+
console.log(' ', item.file, ':', item.line);
84+
});
85+
}
86+
},
87+
flags: ['--web-security=no', '--proxy-type=none', '--remote-debugger-port=9000', '--remote-debugger-autorun=yes']
88+
}
89+
}
6290
});
6391

6492
};

config/test-utils.js

Lines changed: 0 additions & 157 deletions
This file was deleted.

gulp/config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ module.exports = {
77
' * v' + VERSION + '\n' +
88
' */\n',
99
jsBaseFiles: [
10-
'src/core/**/*.js',
11-
'!src/core/**/*.spec.js'
10+
'src/core/**/*.js'
1211
],
1312
jsFiles: [
14-
'src/**/*.js'
13+
'src/**/*.js',
14+
'!src/**/*.spec.js'
1515
],
1616
themeBaseFiles: [
1717
'src/core/style/variables.scss',

gulpfile.js

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,40 +8,40 @@ if (IS_RELEASE_BUILD) {
88
require('./docs/gulpfile')(gulp, IS_RELEASE_BUILD);
99

1010
gulp.task('build-all-modules', function() {
11-
return series(gulp.src(['src/components/*', 'src/core/'])
12-
.pipe(through2.obj(function(folder, enc, next) {
13-
var moduleId = folder.path.indexOf('components') > -1
14-
? 'material.components.' + path.basename(folder.path)
15-
: 'material.' + path.basename(folder.path);
16-
var stream = (IS_RELEASE_BUILD && BUILD_MODE.useBower)
17-
? series(buildModule(moduleId, true), buildModule(moduleId, false))
18-
: buildModule(moduleId, false);
19-
stream.on('end', function() { next(); });
20-
})),
21-
themeBuildStream()
22-
.pipe(BUILD_MODE.transform())
23-
.pipe(gulp.dest(path.join(BUILD_MODE.outputDir, 'core')))
24-
);
11+
return series(
12+
gulp.src(['src/core/', 'src/components/*' ])
13+
.pipe(through2.obj(function(folder, enc, next) {
14+
var moduleId = folder.path.indexOf('components') > -1
15+
? 'material.components.' + path.basename(folder.path)
16+
: 'material.' + path.basename(folder.path);
17+
var stream = (IS_RELEASE_BUILD && BUILD_MODE.useBower)
18+
? series(buildModule(moduleId, true), buildModule(moduleId, false))
19+
: buildModule(moduleId, false);
20+
stream.on('end', function() { next(); });
21+
})),
22+
themeBuildStream()
23+
.pipe(gulp.dest(path.join(BUILD_MODE.outputDir, 'core'))
24+
)).pipe(BUILD_MODE.transform());
2525
});
2626

2727
function buildModule(module, isRelease) {
2828
if ( module.indexOf(".") < 0) {
2929
module = "material.components." + module;
3030
}
31-
32-
var name = module.split('.').pop();
3331
gutil.log('Building ' + module + (isRelease && ' minified' || '') + ' ...');
3432

33+
var name = module.split('.').pop();
3534
utils.copyDemoAssets(name, 'src/components/', 'dist/demos/');
3635

37-
return utils.filesForModule(module)
38-
.pipe(filterNonCodeFiles())
39-
.pipe(gulpif('*.scss', buildModuleStyles(name)))
40-
.pipe(gulpif('*.js', buildModuleJs(name)))
41-
.pipe(BUILD_MODE.transform())
42-
.pipe(insert.prepend(config.banner))
43-
.pipe(gulpif(isRelease, buildMin()))
44-
.pipe(gulp.dest(BUILD_MODE.outputDir + name));
36+
var stream = utils.filesForModule(module)
37+
.pipe(filterNonCodeFiles())
38+
.pipe(gulpif('*.scss', buildModuleStyles(name)))
39+
.pipe(gulpif('*.js', buildModuleJs(name)))
40+
.pipe(insert.prepend(config.banner))
41+
.pipe(gulpif(isRelease, buildMin()))
42+
.pipe(gulp.dest(BUILD_MODE.outputDir + name));
43+
44+
return stream;
4545

4646

4747
function buildMin() {
@@ -175,6 +175,7 @@ global.buildJs = function buildJs(isRelease) {
175175
return series(jsBuildStream, themeBuildStream())
176176
.pipe(concat('angular-material.js'))
177177
.pipe(insert.prepend(config.banner))
178+
.pipe(BUILD_MODE.transform())
178179
.pipe(gulp.dest(config.outputDir))
179180
.pipe(gulpif(isRelease, lazypipe()
180181
.pipe(uglify, { preserveComments: 'some' })

scripts/gulp-utils.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ exports.readModuleDemos = function(moduleName, fileTasks) {
8484
name: path.basename(file.path),
8585
label: path.basename(file.path),
8686
fileType: path.extname(file.path).substring(1),
87-
outputPath: 'demo-partials/' + name + '/' + path.basename(demoFolder.path) + '/' + path.basename(file.path),
87+
outputPath: 'demo-partials/' + name + '/' + path.basename(demoFolder.path) + '/' + path.basename(file.path)
8888
};
8989
}
9090
}));
@@ -259,9 +259,8 @@ exports.hoistScssVariables = function() {
259259
exports.cssToNgConstant = function(ngModule, factoryName) {
260260
return through2.obj(function(file, enc, next) {
261261

262-
var template = '(function(){ \n angular.module("%1").constant("%2", "%3"); \n})();';
263-
var output = file.contents.toString().replace(/\n/g, '')
264-
.replace(/\"/,'\\"');
262+
var template = 'angular.module("%1").constant("%2", "%3"); \n';
263+
var output = file.contents.toString().replace(/\n/g, '').replace(/\"/,'\\"');
265264

266265
var jsFile = new gutil.File({
267266
base: file.base,

src/components/chips/contact-chips.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ describe('<md-contact-chips>', function() {
6060
});
6161

6262
var matches = autocompleteCtrl.matches;
63-
expect(matches.length).toBe(2);
63+
expect(matches.length).toBe(3);
6464
}));
6565

6666
/* it('should not filter when disabled', inject(function($timeout) {

0 commit comments

Comments
 (0)