[BUG] Intermittent test failure on `dev` branch due to race condition
Question
I recommend adding --bail after the mocha command in package.json's test to make this easier to see, e.g.:
"test": "cross-env NODE_PATH=./src mocha --bail --compilers js:babel-core/register --require test/helper.js --timeout 10000 --recursive test/main.js",
On the latest dev branch, this is easy to reproduce by simply running npm test many times:
npm test && npm test && npm test && npm test && npm test && npm test && npm test && npm test && npm test && npm test && npm test && npm test && npm test && npm test && npm test && npm test && npm test && npm test && npm test
Sooner or later you will get:
1 failing
1) Main SelectorManager Views E2E tests "before each" hook:
Uncaught TypeError: this.get(...).getComponent is not a function
at child.getCss (src/editor/model/Editor.js:308:43)
at Object.store (src/css_composer/index.js:154:52)
at src/editor/model/Editor.js:345:19
at Array.forEach (<anonymous>)
at child.store (src/editor/model/Editor.js:344:27)
at child.updateChanges (src/editor/model/Editor.js:119:12)
at triggerEvents (node_modules/backbone/backbone.js:371:57)
at triggerApi (node_modules/backbone/backbone.js:356:19)
at eventsApi (node_modules/backbone/backbone.js:155:16)
at child.Events.trigger (node_modules/backbone/backbone.js:346:5)
at child.set (node_modules/backbone/backbone.js:516:16)
at Timeout._onTimeout (src/editor/model/Editor.js:187:14)
This seems to go away if you .skip this test in test/specs/selector_manager/e2e/ClassManager.js on line 74:
it.skip('Class imported into component is the same model from main container', function() {
var model = components.add({ classes: ['test1'] });
var clModel = model.get('classes').at(0);
var clModel2 = gjs.editor
.get('SelectorManager')
.getAll()
.at(0);
expect(clModel).toEqual(clModel2);
});
Of course, that's not a solution. But it may indicate what the underlying issue is. It looks like a race condition of some sort.
It also goes away if you comment out the event listeners editor/model/Editor.js:
// Load modules
deps.forEach(name => this.loadModule(name));
// this.on('change:selectedComponent', this.componentSelected, this);
// this.on('change:changesCount', this.updateChanges, this);
Perhaps the modules have not entirely loaded yet and there are already changes to be processed? Resulting in const wrp = this.get('DomComponents').getComponent(); on line 308 in Editor.js to throw.
Should we wait for all modules to have loaded prior to attaching the event listeners?
Answers (3)
I haven't seen this in a while. Will close for now.
Should we wait for all modules to have loaded prior to attaching the event listeners?
Mmmm that piece of code is running synchronously so I don't think it's gonna help
BTW never faced this issue within my environment 🤔
@artf it's easily reproducible here. Try to run it repeatedly as suggested above.
Here's proof:

My environment:
OSX High Sierra 10.13.3 Node.js v9.2.1 Latest rapes dev branch commit #e6593e7ad9a
For some reason this.get('DomComponents') returns null when it should return the wrapper on line 308 in editor/model/Editor.js
Related Questions and Answers
Continue research with similar issue discussions.
Issue #2044
Npm start to develop on local server didn't work
Did the procedure to start the local server using dev branch as described on README, it worked on the console, but fails on chrome and the...
Issue #440
Not works with jquery
I use jquery in my project. After version 0.12.8 it does not work with jquery. Prt of my webpack.config is; When I try to drop a block it t...
Issue #809
[Bug]: CSS not added when blocks are drag and dropped after core:canvas-clear command invoked
I'm using grapesjs-blocks-basic plugin that has a number of column blocks. When I drag and drop these blocs onto the canvas they are displa...
Issue #946
[Bug]: overflow:hidden on .gjs-block-label clips the text
Using dev@HEAD (https://github.com/artf/grapesjs/commit/9a71368f43d690405d3c60682c7dfee83fd87a4e) you can see that the Test block has it's...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.