This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 407
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(test): unify mocha/jasmine test
- Loading branch information
1 parent
1ba8519
commit e60bdde
Showing
27 changed files
with
2,636 additions
and
471 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,8 @@ script: | |
- node ./test/webdriver/test.sauce.js | ||
- yarn add [email protected] [email protected] [email protected] | ||
- yarn test:phantomjs-single | ||
- yarn test-mocha-jasmine-bridge-node | ||
- yarn test-mocha-jasmine-bridge-browser | ||
- node_modules/.bin/karma start karma-dist-sauce-jasmine3.conf.js --single-run | ||
- node_modules/.bin/karma start karma-build-sauce-selenium3-mocha.conf.js --single-run | ||
- node_modules/.bin/gulp test/node | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
|
||
module.exports = function(config) { | ||
require('./karma-base.conf.js')(config); | ||
config.files.push('build/test/mocha/mocha-browser-karma.js'); | ||
config.files.push('build/test/wtf_mock.js'); | ||
config.files.push('build/test/test_fake_polyfill.js'); | ||
config.files.push('build/lib/zone.js'); | ||
config.files.push('build/lib/common/promise.js'); | ||
config.files.push('build/lib/common/error-rewrite.js'); | ||
config.files.push('build/test/main.js'); | ||
|
||
config.plugins.push(require('karma-mocha')); | ||
config.frameworks.push('mocha'); | ||
config.client.mocha = { | ||
timeout: 5000 // copied timeout for Jasmine in WebSocket.spec (otherwise Mochas default timeout | ||
// at 2 sec is to low for the tests) | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* @license | ||
* Copyright Google Inc. All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
// need to patch jasmine.clock().mockDate and jasmine.clock().tick() so | ||
// they can work properly in FakeAsyncTest | ||
export function patchJasmineClock(jasmine: any, enableClockPatch: boolean) { | ||
const symbol = Zone.__symbol__; | ||
const originalClockFn: Function = ((jasmine as any)[symbol('clock')] = jasmine['clock']); | ||
(jasmine as any)['clock'] = function() { | ||
const clock = originalClockFn.apply(this, arguments); | ||
if (!clock[symbol('patched')]) { | ||
clock[symbol('patched')] = symbol('patched'); | ||
const originalTick = (clock[symbol('tick')] = clock.tick); | ||
clock.tick = function() { | ||
const fakeAsyncZoneSpec = Zone.current.get('FakeAsyncTestZoneSpec'); | ||
if (fakeAsyncZoneSpec) { | ||
return fakeAsyncZoneSpec.tick.apply(fakeAsyncZoneSpec, arguments); | ||
} | ||
return originalTick.apply(this, arguments); | ||
}; | ||
const originalMockDate = (clock[symbol('mockDate')] = clock.mockDate); | ||
clock.mockDate = function() { | ||
const fakeAsyncZoneSpec = Zone.current.get('FakeAsyncTestZoneSpec'); | ||
if (fakeAsyncZoneSpec) { | ||
const dateTime = arguments.length > 0 ? arguments[0] : new Date(); | ||
return fakeAsyncZoneSpec.setCurrentRealTime.apply( | ||
fakeAsyncZoneSpec, | ||
dateTime && typeof dateTime.getTime === 'function' ? [dateTime.getTime()] : | ||
arguments); | ||
} | ||
return originalMockDate.apply(this, arguments); | ||
}; | ||
// for auto go into fakeAsync feature, we need the flag to enable it | ||
if (enableClockPatch) { | ||
['install', 'uninstall'].forEach(methodName => { | ||
const originalClockFn: Function = (clock[symbol(methodName)] = clock[methodName]); | ||
clock[methodName] = function() { | ||
const FakeAsyncTestZoneSpec = (Zone as any)['FakeAsyncTestZoneSpec']; | ||
if (FakeAsyncTestZoneSpec) { | ||
(jasmine as any)[symbol('clockInstalled')] = 'install' === methodName; | ||
return; | ||
} | ||
return originalClockFn.apply(this, arguments); | ||
}; | ||
}); | ||
} | ||
} | ||
return clock; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** | ||
* @license | ||
* Copyright Google Inc. All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import './jasmine'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* @license | ||
* Copyright Google Inc. All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
export function mappingBDD(jasmine: any, Mocha: any, global: any) { | ||
const mappings: {jasmine: string, Mocha: string}[] = [ | ||
{jasmine: 'beforeAll', Mocha: 'before'}, {jasmine: 'afterAll', Mocha: 'after'}, | ||
{jasmine: 'xdescribe', Mocha: 'describe.skip'}, {jasmine: 'fdescribe', Mocha: 'describe.only'}, | ||
{jasmine: 'xit', Mocha: 'it.skip'}, {jasmine: 'fit', Mocha: 'it.only'} | ||
]; | ||
mappings.forEach(map => { | ||
if (!global[map.jasmine]) { | ||
const mocha = map.Mocha; | ||
const chains = mocha.split('.'); | ||
let mochaMethod: any = null; | ||
for (let i = 0; i < chains.length; i++) { | ||
mochaMethod = mochaMethod ? mochaMethod[chains[i]] : Mocha[chains[i]]; | ||
} | ||
global[map.jasmine] = jasmine[map.jasmine] = function() { | ||
const args = Array.prototype.slice.call(arguments); | ||
if (args.length > 0 && typeof args[args.length - 1] === 'number') { | ||
// get a timeout | ||
const timeout = args[args.length - 1]; | ||
if (this && typeof this.timeout === 'function') { | ||
this.timeout(timeout); | ||
} | ||
} | ||
return mochaMethod.apply(this, args); | ||
}; | ||
} | ||
}); | ||
|
||
if (!global['pending']) { | ||
global['pending'] = function() { | ||
const ctx = Mocha.__zone_symbol__current_ctx; | ||
if (ctx && typeof ctx.skip === 'function') { | ||
ctx.skip(); | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* @license | ||
* Copyright Google Inc. All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
import {patchJasmineClock} from '../../jasmine/jasmine.clock'; | ||
export function addJasmineClock(jasmine: any) { | ||
jasmine.clock = function() { | ||
return { | ||
tick: function() {}, | ||
install: function() {}, | ||
uninstall: function() {}, | ||
mockDate: function() {} | ||
}; | ||
}; | ||
patchJasmineClock(jasmine, true); | ||
} |
Oops, something went wrong.