Skip to content

Commit 5ef667c

Browse files
First attempt to add a simple test
1 parent 7dea9a9 commit 5ef667c

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// import { expect } from 'chai'
2+
const {expect} = require('chai')
3+
// import rules from './index'
4+
const rules = require('./index')
5+
6+
const httpRule = rules['no-duplicate-http-in-urls']
7+
const reports = []
8+
const fakeContext = {
9+
report: ({ location, message }) => {
10+
console.log(`Error Report`)
11+
reports.push({location, message})
12+
}
13+
}
14+
15+
describe('', () => {
16+
const fakeFlowConfig = {}
17+
it('should report not report error if no nodes', () => {
18+
// Arrange
19+
const nodes = []
20+
const createdFunction = httpRule.create(fakeContext, fakeFlowConfig)
21+
// Act
22+
createdFunction.start(fakeFlowConfig)
23+
nodes.forEach(node => createdFunction["type:http in"](node))
24+
createdFunction.end(fakeFlowConfig)
25+
// Assert
26+
expect(reports.length).to.equal(0)
27+
})
28+
it('should report warning if two duplicate nodes', () => {
29+
// Arrange
30+
const nodeWithUrl = {
31+
config: {
32+
method: "GET",
33+
url: "http://nodered.org"
34+
}
35+
}
36+
const nodes = [{id:1, ...nodeWithUrl},{id:2, ...nodeWithUrl}]
37+
const createdFunction = httpRule.create(fakeContext, fakeFlowConfig)
38+
// Act
39+
createdFunction.start(fakeFlowConfig)
40+
nodes.forEach(node => createdFunction["type:http in"](node))
41+
createdFunction.end(fakeFlowConfig)
42+
// Assert
43+
expect(reports.length).to.equal(1)
44+
})
45+
})

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,14 @@
3737
"nrlint-rules-eslint": "dist/nrlint-rules-function-eslint.html"
3838
}
3939
},
40+
"mocha": {
41+
"spec": ["lib/rules/*.spec.js"]
42+
},
4043
"devDependencies": {
4144
"chai": "*",
4245
"fs-extra": "^10.0.0",
4346
"html-minifier": "^4.0.0",
47+
"mocha": "^9.1.3",
4448
"webpack": "^5.37.1",
4549
"webpack-cli": "^4.7.0"
4650
},

0 commit comments

Comments
 (0)