Comments (12)
That all looks good to me =/ We run our tests against these versions so it should just work. Sanity check: Have you upgraded to the latest karma-electron
as well? =/
from karma-electron.
I wonder if maybe it's a side-effect of karma-webpack. The new karma-webpack has an optimization that splits common dependencies into a shared module (the older version made a big bundle for every test file, each bundle having duplicates). This is what one test file looks like:
// /absoluteElementOperations.test.2135415586.js
"use strict";
(self["webpackChunklume"] = self["webpackChunklume"] || []).push([["ElementOperations.test.2135415586"],{},
/******/ __webpack_require__ => { // webpackRuntimeModules
/******/ var __webpack_exec__ = (moduleId) => (__webpack_require__(__webpack_require__.s = moduleId))
/******/ __webpack_require__.O(0, ["commons"], () => (__webpack_exec__("./dist/core/ElementOperations.test.js")));
/******/ var __webpack_exports__ = __webpack_require__.O();
/******/ module.exports = __webpack_exports__;
/******/ }
]);
It is loaded in the karma's html entrypoint like this:
<script type="text/javascript" src="/absoluteElementOperations.test.2135415586.js" crossorigin="anonymous"></script>
and it gives module is not defined
on module.exports
.
hm.
from karma-electron.
Yea, using webpack
to define its own require/import
while also expecting Electron/Node.js' require
to just work seems like a big headache to wrangle x_x
from karma-electron.
Oh.. My.. Goodness... those above options have to be inside the webPreferences
object. Doh!
browserWindowOptions: {
webPreferences: {
nodeIntegration: true,
nodeIntegrationInWorker: true,
nodeIntegrationInSubFrames: true,
contextIsolation: false,
}
},
It's all working smoothly now (but still with Webpack, and the output as CommonJS).
from karma-electron.
I still keep getting these errors, but only in debug mode with a window open, regardless if I have the proper config.
In "debug mode" I set singleRun
to false
, and browserWindowOptions.show
to true
. In this mode, even if client.loadScriptsViaRequire
is true
, I get require is not defined
.
When I run tests without debug mode enabled, console.log
statements that come after any require()
call show up in the terminal output just fine. It just isn't working in the debug window.
Any ideas?
from karma-electron.
Shot in the dark: It sounds like something in your singleRun: false
is messing with you (e.g. test environment isn't properly being cleaned, or maybe something is overzealously removing require
)
from karma-electron.
Hmm. Yeah, no idea why something would be different. This is the first file I have in files
:
// karma-augment-node-path.js
const path = require('path')
process.env.NODE_PATH = path.resolve(process.cwd(), 'node_modules') + ':' + process.env.NODE_PATH
require('module').Module._initPaths()
console.log('################################################################')
console.log('################################################################')
console.log('################################################################')
console.log('################################################################')
console.log('################################################################')
When I run with singleRun: true
, I see this in my terminal output:
...
22 09 2021 12:17:20.242:INFO [launcher]: Starting browser Electron
22 09 2021 12:17:20.669:INFO [Electron 14.0.1 (Node 14.17.0)]: Connected on socket eMIRJxV7RjNPNWytAAAB with id 67478283
Electron 14.0.1 (Node 14.17.0) LOG LOG: '################################################################'
Electron 14.0.1 (Node 14.17.0) LOG LOG: '################################################################'
Electron 14.0.1 (Node 14.17.0) LOG LOG: '################################################################'
Electron 14.0.1 (Node 14.17.0) LOG LOG: '################################################################'
Electron 14.0.1 (Node 14.17.0) LOG LOG: '################################################################'
...
When I run with singleRun: false
, I see this in my terminal, and similar in Electron console (just the require errors, not the other terminal output):
...
22 09 2021 12:28:40.750:INFO [launcher]: Starting browser Electron
22 09 2021 12:28:41.220:INFO [Electron 14.0.1 (Node 14.17.0)]: Connected on socket 8PCN10VDBPVkc12tAAAB with id 6745101
22 09 2021 12:28:56.969:WARN [Electron 14.0.1 (Node 14.17.0)]: Disconnected (0 times) Client disconnected from CONNECTED state (transport close)
Electron 14.0.1 (Node 14.17.0) ERROR
Disconnected Client disconnected from CONNECTED state (transport close)
22 09 2021 12:28:57.046:INFO [Electron 14.0.1 (Node 14.17.0)]: Connected on socket v_9MI5_w9DYWsB0dAAAD with id 6745101
Electron 14.0.1 (Node 14.17.0) ERROR
An error was thrown in afterAll
Uncaught ReferenceError: require is not defined
ReferenceError: require is not defined
at /home/trusktr/src/lume+lume/packages/cli/config/karma-augment-node-path.js:2:14
...
May the disconnected error have to do with it? I think that's just the open/refreshing of the debug window, right?
from karma-electron.
I confirm the only difference in my config is singleRun:true
(working) vs singleRun:false
(not working).
from karma-electron.
Ok, I found a clue, but not sure what it points to.
I noticed that when I first open the debug window and subsequently open the console, I see the expected ######...
output and no require is not defined
errors.
It is only after I refresh the debug window that the errors happen. All subsequent runs after the first have the error.
This explains why when singleRun
is true
the tests pass and the whole process exits with 0
; because the first run is always fine.
The combination of my mistake, plus the fact that refreshing the Electron breaks it, totally did not help because no matter what options I tried, even if they were correct, things continued to not work.
The question is, why are require
and friends not available after refresh of the Electron window? This seems like an Electron bug.
from karma-electron.
(No luck updating from Electron 14.0.1 to 15.0.0. Electron 15 completely crashes on any refresh attempt with devtools saying DevTools was disconnected from the page. Once page is reloaded, DevTools will automatically reconnect.
)
from karma-electron.
^ I think the issue is in Electron itself: karma-electron has launched Electron using new BrowserWindow
like normal, and it even all works fine on first run, but then a refresh of the window causes Node APIs (require
, module
, etc) to be is not defined
.
I don't think there is any possible option that karma-electron
could define that would cause Electron to disable Node integration upon refresh of an Electron window. I don't think there is any such Electron option for that behavior. Something seems wrong in Electron.
from karma-electron.
Now that we discovered setWindowOpenHandler
wasn't set so settings didn't propagate (#54), it might be worth trying out 7.1.0
to see if this fixes it. Though, I'm doubtful since our tests still didn't raise any issues =/
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
- Regardless of the `browserWindowOptions.show` value, a window always opens. HOT 12
- sqlite3 stalls with nodeIntegration true contextIsolation false 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.