From e787b146e87b62a005c1fa99e916ee9062e38bba Mon Sep 17 00:00:00 2001 From: Sugat Bajracharya Date: Thu, 20 Jun 2024 16:30:17 +0545 Subject: [PATCH] Setup mocha hooks and add to npm run command --- package.json | 2 +- test/e2e/.mocharc.js | 20 ++++++++++++++++++++ test/e2e/hooks.js | 15 +++++++++++++++ test/e2e/placeholder.spec.js | 7 +++++++ test/e2e/specs.js | 5 +++++ 5 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 test/e2e/.mocharc.js create mode 100644 test/e2e/hooks.js create mode 100644 test/e2e/placeholder.spec.js create mode 100644 test/e2e/specs.js diff --git a/package.json b/package.json index 1962a14c..50390681 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "docker-start-couchdb": "npm run docker-stop-couchdb && docker run -d -p 6984:5984 --rm --name cht-conf-couchdb couchdb:2.3.1 && sh test/scripts/wait_for_response_code.sh 6984 200 CouchDB", "docker-stop-couchdb": "docker stop cht-conf-couchdb || true", "test": "npm run eslint && npm run docker-start-couchdb && npm run clean && mkdir -p build/test && cp -r test/data build/test/data && cd build/test && nyc --reporter=html mocha --forbid-only \"../../test/**/*.spec.js\" && cd ../.. && npm run docker-stop-couchdb", - "test-e2e": "npm run eslint && ./test/e2e/test_runner.sh", + "test-e2e": "npm run eslint && mocha --config test/e2e/.mocharc.js", "semantic-release": "semantic-release" }, "bin": { diff --git a/test/e2e/.mocharc.js b/test/e2e/.mocharc.js new file mode 100644 index 00000000..6ad8a1f9 --- /dev/null +++ b/test/e2e/.mocharc.js @@ -0,0 +1,20 @@ +const chaiExclude = require('chai-exclude'); +const chaiAsPromised = require('chai-as-promised'); +const chai = require('chai'); +chai.use(chaiAsPromised); +chai.use(chaiExclude); + +module.exports = { + allowUncaught: false, + color: true, + checkLeaks: true, + fullTrace: true, + asyncOnly: false, + spec: require('./specs').all, + timeout: 200 * 1000, //API takes a little long to start up + reporter: 'spec', + file: [ 'test/e2e/hooks.js' ], + captureFile: 'test/e2e/results.txt', + exit: true, + recursive: true, +}; diff --git a/test/e2e/hooks.js b/test/e2e/hooks.js new file mode 100644 index 00000000..a751b6e3 --- /dev/null +++ b/test/e2e/hooks.js @@ -0,0 +1,15 @@ +before(() => { + console.log('before'); +}); + +after(() => { + console.log('after'); +}); + +beforeEach(() => { + console.log('beforeEach'); +}); + +afterEach(() => { + console.log('afterEach'); +}); \ No newline at end of file diff --git a/test/e2e/placeholder.spec.js b/test/e2e/placeholder.spec.js new file mode 100644 index 00000000..f5154a76 --- /dev/null +++ b/test/e2e/placeholder.spec.js @@ -0,0 +1,7 @@ +const assert = require('assert'); + +describe('placeholder', () => { + it('checks if the mocha test setup works', () => { + assert.strictEqual(1, 1); + }); +}); \ No newline at end of file diff --git a/test/e2e/specs.js b/test/e2e/specs.js new file mode 100644 index 00000000..8deec4aa --- /dev/null +++ b/test/e2e/specs.js @@ -0,0 +1,5 @@ +module.exports = { + all: [ + 'test/e2e/**/*.spec.js' + ] +}; \ No newline at end of file