How to turn off strongloop loopback-testing console logging? - javascript

I have a very simple test case of API done with usage of loopback-testing module.
lt = require('loopback-testing')
assert = require('assert')
describe '/profile', ->
lt.beforeEach.withApp app
lt.describe.whenCalledRemotely 'GET', '/api/profiles/ping', { data: 'test' }, ->
lt.it.shouldBeAllowed()
it 'should have statusCode 200', ->
assert.equal #res.statusCode, 200
it 'should have pong response', ->
assert.equal #res.body.pong, 'test'
and as result of testing I'm getting printed lines at the system console like this ones:
/profile
GET /api/profiles/ping
GET /api/profiles/ping 200 50.639 ms - 15
✓ should be allowed
GET /api/profiles/ping 200 8.026 ms - 15
✓ should have statusCode 200
GET /api/profiles/ping 200 3.633 ms - 15
✓ should have pong response
Is there a way to turn off writing these lines to system console by loopback-testing module? It's simply trashes my mocha reports overview.

Do you have any logging middleware configured in your application? The extra lines look like HTTP access logs produced by morgan.
You need to disable any HTTP logging middleware in your application when running the tests. The instructions for that depend on how you have configured this middleware, could you please extend your question and describe your app setup?

Related

Taiko/Gauge with Javascript unable to use Axios for request

So I'm trying to use Axios to fetch some data before the test begins.
the test step is defined as follows
const axios = require('axios');
step("GET google", async function() {
await axios.get("https://www.google.com/")
});
And I have a test spec that looks like this
# Getting Started with Gauge
## GET google
* GET google
This is on a fresh Taiko/Gauge project. When running gauge runs specs I get the following error
Installing required plugins.
# Getting Started with Gauge
## GET google F
Failed Step: GET google
Specification: specs\test.spec:6
Error Message: AxiosError: Request failed with status code 400
Stacktrace:
And nothing else happens

Issue when asserting either of 2 response codes in Postman - pm.expect(pm.response.code).to.be.oneOf([200,409]);

I have some Postman tests using this assertion to check any of these 2 response codes 200 or 409
pm.test("Successful claim lodgement?", function () {
pm.expect(pm.response.code).to.be.oneOf([200,409]);
});
however when I run the Postman tests via Newman or Jenkins, my assertion fails when I get a valid code response 409.
MRJ - Claim (fire)
POST https://sandbox-api.iag.com.au/services/v1/digitalclaims/nrma/lodgeClaim [409 Conflict, 536B, 1462ms]
The error shown in the console is:
**expected response code to not be 4XX or 5XX**
Why is the assertion failing if the response is 409 valid??? The assertion seems validating "not to be"

Node JS VPN connect to endpoint

I hope you can help!
I have setup and Amazon echo applcation, the application makes a request to and AWS EC2 instance and gets JSON data as a response, this is working as expected however the use case for the final application is to connect to a private IP sending paramaters to an API to return the same JSON DATA.
for many reasons sadly I cannot share any of the endpoint information.
I need my NODE.js Application to make a request to the private IP over a VPN connection, Im currently using OPENVPN to make local requests to the endpoint.
I have looked at node packages to see if this is possible but I cannot seem to find one, except for this package here
https://www.npmjs.com/package/node-openvpn
This package is has a dependancy thats fails to download, so i got the node_module manually but Im getting an error when i try to execute the code
var openvpnmanager = require('node-openvpn');
var opts = {
host: 'xx.xx.xx.xx', // normally '127.0.0.1', will default to if undefined
port: 443, //port openvpn management console
timeout: 1500, //timeout for connection - optional, will default to 1500ms if undefined
logpath: 'log.txt' //optional write openvpn console output to file, can be relative path or absolute
};
var auth = {
user: '*******',
pass: '*******',
};
var openvpn = openvpnmanager.connect(opts)
openvpn.on('connected', function() { //will be emited on successful interfacing with openvpn instance
openvpnmanager.authorize(auth);
});
openvpn.on('console-output', function(output) { //emits console output of openvpn instance as a line
console.log(output)
});
openvpn.on('state-change', function(state) { //emits console output of openvpn state as a array
console.log(output)
});
// openvpnmanager.getLog(console.log) //get all console logs up to this point
// and finally when/if you want to
// openvpnmanager.disconnect();
openvpn.on('disconnected', function() { //emits on disconnect
openvpnmanager.destroy() //finally destroy the disconnected manager
});
this just gives me an error
Unhandled rejection TypeError: Cannot read property 'writable' of undefined
at Telnet.exec (C:\Users\user\Desktop\alexa- po\node_modules\node-openvpn\node_modules\telnet-client\lib\telnet- client.js:90:24)
If anybody has any suggetions on how to make this possible I would be very grateful.

