Issues with minification - javascript

I decided to switch from socketIO to sockjs for my Angularjs app. I never had problems building my project before (with socketIO) which involves minification and concat but when I build my project now I think that this file is giving me issues which is from here: https://github.com/bendrucker/angular-sockjs as it's the only new file.
/*
* angular-sockjs v0.0.1
* (c) 2014 Ben Drucker http://bendrucker.me
* Based on https://github.com/btford/angular-socket-io
* License: MIT
*/
'use strict';
angular.module('bd.sockjs', [])
.provider('socketFactory', function () {
// when forwarding events, prefix the event name
var ioSocket;
// expose to provider
this.$get = function ($timeout) {
var asyncAngularify = function (socket, callback) {
return callback ? function () {
var args = arguments;
$timeout(function () {
callback.apply(socket, args);
}, 0);
} : angular.noop;
};
return function socketFactory (options) {
options = options || {};
var socket = options.socket || new SockJS(options.url);
var wrappedSocket = {
callbacks: {},
setHandler: function (event, callback) {
socket['on' + event] = asyncAngularify(socket, callback);
return this;
},
removeHandler: function(event) {
delete socket['on' + event];
return this;
},
send: function () {
return socket.send.apply(socket, arguments);
},
close: function () {
return socket.close.apply(socket, arguments);
}
};
return wrappedSocket;
};
};
});
Is there any reason why this file won't minify?
I am aware of the typical Angularjs minification issues so I've used string-injection syntax in all of my files. However, I can't see an opportunity to do that with this file and there isn't a minified file included with the Bower install.
This is the error in the browser console which looks to me like an injection issue:
Error: [$injector:unpr] http://errors.angularjs.org/1.3.0-beta.13/$injector/unpr?p0=aProvider%20%3C-%20a%20%3C-ocketFactory%20%3C-%socket
UPDATE:
To test that it was this file causing the issue I hosted the file on a CDN instead of minifying it. Everything works fine now so it must be this file causing the issue. It would be interesting to know what the problem is if anyone comes across this question.

Solved this on Github. #efeder was mostly correct (although it's this.$get and not this.get). The issue is that v0.0.1 didn't have proper annotations but v0.1 (latest) fixed that.

Related

(Alexa) Bespoken throws an `cannot find module` when testing locally

Hope you all had a wonderful holiday. My name is James David Bohrman and I am currently undertaking my first big code project that is not attached to a tutorial, so I'm exiting a huge stage in my journey.
My project is an Alexa skill that calls on the Cannabis Reports API by using an API wrapper called the same. The goal is to have a skill that accesses the API using the wrapper and creates a voice skill, but I'm having trouble with the Lambda.
Now I will state that I was testing in the Lambda console and not locally, which someone suggested I acquire tools to do.
As I said this is my first solo project so while I do not want my hand held, it is very important to my confidence that I finish this.
One of the errors I'm throwing in Bespoken CLI is "Cannot find module 'alexa-sdk'"
I have my package.json up to date on all my local versions of the project, even those not on GitHub, and alexa-sdk is for sure installed.
The github page is a little messy, but it's at https://github.com/jdbohrman/cannabis-reports-alexa
'use strict';
const Alexa = require('alexa-sdk');
var CannabisReport = require('cannabis-report');
const SKILL_NAME = 'Cannabis Report';
const answer = {
'AMAZON.HelpIntent': function () {
this.response.speak(HELP_MESSAGE).listen(HELP_REPROMPT);
this.emit(':responseReady');
},
'AMAZON.CancelIntent': function () {
this.response.speak(STOP_MESSAGE);
this.emit(':responseReady');
},
'AMAZON.StopIntent': function () {
this.response.speak(STOP_MESSAGE);
this.emit(':responseReady');
},
'CannabisReport': function () {
var speechOutput = Strain.search('');
this.emit ('tell', speechOutput);
}
};
exports.handler = function (event, context, callback) {
var alexa = Alexa.handler(event, context);
alexa.appId = APP_ID;
alexa.registerHandlers(handlers);
alexa.execute();
});

AngularJS app works on localhost but throws errors on server

