How can I add jsonwebtoken as external lib for postman? - postman

From the following blog posts its possible to reference an external lib in postman
https://blog.postman.com/adding-external-libraries-in-postman/
https://community.postman.com/t/adding-external-libraries-to-postman/1971/3
However if I attempt this with jsonwebtoken it does not work as that lib references its own files.
pm.sendRequest("https://cdnjs.cloudflare.com/ajax/libs/jsonwebtoken/8.5.1/sign.min.js", (err, res) => {
//convert the response to text and save it as an environment variable
pm.collectionVariables.set("jsonwebtoken_library", res.text());
// eval will evaluate the JavaScript code and initialize the min.js
eval(pm.collectionVariables.get("jsonwebtoken_library"));
// you can call methods in the cdn file using this keyword
console.log(this.sign({ foo: 'bar' }, 'shhhhh'))
})
Error is always
Error: Cannot find module './lib/timespan'
How can jsonwebtoken be used as an external lib on postman?

Related

Correct way to import all assets from external library with Ember CLI

I'm working on an Ember.js project and would like to leverage the Slick Carousel library. I've installed the library via Bower in my project folder, and am having difficulty with importing it into my project.
In my ember-cli-build.js, I've added import statements as follows:
app.import('bower_components/slick-carousel/slick/slick.css');
app.import('bower_components/slick-carousel/slick/slick-theme.css');
app.import('bower_components/slick-carousel/slick/slick.js');
The issue I am running into is that the rest of the required assets do not get built and included in the dist folder when I do a build (fonts, assets, etc.), leading to errors with missing fonts and assets that are present in the "bower_components/slick-carousel" folder, but not in the build of my actual Ember application.
Edit: It looks like Broccoli-Funnel was what I needed. The issue was resolved by specifying the source files from the 'bower_components' folder and pointing the relative path to the 'dist' folder in the ember-cli-build.js file.
As a note: The 'broccoli-static-compiler' plugin commonly referenced elsewhere as the solution is deprecated, with the use of 'broccoli-funnel' as the recommended plugin.
Broccoli-funnel ended up being what I was looking for. By placing the following inside of ember-cli-build.js, the needed files would be placed in the correct directory during build:
var Funnel = require('broccoli-funnel');
var requiredAssets = new Funnel('bower_components/slick-carousel/slick/fonts', {
srcDir: '/',
include: ['**/*.*'],
destDir: '/assets/fonts'
});
return app.toTree([requiredAssets]);

emberjs how to add external js files

I am novice to ember.js, This is how I have included my external java script file to ember project to call to jquery plugin in imagerotator.js
<script src="{{rootURL}}assets/imagerotator/html/js/imagerotator.js"></script>
when I am calling it from the document.ready() function it getting initialized properly.
But I need that plugin should be only in only one hadlerbar(.hbs) file.
Am I doing it correctly ?
I heard there is a "didInsertElement" function in components file and define there but in my case I don't have component just have template file only.
I am novice to emberjs and sorry for my poor English.
Place imagerotator/html/js/imagerotator.js file in vendor folder and include it in ember-cli-build.js file by app.import('vendor/imagerotator/html/js/imagerotator.js');
It good to create component and initialize it in didInsertElement hook.

Ember external js and global

In my Ember app I am trying to add the money.js external lib. I successfully achieved that by installing it with bower and then adding app.import('bower_components/money.js/money.js'); to my ember-cli-build.js.
money.js defines a global variable fx which is available all over my app. However I receive many JSHint Errors while building the app like:
components/purchase-form.js: line 41, col 29, 'fx' is not defined.
Ember docs states:
Typically, the application object is the only global variable. All
other classes in your app should be properties on the
Ember.Application instance, which highlights its first role: a global
namespace.
I just wonder what is the proper way to import this kind of lib along with its global
If you app.import a global you have to possibilities to make jsHint happy:
Adding /* global fx */ before accessing the global per file.
Adding it to predefs section in .jshintrc as #kumkanillam mentioned in his answer.
If you don't like to access dependency as a global you could shim it. Ember-cli provides a vendor-shim generator: ember generate vendor-shim money.js Afterward you could use import in your modules.
This topic is well-documented in ember-cli docs.
To avoid jsHint error, you can mention fx global variable
{
"predef": [
"document",
"window",
"-Promise",
"fx"
]
}

