vscode copilot shows an error while running generated test - vscode-extensions

I just write a JS like this.
modules.export = {
add(a, b){
return a + b;
},
}
it is quite simple and click Suggest a new test.
describe('test add', function() {
it('test add.exports', function(done) {
assert.equal(add.exports(1, 2), 3);
done();
})
})
I get this then Run this test.
RESULT
Could not find enclosing package.
I just joined subscription to github copilot, installed required library(like chai, mocha)
The error message is too simple so I googled this and try to find solution, I couldn't.
I want to know what the error message means.
I wonder "package 'main'" like golang at the top but this is JS.
Please give me a chance to continue using copilot labs.
Thankyou.

Related

How to be more verbose on tests?

I wanted to have more verbose output for each test step;
Any ideas on how could I best achieve this without adding console.log after each step ?
I tried to overload the t object as shown below but can't get to have it work more than one time in the output.
in mylib.js
exports.init = function(t) {
t.oTypeText = t.typeText;
t.typeText = function fn(selector, data, opts) {
console.log('typing text in '+selector+': '+data);
return t.oTypeText(selector, data, opts);
};
return;
};
in test.js
import { Selector } from 'testcafe';
const mylib = require('./mylib');
fixture("Getting Started")
.page("https://devexpress.github.io/testcafe/example");
test('My first test', async t => {
mylib.init(t);
await t.typeText('#developer-name', 'John Smith')
.selectText('#developer-name').pressKey('delete')
.typeText('#developer-name', 'new name')
.selectText('#developer-name').pressKey('delete')
.typeText('#developer-name', 'another name');
await t.click('#submit-button');
});
result is:
Using locally installed version of TestCafe.
Running tests in:
- Firefox 68.0.0 / Mac OS X 10.14.0
Getting Started
(node:62978) Warning: Setting the NODE_TLS_REJECT_UNAUTHORIZED environment variable to '0' makes TLS connections and HTTPS requests insecure by disabling certificate verification.
typing text in #developer-name: John Smith
✓ My first test
1 passed (4s)
TestCafe doesn't support this feature out of box. I've created suggestion for you use case - https://github.com/DevExpress/testcafe/issues/4001 in the TestCafe repository. We can use the way with action overriding right now, but theoretically it can broke some functionality.

mocha programmatically set vue error handler

I find myself writing this at the start of pretty much all of my unit tests in mocha:
it('should do something', (done) => {
Vue.config.errorHandler = done;
// do something aynchronous
});
By default, Vue catches all errors itself and logs them to the console, so mocha can't see them. This code makes sure that thrown errors fail the tests.
Is there a way with mocha to do this without having to start every single async test with this line of code? If I have to write / use a plugin, that's fine.
Try:
Vue.config.errorHandler = function (err, vm, info) {
throw err
}
in your test entry.

Need advice about testing using Chimp.js/Mocha in Meteor.js

I'm trying to teach myself testing with Meteor but there is so much conflicting and outdated info online it's really difficult to work out what I need to do.
My current situation it that I have an application using the latest Meteor version (and the imports folder structure).
I've installed chimp globally and have created a /tests directory.
My first test is using chimp/mocha to fill in a form and try to insert something to the database. I'm also using the xolvio/backdoor package and running chimp like so
chimp --ddp=http://localhost:3000 --mocha --path=tests
Here's my test code:
describe('Chimp Mocha', function() {
describe( 'Create a Client', function() {
it( 'should fill in add client form', function() {
browser.setValue('#clientName', 'Test')
.setValue('#clientEmail', 'test#test.com')
.selectByValue('#numberTeamMembers', '25')
.submitForm('#createClient')
});
it( 'should check the collections for new client data', function() {
let getClient = server.execute( function() {
return Clients.findOne({ name: 'Test' });
});
expect( getClient.name ).to.equal( 'Test' );
});
after( function() {
server.execute( function() {
let client = Clients.findOne( { name: 'Test' } );
if ( client ) {
Clients.remove( client._id );
}
});
});
});
});
This is throwing an error that Clients is undefined
However, if I add
import { Clients } from '/imports/api/clients/clients.js';
I get this error Error: Cannot find module '/imports/api/clients/clients.js'
What am I doing wrong? Should I be using chimp? Any help would really be appreciated because I don't find the Meteor guide very clear about this!
Thanks
You need to use require like this:
require('/imports/api/clients/clients').Clients
See here for an example.

ng-2 and ionic 2: Error while waiting for Protractor to sync with the page: "window.angular is undefined

I'm running a pretty basic Protractor test with Page Object scheming set up. But when I run my tests, I get the error described in the title. This is my spec file.
var tabs = require('../../pages/tabBar.page.js');
var dashboard = require('../../pages/dashboard.page.js');
describe('Dashboard - Nav', function() {
beforeEach(function() {
browser.ignoreSynchronization = false;
browser.waitForAngular();
})
it('Given I open the dashboard tab', function() {
browser.get('http://localhost:8100');
browser.refresh();
browser.sleep(2000);
expect(dashboard.salesButton.isDisplayed()).toBe(true);
browser.sleep(1000);
})
})
I can get it to run by setting ignoreSync to true, but the test is a lot slower due to some dependencies, and I don't see why I should have to anyway, it's all angular2/ionic2. Anyone able to help?
Homer Simpson: DOH
It would probably help if I loaded my page before waiting for Angular huh?
Thanks everyone for humoring me on this. As you were.

How to perfectly isolate and clear environments between each test?

I'm trying to connect to SoundCloud using CasperJS. What is interesting is once you signed in and rerun the login feature later, the previous login is still active. Before going any further, here is the code:
casper.thenOpen('https://soundcloud.com/', function() {
casper.click('.header__login');
popup = /soundcloud\.com\/connect/;
casper.waitForPopup(popup, function() {
casper.withPopup(popup, function() {
selectors = {
'#username': username,
'#password': password
};
casper.fillSelectors('form.log-in', selectors, false);
casper.click('#authorize');
});
});
});
If you run this code at least twice, you should see the following error appears:
CasperError: Cannot dispatch mousedown event on nonexistent selector: .header__login
If you analyse the logs you will see that the second time, you were redirected to https://soundcloud.com/stream meaning that you were already logged in.
I did some research to clear environments between each test but it seems that the following lines don't solve the problem.
phantom.clearCookies()
casper.clear()
localStorage.clear()
sessionStorage.clear()
Technically, I'm really interested about understanding what is happening here. Maybe SoundCloud built a system to also store some variables server-side. In this case, I would have to log out before login. But my question is how can I perfectly isolate and clear everything between each test? Does someone know how to make the environment unsigned between each test?
To clear server-side session cache, calling: phantom.clearCookies(); did the trick for me. This cleared my session between test files.
Example here:
casper.test.begin("Test", {
test: function(test) {
casper.start(
"http://example.com",
function() {
... //Some testing here
}
);
casper.run(function() {
test.done();
});
},
tearDown: function(test) {
phantom.clearCookies();
}
});
If you're still having issues, check the way you are executing your tests.
Where did you call casper.clear() ?
I think you have to call it immediately after you have opened a page like:
casper.start('http://www.google.fr/', function() {
this.clear(); // javascript execution in this page has been stopped
//rest of code
});
From the doc: Clears the current page execution environment context. Useful to avoid having previously loaded DOM contents being still active.