Skip to content

Commit

Permalink
add unit tests for contrib loading utils routine
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve-Mcl committed Sep 11, 2024
1 parent c520ceb commit 12d43a2
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 0 deletions.
20 changes: 20 additions & 0 deletions test/nodes/fixtures/contrib-node/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "@me/node-red-dashboard-2-two-widgets",
"version": "1.0.0",
"description": "My dashboard 2 test node package",
"node-red-dashboard-2": {
"version": "1.0.0",
"widgets": {
"ui-widget-1": {
"output": "ui-widget-1.js",
"component": "ui-widget-1"
},
"ui-widget-2": {
"output": "ui-widget-2.js",
"component": "ui-widget-2"
}
}
},
"author": "Your Name",
"license": "Apache-2.0"
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions test/nodes/fixtures/contrib-nodes/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "@me/my-2-widgets",
"version": "1.0.0",
"description": "My dashboard 2 test node",
"dependencies": {
"@me/node-red-dashboard-2-widget-a": "1.0.0",
"@me/node-red-dashboard-2-widget-b": "1.0.0"
},
"author": "Your Name",
"license": "Apache-2.0"
}
42 changes: 42 additions & 0 deletions test/nodes/utils.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const should = require('should') // eslint-disable-line no-unused-vars

const utils = require('../../nodes/utils/index.js')

describe('utils', function () {
describe('getThirdPartyWidgets', function () {
it('should load single node package', function () {
// this covers loading from a nodesDir source
const widgets = utils.getThirdPartyWidgets('test/nodes/fixtures/contrib-node')
widgets.should.be.an.Object()
widgets.should.have.properties(['ui-widget-1', 'ui-widget-2'])
widgets['ui-widget-1'].should.have.properties(['component', 'name', 'package', 'path', 'src'])
widgets['ui-widget-1'].component.should.equal('ui-widget-1')
widgets['ui-widget-1'].name.should.equal('ui-widget-1')
widgets['ui-widget-1'].package.should.equal('@me/node-red-dashboard-2-two-widgets')
widgets['ui-widget-1'].src.should.equal('ui-widget-1.js')

widgets['ui-widget-2'].should.have.properties(['component', 'name', 'package', 'path', 'src'])
widgets['ui-widget-2'].component.should.equal('ui-widget-2')
widgets['ui-widget-2'].name.should.equal('ui-widget-2')
widgets['ui-widget-2'].package.should.equal('@me/node-red-dashboard-2-two-widgets')
widgets['ui-widget-2'].src.should.equal('ui-widget-2.js')
})
it('should load nodes from a package dependencies', function () {
// this covers loading from node-red src package and from userDir package
const widgets = utils.getThirdPartyWidgets('test/nodes/fixtures/contrib-nodes')
widgets.should.be.an.Object()
widgets.should.have.properties(['widget-a', 'widget-b'])
widgets['widget-a'].should.have.properties(['component', 'name', 'package', 'path', 'src'])
widgets['widget-a'].component.should.equal('ui-widget-a')
widgets['widget-a'].name.should.equal('widget-a')
widgets['widget-a'].package.should.equal('@me/node-red-dashboard-2-widget-a')
widgets['widget-a'].src.should.equal('ui-widget.js')

widgets['widget-b'].should.have.properties(['component', 'name', 'package', 'path', 'src'])
widgets['widget-b'].component.should.equal('ui-widget-b')
widgets['widget-b'].name.should.equal('widget-b')
widgets['widget-b'].package.should.equal('@me/node-red-dashboard-2-widget-b')
widgets['widget-b'].src.should.equal('ui-widget.js')
})
})
})

0 comments on commit 12d43a2

Please sign in to comment.