diff --git a/package.json b/package.json index 4145c3b..4b02299 100644 --- a/package.json +++ b/package.json @@ -59,6 +59,10 @@ "main.js" ], "scripts": { + "test:js": "mocha --config test/mocharc.custom.json \"{!(node_modules|test)/**/*.test.js,*.test.js,test/**/test!(PackageFiles|Startup).js}\"", + "test:package": "mocha test/package --exit", + "test:integration": "mocha test/integration --exit", + "test": "npm run test:js && npm run test:package", "check": "tsc --noEmit -p tsconfig.check.json", "lint": "eslint .", "translate": "translate-adapter", diff --git a/test/integration.js b/test/integration.js new file mode 100644 index 0000000..1b3453e --- /dev/null +++ b/test/integration.js @@ -0,0 +1,5 @@ +const path = require('path'); +const { tests } = require('@iobroker/testing'); + +// Run integration tests - See https://github.com/ioBroker/testing for a detailed explanation and further options +tests.integration(path.join(__dirname, '..')); diff --git a/test/mocha.setup.js b/test/mocha.setup.js new file mode 100644 index 0000000..7bc1808 --- /dev/null +++ b/test/mocha.setup.js @@ -0,0 +1,14 @@ +// Don't silently swallow unhandled rejections +process.on('unhandledRejection', (e) => { + throw e; +}); + +// enable the should interface with sinon +// and load chai-as-promised and sinon-chai by default +const sinonChai = require('sinon-chai'); +const chaiAsPromised = require('chai-as-promised'); +const { should, use } = require('chai'); + +should(); +use(sinonChai); +use(chaiAsPromised); diff --git a/test/mocharc.custom.json b/test/mocharc.custom.json new file mode 100644 index 0000000..f01dabb --- /dev/null +++ b/test/mocharc.custom.json @@ -0,0 +1,4 @@ +{ + "require": ["test/mocha.setup.js"], + "watch-files": ["!(node_modules|test)/**/*.test.js", "*.test.js", "test/**/test!(PackageFiles|Startup).js"] +} diff --git a/test/package.js b/test/package.js new file mode 100644 index 0000000..38eacc8 --- /dev/null +++ b/test/package.js @@ -0,0 +1,5 @@ +const path = require('path'); +const { tests } = require('@iobroker/testing'); + +// Validate the package files +tests.packageFiles(path.join(__dirname, '..')); diff --git a/test/tsconfig.json b/test/tsconfig.json new file mode 100644 index 0000000..0fa051d --- /dev/null +++ b/test/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../tsconfig.json", + "compilerOptions": { + "noImplicitAny": false + }, + "include": ["./**/*.js"] +}