-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[2.0] Fix loopback in PhantomJS, fix karma tests #344
Conversation
@bajtos you can test what Jenkins will do by using What kind of report is generated by the karma tests? |
@rmg I am always forgetting about |
@@ -80,6 +80,10 @@ function createApplication() { | |||
function mixin(source) { | |||
for (var key in source) { | |||
var desc = Object.getOwnPropertyDescriptor(source, key); | |||
|
|||
// Fix for legacy (pre-ES5) browsers like PhantomJS | |||
if (!desc) continue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this breaking?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK it is not breaking. This check is preventing the following situation:
$ node
> Object.defineProperty({}, 'foo', undefined)
TypeError: Property description must be an object: undefined
at Function.defineProperty (native)
desc
is not defined when the key
is not an own property of the source
. MDN on getOwnPropertyDescriptor:
Return value
A property descriptor of the given property if it exists on the object, undefined otherwise.
What happens in PhantomJS:
for (var key in source)
enumerates overbind
function- the
bind
function is not an own property,getOwnPropertyDescriptor
returns undefined Object.defineProperty
throws when the descriptor is not defined
@bajtos Are we including the es5 shim when not running the tests (eg. when built by browserify)? |
|
test please |
No. Most browsers support ES5 these days, with the exception of Internet Explorer 6-8.
<!--[if lt IE 9]>
<script src="bower_components/es5-shim/es5-shim.js"></script>
<script src="bower_components/json3/lib/json3.min.js"></script>
<![endif]--> Even if this was not the case, including ES5 shim in the browserified bundle would not be a good idea, as it would unnecessarily increase the size of the browser bundle for all browsers. I suppose this matter should be described in the documentation. The docs should mention that loopback depends on ES5 and users should load ES5-shim to run it in a browser that does not implement ES5. /cc @crandmck |
Yes, that's correct. I tried to change the test script to |
Sure.
We should have a guide for using loopback in browsers that includes this. |
@bajtos the Gruntfile could have a top-level test task that runs tests based on the environment. It could check for |
@rmg that sounds plausible, I'll look into it tomorrow. thanks! |
@bajtos it looks like I'll have to make changes to sl-ci-run so that it doesn't assume mocha and bypass |
@slnode test please |
- Move configuration of Karma unit-tests from `Gruntfile.js` to a standalone file (`test/karma.conf.js`). - Add a new Grunt task `karma:unit-ci` to run Karma unit-tests in PhantomJS and produce karma-xunit.xml file that can be consumed by the CI server. - Add grunt-mocha-test, configure it to run unit-tests. - Add `grunt test` task that runs both karma and mocha tests, detects Jenkins to produce XML output on CI server. - Modify the `test` script in `package.json` to run `grunt mocha-and-karma` (an alias for `grunt test`). The alias is required to trick `sl-ci-run` to run `npm test` instead of calling directly `mocha`. - Add `es5-shim` module to karma unit-tests in order to provide ES5-methods required by LoopBack. - Fix `mixin(source)` in lib/loopback.js to work in PhantomJS. `Object.getOwnPropertyDescriptor()` provided by `es5-shim` does not work in the same way as in Node.
|
[2.0] Fix loopback in PhantomJS, fix karma tests
Gruntfile.js
to astandalone file (
test/karma.conf.js
).karma:unit-ci
to run Karma unit-tests inPhantomJS and produce karma-xunit.xml file that can be consumed
by the CI server.
grunt karma:unit-ci
to thetest
script inpackage.json
.es5-shim
module to karma unit-tests in order to provideES5-methods required by LoopBack.
mixin(source)
in lib/loopback.js to work in PhantomJS.Object.getOwnPropertyDescriptor()
provided byes5-shim
does notwork in the same way as in Node.
Requires loopbackio/loopback-datasource-juggler#152
/to @ritch Please review.
/cc @rmg When this patch is landed, loopback is ready to run karma unit-tests on our Jenkins.
npm test
is already running karma via Grunt, is there anything else needed to enable karma tests on Jenkins?