grunt-karma not running the spec file when using shared config

I created a basic project to try and get Gruntjs, Karma and Jasmine to play together. When I setup the karma.conf.js file with all of the neccesary files, everything works and the tests pass.
When I try to split them up in Grunt though, I get problems.
Gruntfile.js
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
karma: {
options: {
configFile: 'karma.conf.js'
},
basicController: {
files: ['/basicController/scBasicControllerCtrl.js', '/basicController/test/ControllersSpec.js']
},
overworkedController: {
src: ['overworkedController/scOverworkedControllerCtrl.js', 'overworkedController/test/ControllersSpec.js']
}
}
});
The documentation at grunt-karma show to use "files:" when splitting up the modules. I did that under the basicController module and when I try to run $ grunt karma:basicController --verbose, I get an error saying
Warning: Cannot use 'in' operator to search for 'src' in /basicController/scBasicControllerCtrl.js Use --force to continue
Aborted due to warnings.
When I run $ grunt karma:overworkedControllers --verbose (using "src" instead of "files", it looks like everything is going to work and the Chrome browser launches but then is says it executed 0 of 0 ERROR.
There should be 3 tests.
Let me know if there's any more info I could post.
My understanding of grunt-karma was incorrect.
I thought I could have the base and source files in the karma.conf.js file. Then in each module, I'd just add the specific files needed for that module and test.
The way it actually works is that the files declared in each module completely overwrite the files property in the karma.conf.js file. Not append to them.
I ended up creating an array in Gruntfile.js that contains all of the source .js files and just concat the necessary files to it in each module.

Testing a non-trivial AngularJS app with Jasmine & Karma

I'm working on a non-trivial application, with the following folder structure:
build (required files such as angular.js)
Gruntfile.js
karma.conf.js
logs/
node_modules/
src/
- app/
- app.js
- module_name/
- module.js
- controllers/
- controller1.js
- controller2.js
- views/
- view1.html
- assets/
- 1.jpg
- styler.css
- components/ (plugged in modules [angular-ui, etc])
- index.html
My controllers are each attached to their parent module. That module is then required in my app.js file.
I have tried writing some unit tests, but I seem to keep having trouble with dependancies, since the controller I try to test requires it's module, then that module requires another one, etc.
My question has a few parts:
How do I go about structuring my karma.conf.js file to include the necessary files?
Specifically this part of the configuration:
files: [
'files_to_be_tested.js',
]
Using Jasmine, how do I write up a unit test with all the proper dependancies? As an example, I run the following test
Javascript
using 'strict'
describe('my Module', function() {
describe('myController', function() {
var ctrl, scope;
beforeEach(module('myModule'));
beforeEach(inject(function ($rootScope, $controller) {
scope = $rootScope.$new();
ctrl = $controller('myController', { $scope: scope });
}));
it('should work', function() {
// Execute functionality
})
})
})
but I keep getting the error: Unknown provider: $stateProvider, which I think is coming from the loaded module's route configuration.
I'm beginning to wonder whether I've been separating out my controllers properly?
To answer the second question:
Unknown provider: $stateProvider is caused by the ui.router module not being loaded. To solve the problem, add beforeEach(module('ui.router'))
The problem arises because the controller you are loading is trying to inject $state
Make sure that the ui.router Javascript file is in the files list in karma.conf.js or the module will not be available to karma.
Here is the answer to your first question. Configuring the files section;
// list of files / patterns to load in the browser
files = [
JASMINE,
JASMINE_ADAPTER,
'components/angular/angular.js', //path to your angular.js file
'components/angular-mocks/angular-mocks.js',//path to your angular-mocks.js file
'components/angular-resource/angular-resource.js',//path to your angular-resource.js file
'app/*.js',
'app/**/*.js',
'test/mock/**/*.js',
'test/spec/**/*.js'
];
Try this change in your karma.conf.js and carry out your test. Hope it helps.
Same files/patterns as your application, in the same order, then angular-mock, then your specs.
If you're loading a module, it should be already loaded with all its dependent modules. Since you're missing a provider and your example is calling only a controller, it could be missing from the injected controller dependencies in $controller('myController', { $scope: scope });.