I have an angularJS quiz application that works fine on localhost. Once uploaded to a live server the app doesnt load and the console fires an error. I have no idea what could be wrong as the app is working locally. Here is the error:
Error: [$injector:modulerr] http://errors.angularjs.org/1.6.3/$injector/modulerr?p0=ng&p1=%5B%24compile%3Abaddir%5D%20http%3A%2F%2Ferrors.angularjs.org%2F1.6.3%2F%24compile%2Fbaddir%3Fp0%3Dng%2520%0AM%2F%3C%40http%3A%2F%2Fexpertonlinetraining.info%2Fwp-content%2Fplugins%2Feot_quiz%2Fpublic%2Fjs%2Fangular.min.js%2Cqver%3D1.0.0.pagespeed.jm.L2GCHQP8hk.js%3A1%3A425%0Ac%40http%3A%2F%2Fexpertonlinetraining.info%2Fwp-content%2Fplugins%2Feot_quiz%2Fpublic%2Fjs%2Fangular.min.js%2Cqver%3D1.0.0.pagespeed.jm.L2GCHQP8hk.js%3A4%3A16055%0Ay%40http%3A%2F%2Fexpertonlinetraining.info%2Fwp-content%2Fplugins%2Feot_quiz%2Fpublic%2Fjs%2Fangular.min.js%2Cqver%3D1.0.0.pagespeed.jm.L2GCHQP8hk.js%3A4%3A16467%0AIc%2F%3C%40http%3A%2F%2Fexpertonlinetraining.info%2Fwp-content%2Fplugins%2Feot_quiz%2Fpublic%2Fjs%2Fangular.min.js%2Cqver%3D1.0.0.pagespeed.jm.L2GCHQP8hk.js%3A1%3A1416%0Ap%40http%3A%2F%2Fexpertonlinetraining.info%2Fwp-content%2Fplugins%2Feot_quiz%2Fpublic%2Fjs%2Fangular.min.js%2Cqver%3D1.0.0.pagespeed.jm.L2GCHQP8hk.js%3A1%3A1201%0Ay%40http%3A%2F%2Fexpertonlinetraining.info%2Fwp-content%2Fplugins%2Feot_quiz%2Fpublic%2Fjs%2Fangular.min.js%2Cqver%3D1.0.0.pagespeed.jm.L2GCHQP8hk.js%3A4%3A16968%0ACe%2F%3C%40http%3A%2F%2Fexpertonlinetraining.info%2Fwp-content%2Fplugins%2Feot_quiz%2Fpublic%2Fjs%2Fangular.min.js%2Cqver%3D1.0.0.pagespeed.jm.L2GCHQP8hk.js%3A4%3A3365%0Ainvoke%40http%3A%2F%2Fexpertonlinetraining.info%2Fwp-content%2Fplugins%2Feot_quiz%2Fpublic%2Fjs%2Fangular.min.js%2Cqver%3D1.0.0.pagespeed.jm.L2GCHQP8hk.js%3A4%3A10908%0Ad%40http%3A%2F%2Fexpertonlinetraining.info%2Fwp-content%2Fplugins%2Feot_quiz%2Fpublic%2Fjs%2Fangular.min.js%2Cqver%3D1.0.0.pagespeed.jm.L2GCHQP8hk.js%3A4%3A9758%0Ag%2F%3C%40http%3A%2F%2Fexpertonlinetraining.info%2Fwp-content%2Fplugins%2Feot_quiz%2Fpublic%2Fjs%2Fangular.min.js%2Cqver%3D1.0.0.pagespeed.jm.L2GCHQP8hk.js%3A4%3A9905%0Ap%40http%3A%2F%2Fexpertonlinetraining.info%2Fwp-content%2Fplugins%2Feot_quiz%2Fpublic%2Fjs%2Fangular.min.js%2Cqver%3D1.0.0.pagespeed.jm.L2GCHQP8hk.js%3A1%3A1011%0Ag%40http%3A%2F%2Fexpertonlinetraining.info%2Fwp-content%2Fplugins%2Feot_quiz%2Fpublic%2Fjs%2Fangular.min.js%2Cqver%3D1.0.0.pagespeed.jm.L2GCHQP8hk.js%3A4%3A9667%0Aeb%40http%3A%2F%2Fexpertonlinetraining.info%2Fwp-content%2Fplugins%2Feot_quiz%2Fpublic%2Fjs%2Fangular.min.js%2Cqver%3D1.0.0.pagespeed.jm.L2GCHQP8hk.js%3A4%3A11811%0Ac%40http%3A%2F%2Fexpertonlinetraining.info%2Fwp-content%2Fplugins%2Feot_quiz%2Fpublic%2Fjs%2Fangular.min.js%2Cqver%3D1.0.0.pagespeed.jm.L2GCHQP8hk.js%3A3%3A373%0APc%40http%3A%2F%2Fexpertonlinetraining.info%2Fwp-content%2Fplugins%2Feot_quiz%2Fpublic%2Fjs%2Fangular.min.js%2Cqver%3D1.0.0.pagespeed.jm.L2GCHQP8hk.js%3A3%3A686%0Aue%40http%3A%2F%2Fexpertonlinetraining.info%2Fwp-content%2Fplugins%2Feot_quiz%2Fpublic%2Fjs%2Fangular.min.js%2Cqver%3D1.0.0.pagespeed.jm.L2GCHQP8hk.js%3A2%3A5429%0A%40http%3A%2F%2Fexpertonlinetraining.info%2Fwp-content%2Fplugins%2Feot_quiz%2Fpublic%2Fjs%2Fangular.min.js%2Cqver%3D1.0.0.pagespeed.jm.L2GCHQP8hk.js%3A9%3A72076%0Ai%40http%3A%2F%2Fexpertonlinetraining.info%2Fwp-includes%2Fjs%2Fjquery%2Fjquery.js%2Cqver%3D1.12.4.pagespeed.jm.pPCPAKkkss.js%3A1%3A27444%0AfireWith%40http%3A%2F%2Fexpertonlinetraining.info%2Fwp-includes%2Fjs%2Fjquery%2Fjquery.js%2Cqver%3D1.12.4.pagespeed.jm.pPCPAKkkss.js%3A1%3A28213%0Aready%40http%3A%2F%2Fexpertonlinetraining.info%2Fwp-includes%2Fjs%2Fjquery%2Fjquery.js%2Cqver%3D1.12.4.pagespeed.jm.pPCPAKkkss.js%3A1%3A30004%0AK%40http%3A%2F%2Fexpertonlinetraining.info%2Fwp-includes%2Fjs%2Fjquery%2Fjquery.js%2Cqver%3D1.12.4.pagespeed.jm.pPCPAKkkss.js%3A1%3A30366%0A
Does anyone have any insights? I have developed the quiz as a wordpress plugin with some variables localized to the angular script.
I am using angular 1.6 with angular route. Some of my code is below:
(function(){
/*
* Declaration of main angular module for this appllication.
*
* It is named quiz and has no dependencies (hence the
* empty array as the second argument)
*/
angular
.module("quiz", []);
})();
Controllers:
(function () {
angular
.module("quiz")
.controller("quizCtrl", QuizController);
QuizController.$inject = ['quizmanager'];
function QuizController(quizmanager)
{
...
Controllers:
(function () {
angular
.module("quiz")
.controller("resultsCtrl", ResultsController);
ResultsController.$inject = ['quizmanager'];
function ResultsController(quizmanager)
{
var vm = this;
vm.quizmanager = quizmanager;
}
})();
CONTROLLER:
(function () {
angular
.module("quiz")
.controller("welcomeCtrl", WelcomeController);
WelcomeController.$inject = ['quizmanager'];
function WelcomeController(quizmanager)
{
var vm = this;
vm.quizmanager = quizmanager;
vm.activateQuiz = activateQuiz;
/*
* STARTING POINT OF APPLICATION. All the other views are hidden
*/
quizmanager.loadQuiz();
function activateQuiz()
{
quizmanager.changeState("quiz", true);
quizmanager.countdown();
}
}
})();
Based on your responses, heres where i think the problem lies:
FACTORIES:
(function () {
angular
.module("quiz")
.factory("quizmanager", QuizManager)
.filter('formatTimer', function () {
return function (input)
{
function z(n) {
return (n < 10 ? '0' : '') + n;
}
var seconds = input % 60;
var minutes = Math.floor(input / 60);
var hours = Math.floor(minutes / 60);
return (z(hours) + ':' + z(minutes) + ':' + z(seconds));
};
});
QuizManager.$inject = ['$http', '$timeout', '$httpParamSerializer', '$filter'];
......
I have modified the app and added the filter as a seperate module like so:
(function () {
angular
.module("quiz")
.filter('formatTimer', function () {
return function (input)
{
function z(n) {
return (n < 10 ? '0' : '') + n;
}
var seconds = input % 60;
var minutes = Math.floor(input / 60);
var hours = Math.floor(minutes / 60);
return (z(hours) + ':' + z(minutes) + ':' + z(seconds));
};
});
})();
The app still works in localhost but Im still getting an error:
Error: [$injector:modulerr] http://errors.angularjs.org/1.6.3/$injector/modulerr?p0=ng&p1=%5B%24compile%3Abaddir%5D%20http%3A%2F%2Ferrors.angularjs.org%2F1.6.3%2F%24compile%2Fbaddir%3Fp0%3Dng%2520%0AM%2F%3C%40http%3A%2F%2Fexpertonlinetraining.info%2Fwp-content%2Fplugins%2Feot_quiz%2Fpublic%2Fjs%2Fangular.min.js%2Cqver%3D1.0.0.pagespeed.jm.L2GCHQP8hk.js%3A1%3A425%0Ac%40http%3A%2F%2Fexpertonlinetraining.info%2Fwp-content%2Fplugins%2Feot_quiz%2Fpublic%2Fjs%2Fangular.min.js%2Cqver%3D1.0.0.pagespeed.jm.L2GCHQP8hk.js%3A4%3A16055%0Ay%40http%3A%2F%2Fexpertonlinetraining.info%2Fwp-content%2Fplugins%2Feot_quiz%2Fpublic%2Fjs%2Fangular.min.js%2Cqver%3D1.0.0.pagespeed.jm.L2GCHQP8hk.js%3A4%3A16467%0AIc%2F%3C%40http%3A%2F%2Fexpertonlinetraining.info%2Fwp-content%2Fplugins%2Feot_quiz%2Fpublic%2Fjs%2Fangular.min.js%2Cqver%3D1.0.0.pagespeed.jm.L2GCHQP8hk.js%3A1%3A1416%0Ap%40http%3A%2F%2Fexpertonlinetraining.info%2Fwp-content%2Fplugins%2Feot_quiz%2Fpublic%2Fjs%2Fangular.min.js%2Cqver%3D1.0.0.pagespeed.jm.L2GCHQP8hk.js%3A1%3A1201%0Ay%40http%3A%2F%2Fexpertonlinetraining.info%2Fwp-content%2Fplugins%2Feot_quiz%2Fpublic%2Fjs%2Fangular.min.js%2Cqver%3D1.0.0.pagespeed.jm.L2GCHQP8hk.js%3A4%3A16968%0ACe%2F%3C%40http%3A%2F%2Fexpertonlinetraining.info%2Fwp-content%2Fplugins%2Feot_quiz%2Fpublic%2Fjs%2Fangular.min.js%2Cqver%3D1.0.0.pagespeed.jm.L2GCHQP8hk.js%3A4%3A3365%0Ainvoke%40http%3A%2F%2Fexpertonlinetraining.info%2Fwp-content%2Fplugins%2Feot_quiz%2Fpublic%2Fjs%2Fangular.min.js%2Cqver%3D1.0.0.pagespeed.jm.L2GCHQP8hk.js%3A4%3A10908%0Ad%40http%3A%2F%2Fexpertonlinetraining.info%2Fwp-content%2Fplugins%2Feot_quiz%2Fpublic%2Fjs%2Fangular.min.js%2Cqver%3D1.0.0.pagespeed.jm.L2GCHQP8hk.js%3A4%3A9758%0Ag%2F%3C%40http%3A%2F%2Fexpertonlinetraining.info%2Fwp-content%2Fplugins%2Feot_quiz%2Fpublic%2Fjs%2Fangular.min.js%2Cqver%3D1.0.0.pagespeed.jm.L2GCHQP8hk.js%3A4%3A9905%0Ap%40http%3A%2F%2Fexpertonlinetraining.info%2Fwp-content%2Fplugins%2Feot_quiz%2Fpublic%2Fjs%2Fangular.min.js%2Cqver%3D1.0.0.pagespeed.jm.L2GCHQP8hk.js%3A1%3A1011%0Ag%40http%3A%2F%2Fexpertonlinetraining.info%2Fwp-content%2Fplugins%2Feot_quiz%2Fpublic%2Fjs%2Fangular.min.js%2Cqver%3D1.0.0.pagespeed.jm.L2GCHQP8hk.js%3A4%3A9667%0Aeb%40http%3A%2F%2Fexpertonlinetraining.info%2Fwp-content%2Fplugins%2Feot_quiz%2Fpublic%2Fjs%2Fangular.min.js%2Cqver%3D1.0.0.pagespeed.jm.L2GCHQP8hk.js%3A4%3A11811%0Ac%40http%3A%2F%2Fexpertonlinetraining.info%2Fwp-content%2Fplugins%2Feot_quiz%2Fpublic%2Fjs%2Fangular.min.js%2Cqver%3D1.0.0.pagespeed.jm.L2GCHQP8hk.js%3A3%3A373%0APc%40http%3A%2F%2Fexpertonlinetraining.info%2Fwp-content%2Fplugins%2Feot_quiz%2Fpublic%2Fjs%2Fangular.min.js%2Cqver%3D1.0.0.pagespeed.jm.L2GCHQP8hk.js%3A3%3A686%0Aue%40http%3A%2F%2Fexpertonlinetraining.info%2Fwp-content%2Fplugins%2Feot_quiz%2Fpublic%2Fjs%2Fangular.min.js%2Cqver%3D1.0.0.pagespeed.jm.L2GCHQP8hk.js%3A2%3A5429%0A%40http%3A%2F%2Fexpertonlinetraining.info%2Fwp-content%2Fplugins%2Feot_quiz%2Fpublic%2Fjs%2Fangular.min.js%2Cqver%3D1.0.0.pagespeed.jm.L2GCHQP8hk.js%3A9%3A72076%0Ai%40http%3A%2F%2Fexpertonlinetraining.info%2Fwp-includes%2Fjs%2Fjquery%2Fjquery.js%2Cqver%3D1.12.4.pagespeed.jm.pPCPAKkkss.js%3A1%3A27444%0AfireWith%40http%3A%2F%2Fexpertonlinetraining.info%2Fwp-includes%2Fjs%2Fjquery%2Fjquery.js%2Cqver%3D1.12.4.pagespeed.jm.pPCPAKkkss.js%3A1%3A28213%0Aready%40http%3A%2F%2Fexpertonlinetraining.info%2Fwp-includes%2Fjs%2Fjquery%2Fjquery.js%2Cqver%3D1.12.4.pagespeed.jm.pPCPAKkkss.js%3A1%3A30004%0AK%40http%3A%2F%2Fexpertonlinetraining.info%2Fwp-includes%2Fjs%2Fjquery%2Fjquery.js%2Cqver%3D1.12.4.pagespeed.jm.pPCPAKkkss.js%3A1%3A30366%0A angular.min.js,qver=1.0.0.pagespeed.jm.L2GCHQP8hk.js:1:425
Description
This error occurs when a module fails to load due to some
exception. The error message above should provide additional context.
A common reason why the module fails to load is that you've forgotten
to include the file with the defined module or that the file couldn't
be loaded.
Using ngRoute
In AngularJS 1.2.0 and later, ngRoute has been moved to
its own module. If you are getting this error after upgrading to 1.2.x
or later, be sure that you've installed ngRoute.
Monkey-patching AngularJS's ng module
This error can also occur if you
have tried to add your own components to the ng module. This has never
been supported and from 1.3.0 it will actually trigger this error. For
instance the following code could trigger this error.
angular.module('ng').filter('tel', function (){}); Instead create your
own module and add it as a dependency to your application's top-level
module. See #9692 and #7709 for more information
What version of AngularJS are you using? You might be running into the second issue description here.

node.js mock sendmailer transporter inside function

Im working with an node handler in AWS lambda and i need to make another files with integration tests from that function, but i cant mock the transporter with sinon or mockery.
the index.js function:
var nodemailer = require('nodemailer');
exports.handler = (event, context, callback) =>
{
var transporter=createTransporter();
transporter.sendMail(data, function (error, success) {
console.log(error);
response = getResponse(404, error);
}
callback(null, response);
});
}
function createTransporter() {
return nodemailer.createTransport({
service: "SMTP",
auth: {
user: "XXXX#XXX",
pass: "XXXX"
}
});
}
the purpose is to mock the function createTransporter() so that it doesnt send any email when it is called in javascript file test with mocha and expect:
var mockery = require('mockery');
var nodemailerMock = require('nodemailer-mock');
var index = require("../index.js");
describe("The handler function tests", function () {
before(function () {
mockery.enable({
warnOnUnregistered: false
});
mockery.registerMock('nodemailer', nodemailerMock);
});
it('JSON error html ', function () {
var callback = function (name, response) {
expect(JSON.stringify(response.statusCode)).to.be('404');
};
var context = {};
index.handler(event, context, callback);
});
});
I wrote nodemailer-mock :)
The problem you're having is that you are calling var index = require("../index.js"); before you are mocking nodemailer via mockery, so it is already in the module cache. I included // Make sure anything that uses nodemailer is loaded here, after it is mocked... in the examples in the README, but should probably make it more clear.
Move the require("../index.js") after nodemailer is mocked and it will be work as expected.
var mockery = require('mockery');
var nodemailerMock = require('nodemailer-mock');
// don't require here since you will get the real nodemailer and cache it
var index;
describe("The handler function tests", function () {
before(function () {
mockery.enable({
warnOnUnregistered: false
});
mockery.registerMock('nodemailer', nodemailerMock);
// do the require() here after nodemailer is mocked
index = require("../index.js");
});
// your tests here should now use nodemailer-mock
it('JSON error html ', function () {
var callback = function (name, response) {
expect(JSON.stringify(response.statusCode)).to.be('404');
};
var context = {};
index.handler(event, context, callback);
});
});
Another option is to use the { useCleanCache: true } option with calls to mockery.resetCache();, though I have had mixed results. See Controlling the Module Cache in the mockery documentation.
I'm not 100% sure why this would fail, but I suggest one of two things:
Try doing var createTransporter = function()... there's a slight difference here that might be your issue
exporting createTransporter so you can assign a new value to it, either a mock or not. This isn't very "keep implementation details private", it does work
Have your module return a class, or object anyway, where you can set some "use this transporter method" value. (ie dependency injection)
You can use the following option from Jest:
jest.mock('nodemailer').setMock(/* function mock for module */)
Remember to use this at the top of the file, before import or require statements.
Here is the official Jest documentation: https://jestjs.io/docs/manual-mocks#mocking-node-modules.

Reading functions from one file to another in protractor JS

I have written a file with a number of functions that I wish to use across a variety of E2E tests. I have been trying to test this out and have found some solutions but none work for me.
This is how things stand.
In my TestingFunc.js file I have created the following:
var TestingFunc = function() {
this.login = function(Url) {
browser.ignoreSynchronization = true;
browser.get(Url);
browser.wait(EC.elementToBeClickable(element(by.eeHook('login',null,null))), 300000);
element(by.eeHook('login', null, null)).click();
element(by.eeHook('authenticationEmailField',null,null)).sendKeys(logins.International);
element(by.name('password')).sendKeys(logins.password);
element(by.eeHook('authenticationLoginButton',null,null)).click();
browser.wait(EC.elementToBeClickable(paymentFlow), 100000);
paymentFlow.click();
browser.wait(EC.elementToBeClickable(depositAmount), 7000);
};
};
and I am trying to read it in the following:
var url = 'http://master.mrgreen.avengers.zone/en-US/casino';
var TestingFunc = require("C:/Users/davbor.3DB/MrGreen Google Drive/LetsTest/TestingFunc.js");
describe("The security application", function () {
var test = new TestingFunc();
it("will login to the page", function () {
test.login(url);
});
});
Yet each time I run it I keep getting the error:
Failures:
1) The security application encountered a declaration exception
Message:
TypeError: TestingFunc is not a constructor
Stack:
TypeError: TestingFunc is not a constructor
at Suite.<anonymous> (C:\Users\davbor.3DB\MrGreen Google Drive\LetsTest\Testing.js:6:17)
Not sure what i am missing as I have even asked an in house developer to look at it without success.
var TestingFunc = require("C:/Users/davbor.3DB/MrGreen Google Drive/LetsTest/TestingFunc.js");
1) You should not use full path. Use relative path to this file.
In your Testing.js require should look like this:
var TestingFunc = require("./TestingFunc.js");
2) You should 'export' your function:
var TestingFunc = function() {
this.login = function(Url) {
browser.ignoreSynchronization = true;
browser.get(Url);
browser.wait(EC.elementToBeClickable(element(by.eeHook('login',null,null))), 300000);
element(by.eeHook('login', null, null)).click();
element(by.eeHook('authenticationEmailField',null,null)).sendKeys(logins.International);
element(by.name('password')).sendKeys(logins.password);
element(by.eeHook('authenticationLoginButton',null,null)).click();
browser.wait(EC.elementToBeClickable(paymentFlow), 100000);
paymentFlow.click();
browser.wait(EC.elementToBeClickable(depositAmount), 7000);
};
};
module.exports = TestingFunc;
Check more about nodejs modules here:
https://nodejs.org/api/modules.html

