Closed DNature closed 3 years ago
@narration-sd Please take a look at this
@DNature It seems to me that dialog
is an electron related module or function.
Therefore I suspect you have to import electron in your test script in order for it to work. Did you try this?
Check this also it can be relevant: https://www.electronjs.org/docs/api/dialog
On the surface, looks @jurra is likely on the right traiil with this. As far as I know dialog works fine - it's in use, and the Electron side is solid.
Whether you can fix your case by simply importing it is a good question -- if the tests may not be running on an active Electron interface. You'll have to learn the details and so forth to understand.
If you can't solve this readily, I may have an idea coming from the outside, but let's see what you discover.
I imported the dialog module from electron but it still did not work, I also tried the remote module but it didn't work.
import { createLocalVue } from '@vue/test-utils';
const { dialog } = require('electron').remote;
import Vuex from 'vuex';
import * as docs from '../docs';
const localVue = createLocalVue();
localVue.use(Vuex);
describe('Test for docs operations', () => {
const store = new Vuex.Store({
modules: {
docs
}
});
console.log(dialog);
console.log(store.state.actions.cwd);
});
I also noticed that habitat client
does not include electron
as a dependency, therefore, destructuring dialog
will not work.
I found this solution https://github.com/electron/electron/issues/3909#issuecomment-568048005
Divine, I think it's more a nature of what is actually running, operating, than of importing libraries.
In fact, you should not, and should not have to be, importing anything but the habitat-client -- it would be at least redundant, and at worst interfere.
Electron is a quite complex multi-thread-process machine, with much internal interaction expected, and it's not going to work for you unless it's all properly initiated and operating.
In this test you are trying to do, is there a fully running Electron user interface showing on a terminal? Probably not. Then you need to do as we do in the software profession, look for what other persons make available for the problem, have themselves done.
Especially, put the calm time in, to well understand, assimilate what we find.
I made a simple Google query ('unit testing Electron applications') and immediately found these two links. The first is a useful overview, minus the later part which is selling. The second is the free testing framework that he is talking about, which is built into Electron, Spectron.
https://smartbear.com/blog/how-to-test-electron-apps/
https://www.electronjs.org/spectron
At first glance, anyway, Spectron appears to be fully aware and ready to help you for tests that involve with the multi-threads and the ui -- as they should understand the challenge
Thank you for the spectron
package you suggested @narration-sd . I never knew that electron has a different test system.
I will definitely look into it ASAP
We made a first progress and learned how to test vuex with jest using mocks without having to depend on electron to do the tests. But we might need to test also electron features like ipc messaging, and for this particular case we need to use spectron.
I was in the process of writing the first test for
hardocs-desktop-app
and this must includeVuex store
; However, I'm getting this error and it's pointing tohabitat-client
:Steps to reproduce the issue
feature/testing
branchyarn
yarn test
Screenshot