Start adding tests.

This commit is contained in:
Koenkk 2018-08-15 22:19:54 +02:00
parent fc2e93d96f
commit 9a70c95672
5 changed files with 2477 additions and 8 deletions

View File

@ -10,6 +10,10 @@
"rules": {
"require-jsdoc": "off",
"indent": ["error", 4],
"max-len": ["error", { "code": 120 }]
}
"max-len": ["error", { "code": 120 }],
"mocha/no-exclusive-tests": "error"
},
"plugins": [
"mocha"
]
}

View File

@ -11,11 +11,12 @@ node_js:
install:
- npm install
script:
before_script:
- npm test
- npm run verify-homeassistant-mapping
- npm run eslint
after_success:
script:
- ".travis/docker.sh"
- ".travis/wiki.sh"
- ".travis/trigger-downstream.sh"

2433
npm-shrinkwrap.json generated

File diff suppressed because it is too large Load Diff

View File

@ -17,10 +17,12 @@
"cc2531"
],
"scripts": {
"start": "node index.js",
"coverage": "nyc --all report --reporter=text mocha --recursive --timeout=3000",
"docgen": "node support/docgen.js",
"verify-homeassistant-mapping": "node support/verify-homeassistant-mapping.js",
"eslint": "node_modules/.bin/eslint ."
"eslint": "node_modules/.bin/eslint .",
"start": "node index.js",
"test": "mocha --recursive",
"verify-homeassistant-mapping": "node support/verify-homeassistant-mapping.js"
},
"author": "Koen Kanters",
"license": "GPL-3.0",
@ -40,7 +42,13 @@
"zigbee-shepherd-converters": "*"
},
"devDependencies": {
"chai": "*",
"chai-spies": "*",
"eslint": "*",
"eslint-config-google": "*"
"eslint-config-google": "*",
"eslint-plugin-mocha": "*",
"mocha": "*",
"nyc": "*",
"proxyquire": "*"
}
}

23
test/data.test.js Normal file
View File

@ -0,0 +1,23 @@
/* global describe, it */
const chai = require('chai');
const proxyquire = require('proxyquire').noPreserveCache();
const data = () => proxyquire('../lib/util/data.js', {});
const path = require('path');
describe('Data', () => {
describe('Get path', () => {
it('Should return correct path', () => {
const expected = path.normalize(path.join(__dirname, '..', 'data'));
const actual = data().getPath();
chai.assert.strictEqual(actual, expected);
});
it('Should return correct path when ZIGBEE2MQTT_DATA set', () => {
const expected = path.join('var', 'zigbee2mqtt');
process.env.ZIGBEE2MQTT_DATA = expected;
const actual = data().getPath();
chai.assert.strictEqual(actual, expected);
});
});
});