From 41b9df7ad32c31beb60395fbbeb20119fb586a94 Mon Sep 17 00:00:00 2001 From: Anish Karandikar Date: Fri, 26 Oct 2018 15:42:55 -0400 Subject: [PATCH 1/7] chore: Sync from upstream (#1) * test: Scaffold out tests and related stuff * chore(ci): Use Node.js 8.12 (LTS) * chore(ci): Make coveralls upload optional * docs(readme): Add coveralls badge * Update badge links --- .circleci/config.yml | 9 ++++++++- .eslintrc.json | 3 ++- .gitignore | 3 +++ .nycrc | 7 +++++++ package.json | 7 +++++-- readme.md | 3 +++ test/lib.test.js | 8 ++++++++ test/mocha.opts | 1 + 8 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 .nycrc create mode 100644 test/lib.test.js create mode 100644 test/mocha.opts diff --git a/.circleci/config.yml b/.circleci/config.yml index ba4a8e8..7a397b2 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -2,7 +2,7 @@ version: 2 jobs: build: docker: - - image: circleci/node:7.10 + - image: circleci/node:8.12 steps: - checkout @@ -21,3 +21,10 @@ jobs: - run: npm run lint - run: npm run test + + ## Process test artifacts (reports, coverage etc) + - store_artifacts: + path: mochawesome-report + - run: (cat ./coverage/lcov.info | npx coveralls) || true + - store_artifacts: + path: coverage diff --git a/.eslintrc.json b/.eslintrc.json index e72c709..927169c 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -2,7 +2,8 @@ "extends": "airbnb-base", "root": true, "env": { - "node": true + "node": true, + "mocha": true }, "rules": { "no-const-assign": "warn", diff --git a/.gitignore b/.gitignore index 7d2a15b..4168c1a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,6 @@ data package-lock.json yarn.lock .vscode +coverage +.nyc_output +mochawesome-report diff --git a/.nycrc b/.nycrc new file mode 100644 index 0000000..47da9bf --- /dev/null +++ b/.nycrc @@ -0,0 +1,7 @@ +{ + "reporter": [ + "lcov", + "text", + "html" + ] +} diff --git a/package.json b/package.json index d56091e..da83b6b 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ ], "scripts": { "lint": "./node_modules/.bin/eslint .", - "test": "echo 'No tests yet'; exit 0" + "test": "nyc mocha" }, "main": "index.js", "bin": { @@ -45,6 +45,9 @@ "devDependencies": { "eslint": "^4.19.1", "eslint-config-airbnb-base": "^12.1.0", - "eslint-plugin-import": "^2.9.0" + "eslint-plugin-import": "^2.9.0", + "mocha": "^5.2.0", + "mochawesome": "^3.1.1", + "nyc": "^13.1.0" } } diff --git a/readme.md b/readme.md index 712471a..657b658 100644 --- a/readme.md +++ b/readme.md @@ -4,6 +4,7 @@ [![NPM Downloads][npm-dl-img]][npm-stat-url] [![MIT License][license-img]][license-link] [![Build status][circle-img]][circle-url] +[![Code coverage][coveralls-img]][coveralls-url] [npm-url]: https://npmjs.org/package/dbclone [npm-stat-url]: https://npm-stat.com/charts.html?package=dbclone @@ -11,6 +12,8 @@ [npm-dl-img]: https://img.shields.io/npm/dm/dbclone.svg [circle-img]: https://img.shields.io/circleci/project/github/vot/dbclone/master.svg [circle-url]: https://circleci.com/gh/vot/dbclone/tree/master +[coveralls-img]: https://img.shields.io/coveralls/github/vot/dbclone/master.svg +[coveralls-url]: https://coveralls.io/github/vot/dbclone?branch=master [license-img]: https://img.shields.io/badge/license-MIT-blue.svg [license-link]: https://spdx.org/licenses/MIT diff --git a/test/lib.test.js b/test/lib.test.js new file mode 100644 index 0000000..06c4f1e --- /dev/null +++ b/test/lib.test.js @@ -0,0 +1,8 @@ +const dbclone = require('../lib'); + +describe('Library tests', () => { + it('should import data', async () => { + console.log(dbclone); + // TODO: Add actual test + }); +}); diff --git a/test/mocha.opts b/test/mocha.opts new file mode 100644 index 0000000..8e3d39e --- /dev/null +++ b/test/mocha.opts @@ -0,0 +1 @@ +--reporter mochawesome From e799b8733de6819beda43f7e8a982358f18c68ba Mon Sep 17 00:00:00 2001 From: Anish Karandikar Date: Fri, 26 Oct 2018 16:23:32 -0400 Subject: [PATCH 2/7] test: Generate and store XML test results, MongoDB --- .circleci/config.yml | 7 ++++++- .gitignore | 3 +++ package.json | 2 ++ test/mocha-multi-reporter.config.json | 3 +++ test/mocha.opts | 3 ++- 5 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 test/mocha-multi-reporter.config.json diff --git a/.circleci/config.yml b/.circleci/config.yml index 7a397b2..1548f69 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,12 @@ jobs: - run: npm run test ## Process test artifacts (reports, coverage etc) + - store_test_results: + path: ~ - 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..fc0d232 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,9 @@ data package-lock.json yarn.lock .vscode + +## Test results, code coverage etc coverage .nyc_output mochawesome-report +test-results.xml diff --git a/package.json b/package.json index da83b6b..6a8b49c 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,8 @@ "eslint-config-airbnb-base": "^12.1.0", "eslint-plugin-import": "^2.9.0", "mocha": "^5.2.0", + "mocha-junit-reporter": "^1.18.0", + "mocha-multi-reporters": "^1.1.7", "mochawesome": "^3.1.1", "nyc": "^13.1.0" } diff --git a/test/mocha-multi-reporter.config.json b/test/mocha-multi-reporter.config.json new file mode 100644 index 0000000..5b21e5e --- /dev/null +++ b/test/mocha-multi-reporter.config.json @@ -0,0 +1,3 @@ +{ + "reporterEnabled": "spec, mochawesome, mocha-junit-reporter" +} 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 From bb89766b60b7978b51adf2fac2702e84639317e0 Mon Sep 17 00:00:00 2001 From: Anish Karandikar Date: Fri, 26 Oct 2018 16:33:09 -0400 Subject: [PATCH 3/7] test: Store XML result in test-results folder --- .circleci/config.yml | 2 +- .gitignore | 2 +- test/mocha-multi-reporter.config.json | 5 ++++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 1548f69..12b497e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -25,7 +25,7 @@ jobs: ## Process test artifacts (reports, coverage etc) - store_test_results: - path: ~ + path: test-results - store_artifacts: path: mochawesome-report - store_artifacts: diff --git a/.gitignore b/.gitignore index fc0d232..1000968 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,4 @@ yarn.lock coverage .nyc_output mochawesome-report -test-results.xml +test-results diff --git a/test/mocha-multi-reporter.config.json b/test/mocha-multi-reporter.config.json index 5b21e5e..c6982b3 100644 --- a/test/mocha-multi-reporter.config.json +++ b/test/mocha-multi-reporter.config.json @@ -1,3 +1,6 @@ { - "reporterEnabled": "spec, mochawesome, mocha-junit-reporter" + "reporterEnabled": "mochawesome, mocha-junit-reporter", + "mochaJunitReporterReporterOptions": { + "mochaFile": "test-results/mocha/results.xml" + } } From a92d100769ca27dfab2c1a3c46ee4715fec8c85c Mon Sep 17 00:00:00 2001 From: Anish Karandikar Date: Fri, 26 Oct 2018 16:37:02 -0400 Subject: [PATCH 4/7] chore(ci): Also store test-results as artifacts --- .circleci/config.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 12b497e..fea2a82 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -26,6 +26,8 @@ jobs: ## Process test artifacts (reports, coverage etc) - store_test_results: path: test-results + - store_artifacts: + path: test-results - store_artifacts: path: mochawesome-report - store_artifacts: From 7b09f5df2de6a40100696e05c712190ce9e3f959 Mon Sep 17 00:00:00 2001 From: Anish Karandikar Date: Mon, 29 Oct 2018 18:51:52 -0400 Subject: [PATCH 5/7] test(export): Test export from mLab URL --- .gitignore | 1 + package.json | 9 ++++++--- test/lib.test.js | 35 +++++++++++++++++++++++++++++++---- 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 1000968..c390f39 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ coverage .nyc_output mochawesome-report test-results +.env diff --git a/package.json b/package.json index 6a8b49c..fbcb616 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,13 +43,16 @@ "prompt": "^1.0.0" }, "devDependencies": { + "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..c81f284 100644 --- a/test/lib.test.js +++ b/test/lib.test.js @@ -1,8 +1,35 @@ +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, + }, (e, d) => { + console.log(`e = [${e}]`); + console.log(`d = [${d}]`); + resolve(); + }); + }); + }); }); }); From aed054df0eaaef2ccfee98fe4dd31f4f9a3e380e Mon Sep 17 00:00:00 2001 From: Anish Karandikar Date: Mon, 29 Oct 2018 18:54:43 -0400 Subject: [PATCH 6/7] refactor(typecast): Fix eslint warning object-shorthand --- lib/utils/typecast.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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; From 06533ffb79bb9de1407fde399b47c980ef98121d Mon Sep 17 00:00:00 2001 From: Anish Karandikar Date: Sat, 17 Nov 2018 19:24:52 -0500 Subject: [PATCH 7/7] test(export): Add chai assertion --- package.json | 1 + test/lib.test.js | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index f2c9497..f27af1b 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,7 @@ "mongodb": "^3.0.10" }, "devDependencies": { + "chai": "^4.2.0", "dotenv": "^6.1.0", "eslint": "^4.19.1", "eslint-config-airbnb-base": "^12.1.0", diff --git a/test/lib.test.js b/test/lib.test.js index c81f284..932d660 100644 --- a/test/lib.test.js +++ b/test/lib.test.js @@ -1,3 +1,4 @@ +const assert = require('chai').assert; require('dotenv').config(); const dbclone = require('../lib'); @@ -24,9 +25,18 @@ describe('Library tests', async () => { host: TEST_MLAB_URL, db: getDBNameFromURL(TEST_MLAB_URL), dataDir: DATADIR, - }, (e, d) => { - console.log(`e = [${e}]`); - console.log(`d = [${d}]`); + }, (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(); }); });