Qunit testing an Ember.js app with ember-simple-auth authentication?

So, Am writing a Qunit test (with teaspoon as the test runner), for an Ember application that uses ember-simple-auth gem for login authintication, My test is as follows (coffee script) :
#= require qunit_spec_helper
test "Employee signs in", ->
expect(1)
visit("/login").then(->
fillIn "input.email", "employee1#example.com"
).then(->
fillIn "input.user_password", "password1"
).then(->
click "button.btn-primary"
).andThen ->
equal(find('h2').length,1, "Welcome to the App")
And here is the Test helper:
QUnit.testStart ->
Ember.run ->
App.reset()
Ember.testing = true
App.setupForTesting()
App.injectTestHelpers()
QUnit.testDone ->
Ember.testing = false
QUnit.done ->
Ember.run ->
App.reset()
When I run the test (keeping any eye on the console), I get the following error:
POST http://localhost:3000/teaspoon/qunit/oauth/token 404 (Not Found)
I can't seem to be able to login, No matter what ..
I ran out of ideas, Any help/Advice is highly Appreciated :)
Ember.SimpleAuth makes a request against the server to authenticate the session when the button is clicked - the route isn't handled by your server though (or the server isn't running at all maybe?) I'd stub the token endpoint for testing, find an example e.g. here: https://github.com/digitalplaywright/eak-simple-auth/blob/master/tests/acceptance/login-test.js

Karma/Jasmine Tests and dropbox authentication in javascript

I'm attempting to create some tests using Karma and Jasmine for a javascript application that uses the Dropbox Datastore api.
Here is a simplified test using the introductory Dropbox code from https://www.dropbox.com/developers/datastore/tutorial/js
I've manually authorized the application with Dropbox in the browser before running the test, but when I run the test, it says the client is not authenticated and no error occurs. Is there something extra that needs to be done for it to authenticate when running the tests?
'use strict';
describe('dropbox', function () {
var client = null;
beforeEach(function() {
client = new Dropbox.Client({key: '46tjf8x15q98xic'});
// Try to finish OAuth authorization.
client.authenticate({interactive: false}, function (error) {
if (error) {
alert('Authentication error: ' + error);
}
});
});
it('client is not null', function() {
expect( client ).not.toBeNull();
});
it('authenticated is true', function() {
expect( client.isAuthenticated() ).toEqual( true );
});
});
Running "karma:unit" (karma) task
INFO [karma]: Karma v0.10.9 server started at http://localhost:8080/
INFO [launcher]: Starting browser Chrome
INFO [Chrome 33.0.1750 (Mac OS X 10.9.2)]: Connected on socket BKoS8rqqeeL7fg3cHEQl
Chrome 33.0.1750 (Mac OS X 10.9.2) dropbox authenticated is true FAILED
Expected false to equal true.
Error: Expected false to equal true.
at null.<anonymous> (/Users/davidsmith/Sites/myapp/test/spec/dropbox.js:23:38)
Chrome 33.0.1750 (Mac OS X 10.9.2): Executed 2 of 2 (1 FAILED) (0.301 secs / 0.009 secs)
Warning: Task "karma:unit" failed. Use --force to continue.
Aborted due to warnings.
So, to be able to run the tests, I looked at the local storage for my browser and copied my app's dropbox key/value pair.
In my test script, I added that key/value pair with
var value = '{"key":"46tjf8x15q98xic","token":"srMz5w4ReBsAAAAAAAAAAWfQfibrbJfeI7LVKsbMvxRfX1pdpS6SOKqvN6DcgK1B","uid":"1407454"}';
localStorage.setItem('dropbox-auth:default:cHKvNCKVzU7Jmnyaj1InU8TBCOc', value );
Another related problem (not shown above) is that openDefaultDatastore is asyncronous so in my test script I added some code to wait until openDefaultDatastore finishes before running my tests.

Categories

Resources