bclinkinbeard / angular Goto Github PK
View Code? Open in Web Editor NEWAngularJS compiled with jsdom and provided as a CommonJS module. Intended for testing AngularJS code without depending on a browser.
License: MIT License
AngularJS compiled with jsdom and provided as a CommonJS module. Intended for testing AngularJS code without depending on a browser.
License: MIT License
JSDom has major issues compiling to the various platforms (e.g. See the bottom several paragraphs on their npm page detailing how to ensure it builds). The root cause of this is its "contextify" dependency which natively sandboxes the runtime. As useful as that sounds I'm skeptical its truly necessary for most use cases, especially given the many hoops one must jump through to get JSDom to build. On my machine I STILL can't get it working 5 gbs of downloads later. Am I crazy to think this is an unacceptably high hurdle for the majority of developers simple wanting to require Angular from NPM rather than bower?
So an alternative solution to JSDom is the Cheerio library. This module is compatible with all major platforms out of the box, is actually MORE popular than JSDom judging from download numbers, is faster than JSDom, and comes out of the box with its own port of the the jQuery selector library.
I recognize this may NOT be possible if Angular is super strict on the browser like environment it demands. But it would be worth looking into. Any thoughts?
Should I use var angular = require('angular/index-browserify')
or var angular = require('angular')
when using it with browserify?
This is not so clear in the documentation ...
Thanks for clarification!
I tried to point index.js
to use the unminified version of Angular and got the following error.
For both 2.15 and 2.16 the minified version worked but the unminified didn't.
> require('angular')
ReferenceError: angular is not defined
at eval (eval at <anonymous> (F:\Tom\Code\tepez\common\node_modules\angular\index.js:14:3), <anonymous>:21465:28)
at module.exports (F:\Tom\Code\tepez\common\node_modules\angular\index.js:14:43)
at Object.<anonymous> (F:\Tom\Code\tepez\common\node_modules\angular\index.js:15:3)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at repl:1:2
Thanks for this great module! I use it to get angular's $parse
and $interpolate
and on the server.
I'm trying to test an angular app with mocha, from the docs it seems that this should work
var angular = require('angular');
describe('myApp', function() {
beforeEach(angular.mock.module('myApp'));
});
I'm getting Cannot call method 'module' of undefined
I'm attempting to use angular
using Browserify, but I'm unable to figure out how to get AngularJS to use jQuery in this distribution. In a regular AngularJS build, it would simply replace its internal jQLite with jQuery if jQuery turns out to already be loaded, but that is obviously not possible here due to the isolation that Browserify provides.
How can I make angular
use the real jQuery module instead of jQLite?
Using this module as is means that source mapping does not work for the project files.
The solution which i have been using is to remove the source map from angular.min.js
Not sure if this a browserify issue or if chrome does not support nested source maps.
Any ideas?
Error loading source:
Could not load the source for https://localhost:8080/home/michael.heuberger/binarykitchen/code/videomail.io/node_modules/angular/index-browserify.js.
Error: "https://localhost:8080/home/michael.heuberger/binarykitchen/code/videomail.io/node_modules/angular/index-browserify.js" is not in the SourceMap.
Stack: SourceMapConsumer_sourceContentFor@resource://gre/modules/devtools/SourceMap.jsm:391
SourceActor.prototype._getSourceText@resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre/modules/devtools/server/main.js -> resource://gre/modules/devtools/server/actors/script.js:2452
resolve@resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre/modules/commonjs/sdk/core/promise.js:118
then@resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre/modules/commonjs/sdk/core/promise.js:43
then@resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre/modules/commonjs/sdk/core/promise.js:153
SourceActor.prototype.onSource@resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre/modules/devtools/server/main.js -> resource://gre/modules/devtools/server/actors/script.js:2471
DSC_onPacket@resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre/modules/devtools/server/main.js:1023
LDT_send/<@resource://gre/modules/devtools/dbg-client.jsm -> resource://gre/modules/devtools/server/transport.js:258
makeInfallible/<@resource://gre/modules/devtools/DevToolsUtils.jsm -> resource://gre/modules/devtools/DevToolsUtils.js:80
Line: 391, column: 6
I am seeing this in the Firefox console after bundling with browserify with the debug parameter.
I only want the browserify version of angular, but because this repo is dependent on jsdom
to provide the node version of angular I am not able to install this module at all.
That's because jsdom
depends on contextify
which fails to install on several platforms and/or node versions.
IMO it would be better if this repo was split into two repositories, one for the browserify version and one for the node version (which can depend on the browserify version internally).
Until then it's unusable for me...
hi @bclinkinbeard,
is it possible to update your angular version to the latest stable?
maybe you can accept PRs for when new versions come along.
Thank you
-David
Thanks for making this available. Are you planning on doing this for e.g. angular-resource?
If I try this:
var angular = require('angular'),
inject = angular.injector(['ng']).invoke;
require('angular-mocks');
describe('Auth Service', function() {
var $httpBackend;
describe('Login method', function() {
inject(function(_$httpBackend_, $q) {
$httpBackend = _$httpBackend_;
console.log($httpBackend);
});
});
});
I get an error that says 'window is not defined', which is coming from requiring angular-mocks. Is there something else I can try so that I can use the $httpBackend service for testing $http?
Thanks
Not sure why there are two NPM packages, angular and angular-node that AFAICT are the same thing. Also publishing an NPM package called angular
is confusing for someone expecting to just get the straight up Angular files, not your common js wrapper. It would seem that removing the angular
package would clean this up as angular-node
would better describe your package and leave angular
open for someone to publish a package containing straight up Angular. What do you think?
Hi Ben,
https://angularjs.org/ is currently on 1.2.18, while npm published is on 1.2.16. Could you please update it?
Thank you!
Currently you cannot install angular on Windows 8.1 via npm package manager.
npm install angular
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.Cpp.Platform.targets(64,5): error MSB8020: The build tools for Visual Studio 2010 (Platform Toolset = 'v100') cannot be found. To build using the v100 build tools, please install Visual Studio 2010 build tools. Alternatively, you may upgrade to the current Visual Studio tools by selecting the Project menu or right-click the solution, and then selecting "Upgrade Solution...". [node_modules\contextify\build\contextify.vcxproj]
This module helps me a lot in writing code that is shareable between by angularjs-client and nodejs-server. This reduces code repetition.
In order for the code to work in both environments, we have to write shims for angular's modules. For example, for $q
I use the following shim to use q instead.
angular = require('angular')
q = require('q')
angular.module('tepez.common.q', [
])
.config ($provide) ->
# modify angular's $q to use kriskowal's q
$provide.decorator('$q', ['$delegate', ($delegate) ->
$delegate.defer = q.defer
$delegate.all = q.all
return $delegate
])
The same can be written for $http
, $httpbackend
etc.
What do think about this direction? Does it falls within the scope of this module?
I was wondering out the CommonJS-ification of 1.4 might make it easier for angular-node. Obviously it replaces the work angular-node was doing to be importable. But for use outside of a browser, via jsdom, you still need the work custom.js is doing to read the JS source and modify the string before loading. Which means, having a private copy of Angular.
But can this part be eliminated? I don't know how require works, but can you use CommonJS to locate the path to an npm-installed Angular?
Sure wish Angular 1.4 had a hook that let you swap the window and the document.
Ben, alternatively you could declare this project as no longer interesting to you. :)
I get this error just by doing require('angular');
(my script doesn't contain any other code), I'm using 1.2.19 with browserify.
[$injector:nomod] Module 'ngLocale' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
The latest stable of AngularJS is 1.2.15.
Please pull. (Or better yet, automate a pull for latest stable. Better yet, get the AngularJS project to host the official npm angular module instead.)
I checked out the 0.12 branch from the nodejs source repo and built it (it reports its version as 0.11.14-pre).
Using the resulting node binary, require('angular')
(using 1.2.23 of this module installed from npm) throws a TypeError:
magi@ubuntu ~/s/d> node
> require('angular')
TypeError: Cannot set property length of [object Object] which has only a getter
at DocumentFragment.core.Node.insertBefore (/home/magi/src/test/node_modules/angular/node_modules/jsdom/lib/jsdom/level1/core.js:553:30)
at DocumentFragment.<anonymous> (/home/magi/src/test/node_modules/angular/node_modules/jsdom/lib/jsdom/level2/events.js:332:20)
at DocumentFragment.proto.(anonymous function) [as insertBefore] (/home/magi/src/test/node_modules/angular/node_modules/jsdom/lib/jsdom/utils.js:23:26)
at DocumentFragment.core.Node.appendChild (/home/magi/src/test/node_modules/angular/node_modules/jsdom/lib/jsdom/level1/core.js:671:17)
at jqLiteBuildFragment (eval at <anonymous> (/home/magi/src/test/node_modules/angular/custom.js:14:3), <anonymous>:2330:20)
at jqLiteParseHTML (eval at <anonymous> (/home/magi/src/test/node_modules/angular/custom.js:14:3), <anonymous>:2364:10)
at Object.JQLite (eval at <anonymous> (/home/magi/src/test/node_modules/angular/custom.js:14:3), <anonymous>:2383:26)
at forEach.prepend (eval at <anonymous> (/home/magi/src/test/node_modules/angular/custom.js:14:3), <anonymous>:3000:15)
at Object.JQLite.(anonymous function) [as prepend] (eval at <anonymous> (/home/magi/src/test/node_modules/angular/custom.js:14:3), <anonymous>:3112:17)
at eval (eval at <anonymous> (/home/magi/src/test/node_modules/angular/custom.js:14:3), <anonymous>:21956:88)
The actual exception comes from inside https://github.com/tmpvar/jsdom code, and I suspect using a newer version of jsdom might help.
The package.json in the angular npm module requests ~0.8.8 of jsdom, and is currently getting 0.8.11. I changed node_modules/angular/package.json to ask for ~1.0 of jsdom, and it gets 1.0.0-pre.6, and this seems to work better; at least, require('angular')
works from the REPL with my "node 0.12" binary.
Assuming jsdom ~1.0 works for this module's purposes under node 0.10 as well, it might be a good time to upgrade?
Hi,
The idea behind this is fantastic! However, I'm struggling with examples. For instance, I just want to test a simple factory.
Let's say I have a client-side asset, which is an AngularJS Module w/ a factory in its own file (which gets compiled by a build tool):
factory.litcoffee:
angular.module('com.me', []).factory 'myFactory', [
() ->
api =
test: () -> 'someval'
]
In Node.js, I'd like to assert that myFactory.test()
returns someval
, but I keep getting an error. I haven't gotten to "assert" yet, I'm just trying to get someval
logged.
test.litcoffee:
angular = require('angular-node')()
require './factory.litcoffee'
injector = angular.injector [ 'com.me' ]
fn = (myFactory) -> console.log myFactory.test()
injector.invoke fn
The error:
Module 'com.me' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
I have also tried:
angular = require('angular-node')()
require './factory.litcoffee'
injector = angular.injector [ 'myFactory' ]
fn = (myFactory) -> console.log myFactory.test()
injector.invoke fn
The error:
Module 'myFactory' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
...and this...
angular = require('angular-node')()
require './factory.litcoffee'
injector = angular.injector [ 'com.me' ]
injector.invoke [
'myFactory',
(myFactory) ->
console.log myFactory.test()
]
...and this...
angular = require('angular-node')()
require './factory.litcoffee'
injector = angular.injector [ 'myFactory' ]
injector.invoke [
'myFactory',
(myFactory) ->
console.log myFactory.test()
]
... and this...
angular = require('angular-node')()
require './factory.litcoffee'
injector = angular.injector [ 'com.me' ]
myFactory = injector.get 'myFactory'
ctrl = (myFactoryObj) -> console.log myFactoryObj.test()
injector.instantiate ctrl
Think you can help shed some insight? I've used injector on the client-side before, but that was into a config! Can't seem to get it. Is this how you envisioned a test to be ran? Thanks!
Any chance this can be updated to the latest 1.2 version
I am useing angular doing some compile work, make ng tags to common HTML tag.
I wish to config $compileProvider on server side, but don't khow how to. can you help me?
Angular is a v1.2.23 for today. Could you bump version?
I'm trying to pre-render my angular site on the server for SEO purposes and stumbled across this package which comes with jsdom.
I can inject for testing as the documentation describes, but how would I go about getting the full HTML of the page to send on page-load?
angular.$window
and angular.$document
are undefined.
Now that angular core team is using angular
as a npm module name. It'd be nice to give this a new name even though I can technically pull it from github in npm. Call me lazy but I like the convenience of just doing npm i [packageName]
π
So Gemnasium has this thing where it can automatically upgrade your packages for you via pull request. I believe this is free to do for 2 packages.
Theoretically, then, when angularcore
releases a new version, Gemnasium can send a PR with the updated dependency.
After that you'd just have to bump version and tag, or figure out some way to automate further.
At the very least it can let you know when the angular
is updated.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.