diff --git a/.circleci/config.yml b/.circleci/config.yml index 7a397b2..fea2a82 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,6 +3,7 @@ jobs: build: docker: - image: circleci/node:8.12 + - image: circleci/mongo:3.4 steps: - checkout @@ -23,8 +24,14 @@ jobs: - run: npm run test ## Process test artifacts (reports, coverage etc) + - store_test_results: + path: test-results + - store_artifacts: + path: test-results - store_artifacts: path: mochawesome-report - - run: (cat ./coverage/lcov.info | npx coveralls) || true - store_artifacts: path: coverage + - run: + name: Upload code coverage + command: (cat ./coverage/lcov.info | npx coveralls) || true diff --git a/.gitignore b/.gitignore index 4168c1a..c390f39 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,10 @@ data package-lock.json yarn.lock .vscode + +## Test results, code coverage etc coverage .nyc_output mochawesome-report +test-results +.env diff --git a/lib/utils/typecast.js b/lib/utils/typecast.js index b6a31a7..0af1ee5 100644 --- a/lib/utils/typecast.js +++ b/lib/utils/typecast.js @@ -36,7 +36,7 @@ function wrapSingleValue(value) { const wrapped = { type: detectedType, - value: value + value }; return wrapped; diff --git a/package.json b/package.json index 89c5e66..f27af1b 100644 --- a/package.json +++ b/package.json @@ -16,8 +16,8 @@ "migrate" ], "scripts": { - "lint": "./node_modules/.bin/eslint .", - "test": "nyc mocha" + "lint": "eslint *.js lib/**/*.js test/**/*.js", + "test": "npm run lint && nyc mocha" }, "main": "index.js", "bin": { @@ -43,11 +43,17 @@ "mongodb": "^3.0.10" }, "devDependencies": { + "chai": "^4.2.0", + "dotenv": "^6.1.0", "eslint": "^4.19.1", "eslint-config-airbnb-base": "^12.1.0", "eslint-plugin-import": "^2.9.0", + "mkdirp": "^0.5.1", "mocha": "^5.2.0", + "mocha-junit-reporter": "^1.18.0", + "mocha-multi-reporters": "^1.1.7", "mochawesome": "^3.1.1", - "nyc": "^13.1.0" + "nyc": "^13.1.0", + "rimraf": "^2.6.2" } } diff --git a/test/lib.test.js b/test/lib.test.js index 06c4f1e..932d660 100644 --- a/test/lib.test.js +++ b/test/lib.test.js @@ -1,8 +1,45 @@ +const assert = require('chai').assert; +require('dotenv').config(); + const dbclone = require('../lib'); +const rimraf = require('rimraf'); +const mkdirp = require('mkdirp'); + +const DATADIR = `data/${Math.random().toString(36).slice(2)}`; +const TEST_MLAB_URL = process.env.TEST_MLAB_URL; +const getDBNameFromURL = URL => URL.slice(URL.lastIndexOf('/') + 1); + +before(() => { + if (!TEST_MLAB_URL) { + throw new Error('TEST_MLAB_URL env var must be specified'); + } + rimraf.sync('data'); + mkdirp.sync(DATADIR); +}); -describe('Library tests', () => { - it('should import data', async () => { - console.log(dbclone); - // TODO: Add actual test +describe('Library tests', async () => { + describe('Export', async () => { + it('should export data from mLab URL', async () => { + await new Promise((resolve) => { + dbclone.export({ + host: TEST_MLAB_URL, + db: getDBNameFromURL(TEST_MLAB_URL), + dataDir: DATADIR, + }, (error, data) => { + assert.ok(!error, `Error was not null: ${error}`); + const expectedData = [{ + collection: 'system.indexes', + documents: 1 + }, + { + collection: 'bios', + documents: 10 + } + ]; + assert.deepEqual(data, expectedData, 'Returned data did not match expected value.'); + resolve(); + }); + }); + }); }); }); diff --git a/test/mocha-multi-reporter.config.json b/test/mocha-multi-reporter.config.json new file mode 100644 index 0000000..c6982b3 --- /dev/null +++ b/test/mocha-multi-reporter.config.json @@ -0,0 +1,6 @@ +{ + "reporterEnabled": "mochawesome, mocha-junit-reporter", + "mochaJunitReporterReporterOptions": { + "mochaFile": "test-results/mocha/results.xml" + } +} diff --git a/test/mocha.opts b/test/mocha.opts index 8e3d39e..aef3e01 100644 --- a/test/mocha.opts +++ b/test/mocha.opts @@ -1 +1,2 @@ ---reporter mochawesome +--reporter mocha-multi-reporters +--reporter-options configFile=test/mocha-multi-reporter.config.json