Ionic how can I create an mp3 file?

I'm writing a web app with Ionic framework and I'm trying to manage a record and play sounds mechanism. I'm using the following snippet as a service:
.factory('MediaSrv', function ($q, $ionicPlatform, $window) {
var service = {
loadMedia: loadMedia,
getStatusMessage: getStatusMessage,
getErrorMessage: getErrorMessage
};
function loadMedia (src, onError, onStatus, onStop) {
var defer = $q.defer();
$ionicPlatform.ready(function () {
var mediaSuccess = function () {
if (onStop) { onStop(); }
};
var mediaError = function (err) {
_logError(src, err);
if (onError) { onError(err); }
};
var mediaStatus = function (status) {
if (onStatus) { onStatus(status); }
};
if ($ionicPlatform.is('android')) {
src = '/android_asset/www/' + src;
}
defer.resolve(new $window.Media(src, mediaSuccess, mediaError, mediaStatus));
});
return defer.promise;
}
...
return service;
});
I'm able to play an existing .mp3 file, but I cannot record on a non-existing file. I thought it would create the file by itself if the file wasn't found. How can I create an empty .mp3 file for recording?
Creating a file is a server function. You would need a node server using fs to create a file.
From Ionic's website:
Think of Ionic as the front-end UI framework that handles all of the look and feel and UI interactions your app needs in order to be compelling. Kind of like "Bootstrap for Native," but with support for a broad range of common native mobile components, slick animations, and beautiful design.
Ionic can use the Cordova plugins since its built on top of it.
You can use the media-capture plugin to capture audio, however I have found these record as AMR files.
From the [documentation][1]:
// capture callback
var captureSuccess = function(mediaFiles) {
var i, path, len;
for (i = 0, len = mediaFiles.length; i < len; i += 1) {
path = mediaFiles[i].fullPath;
// do something interesting with the file
}
};
// capture error callback
var captureError = function(error) {
navigator.notification.alert('Error code: ' + error.code, null, 'Capture Error');
};
// start audio capture
navigator.device.capture.captureAudio(captureSuccess, captureError, {limit:2});
[1]: http://docs.phonegap.com/en/edge/cordova_media_capture_capture.md.html

Categories