Context:
deno 1.13.2 (release, aarch64-apple-darwin) => on mac m1.
v8 9.3.345.11.
typescript 4.3.5
I'm very new with superoak and Deno tests, so I have just started with a very simple test... but this test fails.
import { Application, Router, RouterContext } from "https://deno.land/x/oak#v9.0.0/mod.ts";
import { superoak } from "https://deno.land/x/superoak#4.4.0/mod.ts";
const router = new Router();
router.get("/", (ctx: RouterContext) => {
ctx.response.body = "Hello Deno!";
});
const app = new Application();
app.use(router.routes());
app.use(router.allowedMethods());
// Send simple GET request
Deno.test("it will allow you to make assertions if you await it", async () => {
const request = await superoak(app);
await request.get("/").expect(200).expect("Hello Deno!");
});
So, as you can see, it comes from the superoak doc.
My result is similar to this issue on github, but I do an action after the get("/"). So, I don't see what I'm missing.
deno test --allow-env --allow-net ./src/app.test.ts
Check file:///Users/manu/workspace/zikstock-core/src/app.test.ts
running 1 test from file:///Users/manu/workspace/zikstock-core/src/app.test.ts
test it will allow you to make assertions if you await it ... FAILED (14ms)
failures:
it will allow you to make assertions if you await it
AssertionError: Test case is leaking async ops.
Before:
- dispatched: 2
- completed: 2
After:
- dispatched: 11
- completed: 10
Make sure to await all promises returned from Deno APIs before
finishing test case.
at assert (deno:runtime/js/06_util.js:42:13)
at asyncOpSanitizer (deno:runtime/js/40_testing.js:48:7)
at async resourceSanitizer (deno:runtime/js/40_testing.js:72:7)
at async exitSanitizer (deno:runtime/js/40_testing.js:99:9)
at async runTest (deno:runtime/js/40_testing.js:215:7)
at async Object.runTests (deno:runtime/js/40_testing.js:283:22)
at async file:///Users/manu/workspace/zikstock-core/01336b7f-6f80-4dfc-a186-d813c04240e0$deno$test.js:4:1
failures:
it will allow you to make assertions if you await it
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out
My first surprise is that the test fails, even before having the error after the failures list.
Indeed, If I do a test which I known will fail, the result seems ok:
Deno.test("it will allow you to make assertions if you await it", async () => {
const request = await superoak(app);
const result = await request.get("/");
console.log(`Is the test ok? ${result.text === "Hello Deno!"}`);
assert(result.text === "Hello Deno!");
});
Result:
deno test --allow-env --allow-net ./src/app.test.ts
Check file:///Users/manu/workspace/zikstock-core/src/app.test.ts
running 1 test from file:///Users/manu/workspace/zikstock-core/src/app.test.ts
test it will allow you to make assertions if you await it ...Is the test ok? true
FAILED (14ms)
...
I guess it's very easy to find but need help to see it :-) Anybody can help me?
Related
I'm trying to add jest acceptance testing into an API repo (currently there are jest unit tests). The app is serverless aws. I'm working on getting a rough working p.o.c. API test against a staging url and I've put together this test file but it isn't working as expected and I don't have details to go on. I'd like to know how to return more details for a failure or what I'm missing to get it to hit the route as expected.
I'm returning 500 errors, but no real extra details. If I input an empty/invalid jwt token - still returns 500. If I remove the expect(response.status).toEqual(200); it "passes" but the console.log("blah blah blah here" + response); fails to show the response (or the "blah blah blah" for that matter). How can I return more details to see what I may be missing? Or adjust my request so it successfully hits that route and returns a better response?
My auth_impersonation p.o.c. test
import { agent as request } from 'supertest';
import express = require('express');
describe('Impersonate SE merchant', () => {
let app: express.Application = express();
let jwtToken = 'string I'm putting in manually for now';
it('returns a valid access token', async () => {
// within it block attempts here (below)
const response = await request(app)
.get('full staging url string here')
.auth(jwtToken, {type: 'bearer'});
console.log("blah blah blah here" + response);
// expect(response.status).toEqual(200);
})
});
Here's how the request looks in postman where the route works
Another go of the postman request, headers
I am trying to list objects and if this works later download/upload files to AWS S3. The code below throws an error. What am I doing incorrectly that this doesn't work? I've passed the accessKeyId and accessSecretKey in all possible ways below. I have a config and credentials file on mac and on windows I have just one awscredentials file and also set this on my windows
setx AWS_SDK_LOAD_CONFIG=1
CODE
const AWS = require('aws-sdk');
function listS3Objects(file, name, type) {
const s3bucket = new AWS.S3({
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
accessSecretKey: process.env.AWS_SECRET_ACCESS_KEY,
// accessKeyId: 'my actual key in credentials file', //aws_access_key_id
// accessSecretKey: 'my actual secret key in credentials file', //aws_secret_access_key
region: "ap-southeast-1"
});
const params = {
Bucket: 'testbucketName',
};
s3bucket.listObjects(params, (err, data) => {
if (err) { throw err; }
/* eslint-disable no-console */
console.log('Success!');
console.log(data);
return data;
/* eslint-enable no-console */
});
}
const objs = listS3Objects()
//Test AWS Credentials
it('Tests', () => {
cy.log(objs)
})
ERROR
The following error originated from your test code, not from Cypress.
Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1
When Cypress detects uncaught errors originating from your test code it will automatically fail the current test.
Cypress could not associate this error to any specific test.
We dynamically generated a new test to display this failure.
node_modules/aws-sdk/lib/config.js:400:1
398 |
399 | function credError(msg, err) {
400 | return new AWS.util.error(err || new Error(), {
| ^
401 | code: 'CredentialsError',
402 | message: msg,
403 | name: 'CredentialsError'
I'd troubleshoot it this way:
Can you run the script to upload or download separately? If not then its with the credentials.
if not credentials and this works perfectly can this script be imported into your spec and run? Let the script resolve and return a promise, then use the return value in your spec.
Refer this blog post.
Other options you could consider and cy.exec("aws command goes here")
Issue:
I am trying to get TestCafe to open an internal website that triggers a windows authentication pop up on opening, but the TestCafe built in Authentication feature doesn't work for some weird reason and the website complains with "401 - Unauthorized: Access is denied due to invalid credentials."
Note manually I can open the website with the same login credentials.
Also note the Authentication feature does work for other websites, and I am doing this at work, so there is a work proxy.
The site that TestCafe is failing to open up:
Is made up of a server name & port only & lives internally eg.
http://[ServerName]:[Port]
The Code:
Made up of 2 files....
The Test Script:
import {Selector} from 'testcafe';
fixture('My Test')
.page('http://[ServerIP]:[Port]/') // Also tried ('http://[ServerName]:[Port]')
.httpAuth({
username: 'domain\name',
password: 'password_here'
})
test ('Opening this internal site', async t => {
await t
.debug()
});
The Runner file:
const createTestCafe = require('testcafe');
let testcafe = null;
createTestCafe('localhost', '8081')
.then(tc => {
testcafe = tc;
const runner = testcafe.createRunner();
return runner
.src([
'My_Test.js'
])
.browsers('chrome')
.useProxy('webproxy01:8080', '[ServerIP]:[Port]') // I tried including the website that I want to test incase it needs to be ByPassed
.run({
skipJsErrors: true,
concurrency: 1
})
})
.then(failedCount => {
console.log(`Tests failed: ` + failedCount);
testcafe.close();
});
Just to add I've tried this too and it doesn't work either:
.httpAuth({
username: 'name',
password: 'password_here',
domain: 'domain_here',
workstation: 'computer_name'
})
Many thanks!
I'm currently experimenting testcafe for the first time, I use the testdriven.io course as an example, and I'm facing really slow tests.
For instance testcafe e2e/login.test.js which is basically a register and a login takes sometimes 6min to pass, which I found insanely slow compared to the 15s the author has in his course.
import {Selector} from 'testcafe';
const randomstring = require('randomstring');
const username = randomstring.generate();
const email = `${username}#test.com`;
const TEST_URL = process.env.TEST_URL;
fixture('/login').page(`${TEST_URL}/login`);
test(`should display the sign-in form`, async (t) => {
await t
.navigateTo(`${TEST_URL}/login`)
.expect(Selector('H1').withText('Login').exists).ok()
.expect(Selector('form').exists).ok()
});
test(`should allow a user to sign in`, async (t) => {
// register user
await t
.navigateTo(`${TEST_URL}/register`)
.typeText('input[name="username"]', username)
.typeText('input[name="email"]', email)
.typeText('input[name="password"]', 'test')
.click(Selector('input[type="submit"]'))
// log a user out
await t
.click(Selector('a').withText('Log Out'))
// log a user in
await t
.navigateTo(`${TEST_URL}/login`)
.typeText('input[name="email"]', email)
.typeText('input[name="password"]', 'test')
.click(Selector('input[type="submit"]'))
// assert user is redirected to '/'
// assert '/' is displayed properly
const tableRow = Selector('td').withText(username).parent();
await t
.expect(Selector('H1').withText('All Users').exists).ok()
.expect(tableRow.child().withText(username).exists).ok()
.expect(tableRow.child().withText(email).exists).ok()
.expect(Selector('a').withText('User Status').exists).ok()
.expect(Selector('a').withText('Log Out').exists).ok()
.expect(Selector('a').withText('Register').exists).notOk()
.expect(Selector('a').withText('Log In').exists).notOk()
// log a user out
await t
.click(Selector('a').withText('Log Out'))
// assert '/logout' is displayed properly
await t
.expect(Selector('p').withText('You are now logged out').exists).ok()
.expect(Selector('a').withText('User Status').exists).notOk()
.expect(Selector('a').withText('Log Out').exists).notOk()
.expect(Selector('a').withText('Register').exists).ok()
.expect(Selector('a').withText('Log In').exists).ok()
});
I tried with Firefox, same deal, albeit much faster, 44s.
(project-tOIAx_A8) ➜ testdriven-app git:(master) ✗ testcafe 'chromium' e2e/login.test.js
Using locally installed version of TestCafe.
(node:16048) ExperimentalWarning: The fs.promises API is experimental
Running tests in:
- Chrome 67.0.3396 / Linux 0.0.0
/login
✓ should display the sign in form
✓ should allow a user to sign in
2 passed (6m 15s)
I wish I could provide more info, went to the dev tools, inspected the console without noticing any error message except this one sometimes:
hammerhead.js:7 WebSocket connection to 'ws://192.168.1.195:38039/4wxhbvTF7!w!http%3A%2F%2F172.18.0.5/http://172.18.0.5/sockjs-node/444/2kjm15kn/websocket' failed: Error during WebSocket handshake: Unexpected response code: 400
, the waterfall looks like slow, is there a way to give a log report of it to help understand what cases this slowness ?
edit: I put a .debug() at beginning and at the end of the tests and save a Performance profile inside Firefox if that helps
edit2: this is a performance profile in chromium if that helps
I'm having issues while trying to send PhantomJS calls to servers from my Mocha testsuite.
Problem
I'm trying to use PhantomJS to do calls against an endpoint. I have the first call working.
But I have two problems:
The current script runs well for the first time, but consecutive runs when watching some files make the tests fail. Do do I solve this?
This does not seem like a nice way to do these tests, is there a better alternative?
Setup:
Gulp as watcher
gulp-mocha to run tests
phantom-sync to do some end2end testing
Mocha test file (simplified):
if(typeof process != 'undefined') {
var should = require('chai').should();
var _ps = require('phantom-sync');
var phantom = _ps.phantom;
var sync = _ps.sync;
}
describe('Login', function() {
this.timeout(5000);
it('should be able to open CMS', function(done) {
sync(function() {
var ph = phantom.create();
var page = ph.createPage();
var status = page.open('http://www.google.com'); // Get a default CMS url...
status.should.equal('success');
ph.exit();
return done();
});
});
it('should redirect after successful login');
});
Gulpfile (simplified):
gulp.task('test-develop', ['scripts'], function() {
return test(null, true);
});
var keepAlive = false;
function test(reporter, _keepAlive) {
keepAlive = _keepAlive;
return gulp.src('test/**/*.js')
.pipe(plugins.plumber())
.pipe(plugins.mocha({ reporter: reporter || 'spec' })
.on('error', onError));
}
function onError(err) {
console.log(err.toString());
if (keepAlive) {
this.emit('end');
} else {
// if you want to be really specific
process.exit(1);
}
}
gulp.task('watch-test', function() {
gulp.watch('test/**/*.js', ['test-develop']);
});
Errors:
➜ [project_dir] git:(feature/phantomjs-tests) ✗ gulp watch-test
[gulp] Using gulpfile [project_dir]/gulpfile.js
[gulp] Starting 'watch-test'...
[gulp] Finished 'watch-test' after 26 ms
[gulp] Starting 'scripts'...
[gulp] Finished 'scripts' after 530 ms
[gulp] Starting 'test-develop'...
Homepage
Menu
- should open without error
- should close without error
Login
✓ should be able to open CMS (2126ms)
- should capture wrong username
- should capture wrong password
- should capture wrong username & password
- should redirect after successful login
ArtobjectPage
#ArtobjectPage
- should save $container
- should call setupZoom
- should call setupInfoButton
- should call setupObjectData
1 passing (2s)
10 pending
[gulp] Finished 'test-develop' after 2.42 s
[gulp] Starting 'scripts'...
[gulp] Finished 'scripts' after 94 ms
[gulp] Starting 'test-develop'...
Homepage
Menu
- should open without error
- should close without error
Login
1) should be able to open CMS
- should capture wrong username
- should capture wrong password
- should capture wrong username & password
- should redirect after successful login
ArtobjectPage
#ArtobjectPage
- should save $container
- should call setupZoom
- should call setupInfoButton
- should call setupObjectData
0 passing (2ms)
10 pending
1 failing
1) Login should be able to open CMS:
TypeError: undefined is not a function
at sync ([project_dir]/node_modules/phantom-sync/node_modules/make-sync/lib/make-sync.js:132:10)
at Context.<anonymous> ([project_dir]/test/e2e/login.js:13:5)
at Test.Runnable.run ([project_dir]/node_modules/gulp-mocha/node_modules/mocha/lib/runnable.js:196:15)
at Runner.runTest ([project_dir]/node_modules/gulp-mocha/node_modules/mocha/lib/runner.js:374:10)
at [project_dir]/node_modules/gulp-mocha/node_modules/mocha/lib/runner.js:452:12
at next ([project_dir]/node_modules/gulp-mocha/node_modules/mocha/lib/runner.js:299:14)
at [project_dir]/node_modules/gulp-mocha/node_modules/mocha/lib/runner.js:309:7
at next ([project_dir]/node_modules/gulp-mocha/node_modules/mocha/lib/runner.js:247:23)
at Object._onImmediate ([project_dir]/node_modules/gulp-mocha/node_modules/mocha/lib/runner.js:276:5)
at processImmediate [as _immediateCallback] (timers.js:330:15)
[gulp] Error in plugin 'gulp-mocha': 1 test failed.
[gulp] Finished 'test-develop' after 85 ms
It ended up state being evil and Phantom not properly clearing it's cache & cookies when asked to.