Comments (12)
It looks like you're missing some of the configurations required by karma-electron
as documented in the README (i.e. preprocessors
, client.useIframe
). Please add those settings and see if that fixes it =/
https://github.com/twolfson/karma-electron#nodejscustom-integration
Additionally, can you verify that electron
does run well with those browserWindowOptions
outside of the karma-electron
context? (thus verifying it's karma-electron
that's the issue)
from karma-electron.
It looks like you're missing some of the configurations required by
karma-electron
as documented in the README (i.e.preprocessors
,client.useIframe
). Please add those settings and see if that fixes it =/https://github.com/twolfson/karma-electron#nodejscustom-integration
That's correct I had forgot the preprocessors, though I have added it now and still seem to get the same result (never reaching 'after' log)
This is the updated karma.conf.js (I copy pasted the config from readme to be 100% sure):
module.exports = function (config) {
config.set({
// Inside `karma.conf.js`
// Define our custom launcher for Node.js support
customLaunchers: {
CustomElectron: {
base: 'Electron',
browserWindowOptions: {
// DEV: More preferentially, should link your own `webPreferences` from your Electron app instead
webPreferences: {
// Preferred `preload` mechanism to expose `require`
preload: __dirname + '/preload.js',
// Alternative non-preload mechanism to expose `require`
nodeIntegration: true,
contextIsolation: false
// nativeWindowOpen is set to `true` by default by `karma-electron` as well, see #50
}
}
}
},
// Use our custom launcher
browsers: ['CustomElectron'],
// DEV: preprocessors is for backfilling `__filename` and local `require` paths
preprocessors: {
'**/*.js': ['electron']
},
// DEV: `useIframe: false` is for launching a new window instead of using an iframe
// In Electron, iframes don't get `nodeIntegration` priveleges yet windows do
client: {
useIframe: false,
mocha: {timeout: 60000},
},
frameworks: ['mocha'],
plugins: [require('karma-electron'), require('karma-mocha')],
basePath: './',
files: ['**/*.test.js'],
singleRun: true,
autoWatch: false,
port: 9371,
colors: true,
logLevel: config.LOG_INFO,
browserNoActivityTimeout: 60000,
browserDisconnectTimeout: 60000,
browserDisconnectTolerance: 5,
})
}
Additionally, can you verify that
electron
does run well with thosebrowserWindowOptions
outside of thekarma-electron
context? (thus verifying it'skarma-electron
that's the issue)
I ran the same browserWindowOptions with electron
command and it seems to work, it reaches the 'after' log. It's in this repo: https://github.com/estebanabaroa/karma-electron-sqlite3-bug
git clone https://github.com/estebanabaroa/karma-electron-sqlite3-bug.git && cd karma-electron-sqlite3-bug
yarn
yarn electron # electron main.js -> works
yarn test # karma start -> fails
from karma-electron.
Thank you for providing the repo to reproduce the issue. Unfortunately, I don't have time/bandwidth to attempt to reproduce the issue and dig into it if I can reproduce it =/
Can you keep attempting to debug the issue? Usually at this point I'd try a few things:
- Set
show: true
, use Karma's debug window, and look for any obvious errors in the Dev Tools console - Verify that a basic synchronous action works as expected
- Verify that a non Node.js specific asynchronous action works as expected
I hope this helps =/
from karma-electron.
Thank you for providing the repo to reproduce the issue. Unfortunately, I don't have time/bandwidth to attempt to reproduce the issue and dig into it if I can reproduce it =/
Can you keep attempting to debug the issue? Usually at this point I'd try a few things:
* Set `[show: true](https://github.com/twolfson/karma-electron#launcher-configuration)`, use Karma's debug window, and look for any obvious errors in the Dev Tools console
I already tried that unfortunately. Show doesn't change the behavior. The debug window stays blank. The dev tool console becomes "disconnected" as soon as the function is called and doesn't give any logs. Karma with LOG_DEBUG also doesn't say anything related to sqlite3 or shows any error, it just stalls.
* Verify that a basic synchronous action works as expected
I think I'm calling the only available method of sqlite3 at this point, which is to create the db, I'm not sure there's any other method I can call but I dont know this library well.
* Verify that a non Node.js specific asynchronous action works as expected
It works in both node and regular electron, just not karma-electron.
I hope this helps =/
I'm guessing the issue is due to sqlite3 using native modules and it not working somehow. If you have any other ideas for debugging let me know.
from karma-electron.
I gave it a whirl and can confirm something is weird with the electron
configuration. I really should document the whole "green bar" setup that Karma has as well as needing singleRun: false
but I'm assuming you got to that step just fine based on the message =/
from karma-electron.
Hmm, I just gave electron@12
a shot and it seems to work fine, so it might be time for an upgrade on our electron
support in this repo =/
Going to reopen this issue with that premise. I don't have time to pick this up any further sadly =/
If you have bandwidth, feel free to give it a shot (and let me know)
Edit: I will address this some time within the next 2 weeks, if it's not addressed by others sooner
from karma-electron.
Hmm, I just gave
electron@12
a shot and it seems to work fine, so it might be time for an upgrade on ourelectron
support in this repo =/Going to reopen this issue with that premise. I don't have time to pick this up any further sadly =/
If you have bandwidth, feel free to give it a shot (and let me know)
Edit: I will address this some time within the next 2 weeks, if it's not addressed by others sooner
Are there any instructions for using electron@12
? I wouldn't mind having to modify karma-electron
temporarily if I could get it to work in the meantime.
from karma-electron.
This package was last tested formally against electron@12
, https://github.com/twolfson/karma-electron/blob/7.2.0/package.json#L58
electron@12
docs can be found here: https://github.com/electron/electron/tree/v12.2.3/docs
If you're going to spend time trying to downgrade electron
on your app, it might be better spent to find what changed/broke this repo instead =/ Usually the changes are minor (e.g. moving from callback to Promise
, renamed an API)
from karma-electron.
Going to take a shot at the electron@20
upgrade/support now
from karma-electron.
Our test suite has broken in electron@15
, so digging into those docs now
from karma-electron.
Ah, sadly it was a red herring. Just a module.parent
change, and the test suite seems to work through electron@20
just fine (albeit looks like a slower launch for the Node.js integration pieces)
from karma-electron.
Yea, I'm quite confident the issue is in Electron and/or sqlite3
now ._. Maybe it has something to do with launching a new sqlite3
in an iframe? But if I update the test to do nothing:
describe('try sqlite3', () => {
it('try sqlite3', async () => {
console.log('before')
// await new Promise(resolve => {
// const db = new window.sqlite3.Database(':memory:')
// db.close(resolve)
// })
console.log('after')
})
})
Show the browser via show: true
:
browserWindowOptions: {
// DEV: More preferentially, should link your own `webPreferences` from your Electron app instead
webPreferences: {
// Preferred `preload` mechanism to expose `require`
preload: __dirname + '/preload.js',
// Alternative non-preload mechanism to expose `require`
nodeIntegration: true,
contextIsolation: false,
// nativeWindowOpen is set to `true` by default by `karma-electron` as well, see #50
},
show: true
}
and move to continuous mode:
singleRun: false,
Then I run npm test
and enter the debug window and run what would be in the promise, we get Electron disconnecting from Karma intensely:
const db = new window.sqlite3.Database(':memory:')
Closing this issue for now as it's very unlikely related to the launcher =/
from karma-electron.
Related Issues (20)
- How to use with karma-babel? HOT 27
- `electron` did show not nothing happen then HOT 1
- Can't import nodejs modules in an angular-cli project (Typescript) HOT 1
- Errors without stack traces coming from karma-electron? HOT 5
- running with ndb for debugging? HOT 2
- Unable to open Electron window using --show HOT 3
- Electron 5 nodeIntegration HOT 12
- Custom launcher `require` mechanism doesn't work HOT 4
- Module paths are messed up HOT 5
- Error: Karma plugin is meant to be used from within Angular CLI and will not work correctly outside of it HOT 1
- How to configure NODE_PATH for the Electron instance? HOT 24
- [feature] option like 'require', but for renderer processes. HOT 1
- Karma times out when using Electron 9 and client.useIframe = false HOT 20
- Non-context aware native modules in renderer will cause specs to error HOT 3
- [questions] Is Electron 12 supported? HOT 16
- electron V12.0.4---------require is not defined HOT 3
- ES Modules HOT 2
- "require is not defined" after update to karma-electron 7 / electron 12 HOT 12
- Regardless of the `browserWindowOptions.show` value, a window always opens. HOT 12
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from karma-electron.