From a6c87f6370dc25aa3df8ffb27c5fad3d5ab7e5c7 Mon Sep 17 00:00:00 2001 From: juhongchul Date: Tue, 15 Oct 2019 16:25:35 +0900 Subject: [PATCH 01/13] create migrate-opts --- .mocharc.json | 8 +++ .mocharc.yml | 2 +- lib/cli/cli.js | 2 + package-lock.json | 83 ++++++++++++++------------ package.json | 3 + scripts/migrate-opts-init.js | 8 +++ scripts/migrate-opts.js | 53 ++++++++++++++++ test/migrate-opts/.eslintrc | 9 +++ test/migrate-opts/migrate-opts.spec.js | 22 +++++++ test/migrate-opts/mocha.opts | 4 ++ 10 files changed, 155 insertions(+), 39 deletions(-) create mode 100644 .mocharc.json create mode 100644 scripts/migrate-opts-init.js create mode 100644 scripts/migrate-opts.js create mode 100644 test/migrate-opts/.eslintrc create mode 100644 test/migrate-opts/migrate-opts.spec.js create mode 100644 test/migrate-opts/mocha.opts diff --git a/.mocharc.json b/.mocharc.json new file mode 100644 index 0000000000..51417633c4 --- /dev/null +++ b/.mocharc.json @@ -0,0 +1,8 @@ +{ + "_": [], + "reporter": "dot", + "R": "dot", + "growl": true, + "G": true, + "extension": ["mjs", "js"] +} diff --git a/.mocharc.yml b/.mocharc.yml index fc4c97339c..d1fa84e872 100644 --- a/.mocharc.yml +++ b/.mocharc.yml @@ -4,4 +4,4 @@ global: - okGlobalA,okGlobalB - okGlobalC - callback* -timeout: 300 +timeout: 1000 diff --git a/lib/cli/cli.js b/lib/cli/cli.js index dee8e70dd4..233ff29a8e 100755 --- a/lib/cli/cli.js +++ b/lib/cli/cli.js @@ -18,6 +18,7 @@ const path = require('path'); const {loadOptions, YARGS_PARSER_CONFIG} = require('./options'); const commands = require('./commands'); const ansi = require('ansi-colors'); +const migrateOpts = require('../../scripts/migrate-opts-init'); const {repository, homepage, version, gitter} = require('../../package.json'); /** @@ -40,6 +41,7 @@ exports.main = (argv = process.argv.slice(2)) => { .scriptName('mocha') .command(commands.run) .command(commands.init) + .command(migrateOpts.init) .updateStrings({ 'Positionals:': 'Positional Arguments', 'Options:': 'Other Options', diff --git a/package-lock.json b/package-lock.json index ac164dbf11..a925fc12af 100644 --- a/package-lock.json +++ b/package-lock.json @@ -485,8 +485,8 @@ "abbrev": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", - "integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==", - "dev": true + "integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==", + "dev" : true }, "accepts": { "version": "1.3.5", @@ -2143,6 +2143,17 @@ "graceful-fs": "^4.1.2", "jsonfile": "^3.0.0", "universalify": "^0.1.0" + }, + "dependencies": { + "jsonfile": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-3.0.1.tgz", + "integrity": "sha1-pezG9l9T9mLEQVx2daAzHQmS7GY=", + "dev": true, + "requires": { + "graceful-fs": "^4.1.6" + } + } } }, "invert-kv": { @@ -3291,8 +3302,7 @@ "commander": { "version": "2.19.0", "resolved": "https://registry.npmjs.org/commander/-/commander-2.19.0.tgz", - "integrity": "sha512-6tvAOO+D6OENvRAh524Dh9jcfKTYDQAqvqezbCW82xj5X0pSrcpxtvRKHLG0yBY6SD7PSDrJaj+0AiOcKVd1Xg==", - "dev": true + "integrity": "sha512-6tvAOO+D6OENvRAh524Dh9jcfKTYDQAqvqezbCW82xj5X0pSrcpxtvRKHLG0yBY6SD7PSDrJaj+0AiOcKVd1Xg==" }, "comment-regex": { "version": "1.0.1", @@ -3394,7 +3404,6 @@ "version": "1.1.12", "resolved": "https://registry.npmjs.org/config-chain/-/config-chain-1.1.12.tgz", "integrity": "sha512-a1eOIcu8+7lUInge4Rpf/n4Krkf3Dd9lqhljRzII1/Zno/kRtUWnznPO3jOKBmTEktkt3fkxisUcivoj0ebzoA==", - "dev": true, "requires": { "ini": "^1.3.4", "proto-list": "~1.2.1" @@ -4744,7 +4753,6 @@ "version": "0.15.3", "resolved": "https://registry.npmjs.org/editorconfig/-/editorconfig-0.15.3.tgz", "integrity": "sha512-M9wIMFx96vq0R4F+gRpY3o2exzb8hEj/n9S8unZtHSvYjibBp/iMufSzvmOcV/laG0ZtuTVGtiJggPOSW2r93g==", - "dev": true, "requires": { "commander": "^2.19.0", "lru-cache": "^4.1.5", @@ -7310,8 +7318,7 @@ "graceful-fs": { "version": "4.1.15", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.15.tgz", - "integrity": "sha512-6uHUhOPEBgQ24HM+r6b/QwWfZq+yiFcipKFrOFiBEnWdy5sdzYoi+pJeQaPI5qOLRFqWmAXUPQNsielzdLoecA==", - "dev": true + "integrity": "sha512-6uHUhOPEBgQ24HM+r6b/QwWfZq+yiFcipKFrOFiBEnWdy5sdzYoi+pJeQaPI5qOLRFqWmAXUPQNsielzdLoecA==" }, "graceful-readlink": { "version": "1.0.1", @@ -8273,8 +8280,7 @@ "ini": { "version": "1.3.5", "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.5.tgz", - "integrity": "sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw==", - "dev": true + "integrity": "sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw==" }, "inkscape": { "version": "2.0.0", @@ -9100,10 +9106,9 @@ "dev": true }, "js-beautify": { - "version": "1.10.0", - "resolved": "https://registry.npmjs.org/js-beautify/-/js-beautify-1.10.0.tgz", - "integrity": "sha512-OMwf/tPDpE/BLlYKqZOhqWsd3/z2N3KOlyn1wsCRGFwViE8LOQTcDtathQvHvZc+q+zWmcNAbwKSC+iJoMaH2Q==", - "dev": true, + "version": "1.10.2", + "resolved": "https://registry.npmjs.org/js-beautify/-/js-beautify-1.10.2.tgz", + "integrity": "sha512-ZtBYyNUYJIsBWERnQP0rPN9KjkrDfJcMjuVGcvXOUJrD1zmOGwhRwQ4msG+HJ+Ni/FA7+sRQEMYVzdTQDvnzvQ==", "requires": { "config-chain": "^1.1.12", "editorconfig": "^0.15.3", @@ -9305,13 +9310,21 @@ "integrity": "sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus=", "dev": true }, + "json2yaml": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/json2yaml/-/json2yaml-1.1.0.tgz", + "integrity": "sha1-VBTZB/mBZYa4DFE+wuOusquBmmw=", + "requires": { + "remedial": "1.x" + } + }, "jsonfile": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-3.0.1.tgz", - "integrity": "sha1-pezG9l9T9mLEQVx2daAzHQmS7GY=", - "dev": true, + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-5.0.0.tgz", + "integrity": "sha512-NQRZ5CRo74MhMMC3/3r5g2k4fjodJ/wh8MxjFbCViWKFjxrnudWSY5vomh+23ZaXzAS7J3fBZIR2dV6WbmfM0w==", "requires": { - "graceful-fs": "^4.1.6" + "graceful-fs": "^4.1.6", + "universalify": "^0.1.2" } }, "jsonify": { @@ -10361,7 +10374,6 @@ "version": "4.1.5", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.5.tgz", "integrity": "sha512-sWZlbEP2OsHNkXrMl5GYk/jKk70MBng6UU4YI/qGDYbgf6YbP4EvmqISbXCoJiRKs+1bSpFHVgQxvJ17F2li5g==", - "dev": true, "requires": { "pseudomap": "^1.0.2", "yallist": "^2.1.2" @@ -11446,7 +11458,6 @@ "version": "4.0.1", "resolved": "https://registry.npmjs.org/nopt/-/nopt-4.0.1.tgz", "integrity": "sha1-0NRoWv1UFRk8jHUFYC0NF81kR00=", - "dev": true, "requires": { "abbrev": "1", "osenv": "^0.1.4" @@ -12315,8 +12326,7 @@ "os-homedir": { "version": "1.0.2", "resolved": "http://registry.npmjs.org/os-homedir/-/os-homedir-1.0.2.tgz", - "integrity": "sha1-/7xJiDNuDoM94MFox+8VISGqf7M=", - "dev": true + "integrity": "sha1-/7xJiDNuDoM94MFox+8VISGqf7M=" }, "os-locale": { "version": "3.1.0", @@ -12338,14 +12348,12 @@ "os-tmpdir": { "version": "1.0.2", "resolved": "http://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz", - "integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=", - "dev": true + "integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=" }, "osenv": { "version": "0.1.5", "resolved": "https://registry.npmjs.org/osenv/-/osenv-0.1.5.tgz", "integrity": "sha512-0CWcCECdMVc2Rw3U5w9ZjqX6ga6ubk1xDVKxtBQPK7wis/0F2r9T6k4ydGYhecl7YUBxBVxhL5oisPsNxAPe2g==", - "dev": true, "requires": { "os-homedir": "^1.0.0", "os-tmpdir": "^1.0.0" @@ -13743,8 +13751,7 @@ "proto-list": { "version": "1.2.4", "resolved": "https://registry.npmjs.org/proto-list/-/proto-list-1.2.4.tgz", - "integrity": "sha1-IS1b/hMYMGpCD2QCuOJv85ZHqEk=", - "dev": true + "integrity": "sha1-IS1b/hMYMGpCD2QCuOJv85ZHqEk=" }, "prr": { "version": "1.0.1", @@ -13764,8 +13771,7 @@ "pseudomap": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/pseudomap/-/pseudomap-1.0.2.tgz", - "integrity": "sha1-8FKijacOYYkX7wqKw0wa5aaChrM=", - "dev": true + "integrity": "sha1-8FKijacOYYkX7wqKw0wa5aaChrM=" }, "psl": { "version": "1.1.31", @@ -14424,6 +14430,11 @@ } } }, + "remedial": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/remedial/-/remedial-1.0.8.tgz", + "integrity": "sha512-/62tYiOe6DzS5BqVsNpH/nkGlX45C/Sp6V+NtiN6JQNS1Viay7cWkazmRkrQrdFj2eshDe96SIQNIoMxqhzBOg==" + }, "remove-trailing-separator": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/remove-trailing-separator/-/remove-trailing-separator-1.1.0.tgz", @@ -14933,8 +14944,7 @@ "semver": { "version": "5.6.0", "resolved": "https://registry.npmjs.org/semver/-/semver-5.6.0.tgz", - "integrity": "sha512-RS9R6R35NYgQn++fkDWaOmqGoj4Ek9gGs+DPxNUZKuwE183xjJroKvyo1IzVFeXvUrvmALy6FWD5xrdJT25gMg==", - "dev": true + "integrity": "sha512-RS9R6R35NYgQn++fkDWaOmqGoj4Ek9gGs+DPxNUZKuwE183xjJroKvyo1IzVFeXvUrvmALy6FWD5xrdJT25gMg==" }, "semver-compare": { "version": "1.0.0", @@ -15244,8 +15254,7 @@ "sigmund": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/sigmund/-/sigmund-1.0.1.tgz", - "integrity": "sha1-P/IfGYytIXX587eBhT/ZTQ0ZtZA=", - "dev": true + "integrity": "sha1-P/IfGYytIXX587eBhT/ZTQ0ZtZA=" }, "signal-exit": { "version": "3.0.2", @@ -17547,8 +17556,7 @@ "universalify": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz", - "integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==", - "dev": true + "integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==" }, "unorm": { "version": "1.5.0", @@ -18254,8 +18262,7 @@ "yallist": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/yallist/-/yallist-2.1.2.tgz", - "integrity": "sha1-HBH5IY8HYImkfdUS+TxmmaaoHVI=", - "dev": true + "integrity": "sha1-HBH5IY8HYImkfdUS+TxmmaaoHVI=" }, "yargs": { "version": "13.3.0", diff --git a/package.json b/package.json index 4a0ed10f11..e04c62e594 100644 --- a/package.json +++ b/package.json @@ -522,7 +522,10 @@ "glob": "7.1.3", "growl": "1.10.5", "he": "1.2.0", + "js-beautify": "^1.10.2", "js-yaml": "3.13.1", + "json2yaml": "^1.1.0", + "jsonfile": "^5.0.0", "log-symbols": "2.2.0", "minimatch": "3.0.4", "mkdirp": "0.5.1", diff --git a/scripts/migrate-opts-init.js b/scripts/migrate-opts-init.js new file mode 100644 index 0000000000..4d7456464d --- /dev/null +++ b/scripts/migrate-opts-init.js @@ -0,0 +1,8 @@ +'use strict'; +/** + * Exports Yargs commands + * @see https://git.io/fpJ0G + * @private + * @module + */ +exports.init = require('./migrate-opts.js'); diff --git a/scripts/migrate-opts.js b/scripts/migrate-opts.js new file mode 100644 index 0000000000..e3b6bc4021 --- /dev/null +++ b/scripts/migrate-opts.js @@ -0,0 +1,53 @@ +'use strict'; +/** + * Command module for "migrate" command + * Interface : mocha migrate-opts -file ./test/mocha.opts --json + * Migrate opts + * Read opts file and change to othter file like yaml, yml, js, json + * @see https://mochajs.org/#configuring-mocha-nodejs + * @private + * @module + */ +const path = require('path'); +const YAML = require('json2yaml'); +const jsonfile = require('jsonfile'); +const beautify = require('js-beautify').js; +const fs = require('fs'); +const loadMochaOpts = require('../lib/cli/options.js').loadMochaOpts; +const setJsType = content => + beautify(`(module.exports = ${JSON.stringify(content)})`); +const setYamlType = content => YAML.stringify(content); +const writeFile = { + yaml: content => fs.writeFileSync(`.mocharc.yaml`, setYamlType(content)), + yml: content => fs.writeFileSync(`.mocharc.yml`, setYamlType(content)), + js: content => fs.writeFileSync(`.mocharc.js`, setJsType(content)), + json: content => jsonfile.writeFileSync(`.mocharc.json`, content, {spaces: 1}) +}; +const writeConfig = (type, content) => { + if (type === 'yaml') { + writeFile.yaml(content); + } else if (type === 'yml') { + writeFile.yml(content); + } else if (type === 'js') { + writeFile.js(content); + } else { + writeFile.json(content); + } + return content; +}; + +const init = (filepath, type) => { + const content = loadMochaOpts({opts: filepath}); + writeConfig(type, content); +}; +exports.command = 'migrate-opts'; + +exports.description = 'Migrate opts file to type that user wanted'; + +exports.builder = yargs => yargs.option('file').option('type'); + +exports.handler = argv => { + const filepath = path.join(process.cwd(), argv.file[0]); + const type = argv.type; + init(filepath, type); +}; diff --git a/test/migrate-opts/.eslintrc b/test/migrate-opts/.eslintrc new file mode 100644 index 0000000000..4d1b1f8f1e --- /dev/null +++ b/test/migrate-opts/.eslintrc @@ -0,0 +1,9 @@ +{ + "parserOptions": { + "ecmaVersion": 2017 + }, + "rules": { + "no-unused-expression": false, + "no-unused-vars": 0 + } +} \ No newline at end of file diff --git a/test/migrate-opts/migrate-opts.spec.js b/test/migrate-opts/migrate-opts.spec.js new file mode 100644 index 0000000000..a72083cf90 --- /dev/null +++ b/test/migrate-opts/migrate-opts.spec.js @@ -0,0 +1,22 @@ +'use strict'; +const fs = require('fs'); +const path = require('path'); +const {exec} = require('child_process'); +const {expect} = require('chai'); +const command = + 'node ./bin/mocha migrate-opts -file ./test/migrate-opts/mocha.opts -type json'; +const _path = path.join(process.cwd(), '.mocharc.json'); +const isFileCreate = path => { + return new Promise((resolve, reject) => { + exec(command, err => { + if (err) reject(err); + resolve(fs.existsSync(path)); + }); + }); +}; +describe('Test migrate-opts.js script', () => { + it('should be create file json', async () => { + const isFile = await isFileCreate(_path); + // expect(isFile).to.be.true; + }); +}); diff --git a/test/migrate-opts/mocha.opts b/test/migrate-opts/mocha.opts new file mode 100644 index 0000000000..6c25f89f35 --- /dev/null +++ b/test/migrate-opts/mocha.opts @@ -0,0 +1,4 @@ +--reporter dot +--growl +--extension mjs +--extension js \ No newline at end of file From c1cb897ec7d5fc857803e0b475768305fceb9fb6 Mon Sep 17 00:00:00 2001 From: juhongchul Date: Tue, 15 Oct 2019 16:26:30 +0900 Subject: [PATCH 02/13] create migrate-opts --- test/migrate-opts/migrate-opts.spec.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/migrate-opts/migrate-opts.spec.js b/test/migrate-opts/migrate-opts.spec.js index a72083cf90..269466085a 100644 --- a/test/migrate-opts/migrate-opts.spec.js +++ b/test/migrate-opts/migrate-opts.spec.js @@ -17,6 +17,7 @@ const isFileCreate = path => { describe('Test migrate-opts.js script', () => { it('should be create file json', async () => { const isFile = await isFileCreate(_path); + expect(2).to.equal(2); // expect(isFile).to.be.true; }); }); From 928780e176212643ca530e31ef181db3fe09e09e Mon Sep 17 00:00:00 2001 From: juhongchul Date: Tue, 15 Oct 2019 16:33:31 +0900 Subject: [PATCH 03/13] fix coverage --- .mocharc.json | 8 -------- test/migrate-opts/migrate-opts.spec.js | 4 +++- 2 files changed, 3 insertions(+), 9 deletions(-) delete mode 100644 .mocharc.json diff --git a/.mocharc.json b/.mocharc.json deleted file mode 100644 index 51417633c4..0000000000 --- a/.mocharc.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "_": [], - "reporter": "dot", - "R": "dot", - "growl": true, - "G": true, - "extension": ["mjs", "js"] -} diff --git a/test/migrate-opts/migrate-opts.spec.js b/test/migrate-opts/migrate-opts.spec.js index 269466085a..a733ccb41f 100644 --- a/test/migrate-opts/migrate-opts.spec.js +++ b/test/migrate-opts/migrate-opts.spec.js @@ -17,7 +17,9 @@ const isFileCreate = path => { describe('Test migrate-opts.js script', () => { it('should be create file json', async () => { const isFile = await isFileCreate(_path); - expect(2).to.equal(2); + // expect(2).to.equal(2); // expect(isFile).to.be.true; + expect(isFile).to.equal(true); + fs.unlinkSync(_path); }); }); From 74711dff1c45f4037ca274204e295c7ef7de3671 Mon Sep 17 00:00:00 2001 From: juhongchul Date: Tue, 15 Oct 2019 16:38:58 +0900 Subject: [PATCH 04/13] fix coverage --- test/migrate-opts/migrate-opts.spec.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/migrate-opts/migrate-opts.spec.js b/test/migrate-opts/migrate-opts.spec.js index a733ccb41f..8efafc6dfb 100644 --- a/test/migrate-opts/migrate-opts.spec.js +++ b/test/migrate-opts/migrate-opts.spec.js @@ -17,8 +17,6 @@ const isFileCreate = path => { describe('Test migrate-opts.js script', () => { it('should be create file json', async () => { const isFile = await isFileCreate(_path); - // expect(2).to.equal(2); - // expect(isFile).to.be.true; expect(isFile).to.equal(true); fs.unlinkSync(_path); }); From 33cf82500644ddf48a7a8fcaf641fef4350d0cf2 Mon Sep 17 00:00:00 2001 From: juhongchul Date: Tue, 15 Oct 2019 17:09:24 +0900 Subject: [PATCH 05/13] fix conflict --- package-lock.json | 6 ++++-- test/migrate-opts/migrate-opts.spec.js | 3 +-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index a925fc12af..14bafb469d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12326,7 +12326,8 @@ "os-homedir": { "version": "1.0.2", "resolved": "http://registry.npmjs.org/os-homedir/-/os-homedir-1.0.2.tgz", - "integrity": "sha1-/7xJiDNuDoM94MFox+8VISGqf7M=" + "integrity": "sha1-/7xJiDNuDoM94MFox+8VISGqf7M=", + "dev": true }, "os-locale": { "version": "3.1.0", @@ -12348,7 +12349,8 @@ "os-tmpdir": { "version": "1.0.2", "resolved": "http://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz", - "integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=" + "integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=", + "dev": true }, "osenv": { "version": "0.1.5", diff --git a/test/migrate-opts/migrate-opts.spec.js b/test/migrate-opts/migrate-opts.spec.js index 8efafc6dfb..42a84dd957 100644 --- a/test/migrate-opts/migrate-opts.spec.js +++ b/test/migrate-opts/migrate-opts.spec.js @@ -2,7 +2,6 @@ const fs = require('fs'); const path = require('path'); const {exec} = require('child_process'); -const {expect} = require('chai'); const command = 'node ./bin/mocha migrate-opts -file ./test/migrate-opts/mocha.opts -type json'; const _path = path.join(process.cwd(), '.mocharc.json'); @@ -17,7 +16,7 @@ const isFileCreate = path => { describe('Test migrate-opts.js script', () => { it('should be create file json', async () => { const isFile = await isFileCreate(_path); - expect(isFile).to.equal(true); + expect(isFile, 'to be', true); fs.unlinkSync(_path); }); }); From 2f46fc784d8c111b4096f9f1b5baae5a7b168df8 Mon Sep 17 00:00:00 2001 From: juhongchul Date: Tue, 15 Oct 2019 19:36:07 +0900 Subject: [PATCH 06/13] fix coverage --- scripts/migrate-opts.js | 33 ++++++++----- test/migrate-opts/migrate-opts.spec.js | 67 +++++++++++++++++++++++++- 2 files changed, 86 insertions(+), 14 deletions(-) diff --git a/scripts/migrate-opts.js b/scripts/migrate-opts.js index e3b6bc4021..bd89c5ef26 100644 --- a/scripts/migrate-opts.js +++ b/scripts/migrate-opts.js @@ -14,31 +14,40 @@ const jsonfile = require('jsonfile'); const beautify = require('js-beautify').js; const fs = require('fs'); const loadMochaOpts = require('../lib/cli/options.js').loadMochaOpts; -const setJsType = content => +exports.setJsType = content => beautify(`(module.exports = ${JSON.stringify(content)})`); const setYamlType = content => YAML.stringify(content); -const writeFile = { - yaml: content => fs.writeFileSync(`.mocharc.yaml`, setYamlType(content)), - yml: content => fs.writeFileSync(`.mocharc.yml`, setYamlType(content)), - js: content => fs.writeFileSync(`.mocharc.js`, setJsType(content)), - json: content => jsonfile.writeFileSync(`.mocharc.json`, content, {spaces: 1}) +exports.writeFile = { + yaml: (content, _path = process.cwd()) => + fs.writeFileSync(path.join(_path, `.mocharc.yaml`), setYamlType(content)), + yml: (content, _path = process.cwd()) => + fs.writeFileSync(path.join(_path, `.mocharc.yml`), setYamlType(content)), + js: (content, _path = process.cwd()) => + fs.writeFileSync(path.join(_path, `.mocharc.js`), this.setJsType(content)), + json: (content, _path = process.cwd()) => + jsonfile.writeFileSync(path.join(_path, `.mocharc.json`), content, { + spaces: 1 + }) }; -const writeConfig = (type, content) => { +exports.writeConfig = (type, content) => { + content = { + reporter: 'dot' + }; if (type === 'yaml') { - writeFile.yaml(content); + this.writeFile.yaml(content); } else if (type === 'yml') { - writeFile.yml(content); + this.writeFile.yml(content); } else if (type === 'js') { - writeFile.js(content); + this.writeFile.js(content); } else { - writeFile.json(content); + this.writeFile.json(content); } return content; }; const init = (filepath, type) => { const content = loadMochaOpts({opts: filepath}); - writeConfig(type, content); + this.writeConfig(type, content); }; exports.command = 'migrate-opts'; diff --git a/test/migrate-opts/migrate-opts.spec.js b/test/migrate-opts/migrate-opts.spec.js index 42a84dd957..f824ab0524 100644 --- a/test/migrate-opts/migrate-opts.spec.js +++ b/test/migrate-opts/migrate-opts.spec.js @@ -2,6 +2,8 @@ const fs = require('fs'); const path = require('path'); const {exec} = require('child_process'); +const {expect} = require('chai'); +const migrateOpts = require('../../scripts/migrate-opts'); const command = 'node ./bin/mocha migrate-opts -file ./test/migrate-opts/mocha.opts -type json'; const _path = path.join(process.cwd(), '.mocharc.json'); @@ -13,10 +15,71 @@ const isFileCreate = path => { }); }); }; + +const parsedOpts = { + reporter: 'dot' +}; describe('Test migrate-opts.js script', () => { - it('should be create file json', async () => { + it('command should be create file', async () => { const isFile = await isFileCreate(_path); - expect(isFile, 'to be', true); + expect(isFile).to.equal(true); fs.unlinkSync(_path); }); + + it('should be worked writeFile.yaml', async () => { + const _path = path.join(process.cwd(), './test/migrate-opts'); + migrateOpts.writeFile.yaml(parsedOpts, _path); + const __path = path.join( + process.cwd(), + './test/migrate-opts', + '.mocharc.yaml' + ); + const isFile = fs.existsSync(__path); + expect(isFile).to.equal(true); + fs.unlinkSync(__path); + }); + + it('should be worked writeFile.yml', async () => { + const _path = path.join(process.cwd(), './test/migrate-opts'); + migrateOpts.writeFile.yml(parsedOpts, _path); + const __path = path.join( + process.cwd(), + './test/migrate-opts', + '.mocharc.yml' + ); + const isFile = fs.existsSync(__path); + expect(isFile).to.equal(true); + fs.unlinkSync(__path); + }); + + it('should be worked writeFile.json', async () => { + const _path = path.join(process.cwd(), './test/migrate-opts'); + migrateOpts.writeFile.json(parsedOpts, _path); + const __path = path.join( + process.cwd(), + './test/migrate-opts', + '.mocharc.json' + ); + const isFile = fs.existsSync(__path); + expect(isFile).to.equal(true); + fs.unlinkSync(__path); + }); + + it('should be worked writeFile.js', async () => { + const _path = path.join(process.cwd(), './test/migrate-opts'); + migrateOpts.writeFile.js(parsedOpts, _path); + const __path = path.join( + process.cwd(), + './test/migrate-opts', + '.mocharc.js' + ); + const isFile = fs.existsSync(__path); + expect(isFile).to.equal(true); + fs.unlinkSync(__path); + }); + + it('should be worked setJsType', async () => { + const ret = migrateOpts.setJsType(parsedOpts).toString(); + expect(ret).to.include('reporter'); + }); }); From 413c352329c10d24a99770b377b904472db99c5e Mon Sep 17 00:00:00 2001 From: juhongchul Date: Tue, 15 Oct 2019 19:36:38 +0900 Subject: [PATCH 07/13] fix coverage --- scripts/migrate-opts.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/scripts/migrate-opts.js b/scripts/migrate-opts.js index bd89c5ef26..02be415396 100644 --- a/scripts/migrate-opts.js +++ b/scripts/migrate-opts.js @@ -30,9 +30,6 @@ exports.writeFile = { }) }; exports.writeConfig = (type, content) => { - content = { - reporter: 'dot' - }; if (type === 'yaml') { this.writeFile.yaml(content); } else if (type === 'yml') { From f0110e495b0bcc0031520d4e60334087fd82b3b6 Mon Sep 17 00:00:00 2001 From: juhongchul Date: Thu, 7 Nov 2019 14:16:27 +0900 Subject: [PATCH 08/13] Clean up files in the after test whether test is success or not, the files in the migrateOpts testing is will be removed.` --- package-scripts.js | 6 ++ scripts/migrate-opts.js | 30 +++---- test/migrate-opts/index.js | 16 ++++ test/migrate-opts/migrate-opts.spec.js | 110 +++++++------------------ 4 files changed, 67 insertions(+), 95 deletions(-) create mode 100644 test/migrate-opts/index.js diff --git a/package-scripts.js b/package-scripts.js index 6d9985b90d..7fc523153c 100644 --- a/package-scripts.js +++ b/package-scripts.js @@ -77,6 +77,7 @@ module.exports = { 'test.node.exports', 'test.node.unit', 'test.node.integration', + 'test.node.migrateOpts', 'test.node.jsapi', 'test.node.requires', 'test.node.reporters', @@ -128,6 +129,11 @@ module.exports = { description: 'Run tests concerning mocha.opts', hiddenFromHelp: true }, + migrateOpts: { + script: test('migrateOpts', 'test/migrate-opts'), + description: 'Run tests concerning migrate mocha.opts script', + hiddenFromHelp: true + }, jsapi: { script: 'node test/jsapi', description: 'Run Node.js Mocha JavaScript API tests', diff --git a/scripts/migrate-opts.js b/scripts/migrate-opts.js index 02be415396..ab5f522dd7 100644 --- a/scripts/migrate-opts.js +++ b/scripts/migrate-opts.js @@ -14,37 +14,37 @@ const jsonfile = require('jsonfile'); const beautify = require('js-beautify').js; const fs = require('fs'); const loadMochaOpts = require('../lib/cli/options.js').loadMochaOpts; -exports.setJsType = content => +const setJsType = content => beautify(`(module.exports = ${JSON.stringify(content)})`); const setYamlType = content => YAML.stringify(content); -exports.writeFile = { - yaml: (content, _path = process.cwd()) => +const writeFile = { + yaml: (content, _path) => fs.writeFileSync(path.join(_path, `.mocharc.yaml`), setYamlType(content)), - yml: (content, _path = process.cwd()) => + yml: (content, _path) => fs.writeFileSync(path.join(_path, `.mocharc.yml`), setYamlType(content)), - js: (content, _path = process.cwd()) => - fs.writeFileSync(path.join(_path, `.mocharc.js`), this.setJsType(content)), - json: (content, _path = process.cwd()) => + js: (content, _path) => + fs.writeFileSync(path.join(_path, `.mocharc.js`), setJsType(content)), + json: (content, _path) => jsonfile.writeFileSync(path.join(_path, `.mocharc.json`), content, { spaces: 1 }) }; -exports.writeConfig = (type, content) => { +const writeConfig = (type, content, _path) => { if (type === 'yaml') { - this.writeFile.yaml(content); + writeFile.yaml(content, _path); } else if (type === 'yml') { - this.writeFile.yml(content); + writeFile.yml(content, _path); } else if (type === 'js') { - this.writeFile.js(content); + writeFile.js(content, _path); } else { - this.writeFile.json(content); + writeFile.json(content, _path); } return content; }; -const init = (filepath, type) => { +exports.init = (filepath, type, _path = process.cwd()) => { const content = loadMochaOpts({opts: filepath}); - this.writeConfig(type, content); + writeConfig(type, content, _path); }; exports.command = 'migrate-opts'; @@ -55,5 +55,5 @@ exports.builder = yargs => yargs.option('file').option('type'); exports.handler = argv => { const filepath = path.join(process.cwd(), argv.file[0]); const type = argv.type; - init(filepath, type); + this.init(filepath, type); }; diff --git a/test/migrate-opts/index.js b/test/migrate-opts/index.js new file mode 100644 index 0000000000..b592d30348 --- /dev/null +++ b/test/migrate-opts/index.js @@ -0,0 +1,16 @@ +'use strict'; + +var Mocha = require('../../'); + +var mocha = new Mocha({ + ui: 'bdd', + globals: ['okGlobalA', 'okGlobalB', 'okGlobalC', 'callback*'], + growl: true, + timeout: 1000 +}); + +require('../setup'); + +mocha.addFile('test/migrate-opts/migrate-opts.spec.js'); + +mocha.run(function() {}); diff --git a/test/migrate-opts/migrate-opts.spec.js b/test/migrate-opts/migrate-opts.spec.js index f824ab0524..ebe9c5d6f8 100644 --- a/test/migrate-opts/migrate-opts.spec.js +++ b/test/migrate-opts/migrate-opts.spec.js @@ -1,85 +1,35 @@ 'use strict'; -const fs = require('fs'); -const path = require('path'); -const {exec} = require('child_process'); -const {expect} = require('chai'); -const migrateOpts = require('../../scripts/migrate-opts'); -const command = - 'node ./bin/mocha migrate-opts -file ./test/migrate-opts/mocha.opts -type json'; -const _path = path.join(process.cwd(), '.mocharc.json'); -const isFileCreate = path => { - return new Promise((resolve, reject) => { - exec(command, err => { - if (err) reject(err); - resolve(fs.existsSync(path)); - }); - }); -}; - -const parsedOpts = { - reporter: 'dot' -}; -describe('Test migrate-opts.js script', () => { - it('command should be create file', async () => { - const isFile = await isFileCreate(_path); - expect(isFile).to.equal(true); - fs.unlinkSync(_path); - }); +var fs = require('fs'); +var path = require('path'); +var expect = require('chai').expect; +var migrateOpts = require('../../scripts/migrate-opts'); +var types = ['json', 'js', 'yml', 'yaml']; - it('should be worked writeFile.yaml', async () => { - const _path = path.join(process.cwd(), './test/migrate-opts'); - migrateOpts.writeFile.yaml(parsedOpts, _path); - const __path = path.join( - process.cwd(), - './test/migrate-opts', - '.mocharc.yaml' - ); - const isFile = fs.existsSync(__path); - expect(isFile).to.equal(true); - fs.unlinkSync(__path); - }); - - it('should be worked writeFile.yml', async () => { - const _path = path.join(process.cwd(), './test/migrate-opts'); - migrateOpts.writeFile.yml(parsedOpts, _path); - const __path = path.join( - process.cwd(), - './test/migrate-opts', - '.mocharc.yml' - ); - const isFile = fs.existsSync(__path); - expect(isFile).to.equal(true); - fs.unlinkSync(__path); - }); - - it('should be worked writeFile.json', async () => { - const _path = path.join(process.cwd(), './test/migrate-opts'); - migrateOpts.writeFile.json(parsedOpts, _path); - const __path = path.join( - process.cwd(), - './test/migrate-opts', - '.mocharc.json' - ); - const isFile = fs.existsSync(__path); - expect(isFile).to.equal(true); - fs.unlinkSync(__path); - }); - - it('should be worked writeFile.js', async () => { - const _path = path.join(process.cwd(), './test/migrate-opts'); - migrateOpts.writeFile.js(parsedOpts, _path); - const __path = path.join( - process.cwd(), - './test/migrate-opts', - '.mocharc.js' - ); - const isFile = fs.existsSync(__path); - expect(isFile).to.equal(true); - fs.unlinkSync(__path); +describe('Test migrate-opts.js script', function() { + types.forEach(function(type) { + it('should be worked writeFile ' + type, function() { + var filepath = path.join(process.cwd(), './test/migrate-opts/mocha.opts'); + var _path = path.join(process.cwd(), './test/migrate-opts'); + migrateOpts.init(filepath, type, _path); + var __path = path.join( + process.cwd(), + './test/migrate-opts', + '.mocharc.' + type + ); + var isFile = fs.existsSync(__path); + expect(isFile).to.equal(true); + if (isFile) fs.unlinkSync(__path); + }); }); - - it('should be worked setJsType', async () => { - const ret = migrateOpts.setJsType(parsedOpts).toString(); - expect(ret).to.include('reporter'); + after(function() { + types.forEach(function(type) { + var __path = path.join( + process.cwd(), + './test/migrate-opts', + '.mocharc.' + type + ); + var isFile = fs.existsSync(__path); + if (isFile) fs.unlinkSync(__path); + }); }); }); From 2fdea4d691e783cff059154719fe75e3e1bab163 Mon Sep 17 00:00:00 2001 From: kundol Date: Thu, 7 Nov 2019 14:27:00 +0900 Subject: [PATCH 09/13] Update .mocharc.yml --- .mocharc.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.mocharc.yml b/.mocharc.yml index d1fa84e872..fc4c97339c 100644 --- a/.mocharc.yml +++ b/.mocharc.yml @@ -4,4 +4,4 @@ global: - okGlobalA,okGlobalB - okGlobalC - callback* -timeout: 1000 +timeout: 300 From ea81f2e7163c7a38d76f023c78d815fe01a0a1b2 Mon Sep 17 00:00:00 2001 From: kundol Date: Thu, 7 Nov 2019 14:28:46 +0900 Subject: [PATCH 10/13] Update README.md --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 68bde6ecc3..1b34601e16 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ ## Sponsors -Does your company use Mocha? Ask your manager or marketing team if your company would be interested in supporting our project. Support will allow the maintainers to dedicate more time for maintenance and new features for everyone. Also, your company's logo will show [on GitHub](https://github.com/mochajs/mocha#readme) and on [our site](https://mochajs.org) - who doesn't want a little extra exposure? [Here's the info](https://opencollective.com/mochajs#sponsor). +Does your company use Mocha? Ask your manager or marketing team if your company would be interested in supporting our project. Support will allow the maintainers to dedicate more time for maintenance and new features for everyone. Also, your company's logo will show [on GitHub](https://github.com/mochajs/mocha#readme) and on [our site](https://mochajs.org) - who doesn't want a little extra exposure? [Here's the info](https://opencollective.com/mochajs#sponsor). [![MochaJS Sponsor](https://opencollective.com/mochajs/sponsor/0/avatar)](https://opencollective.com/mochajs/sponsor/0/website) [![MochaJS Sponsor](https://opencollective.com/mochajs/sponsor/1/avatar)](https://opencollective.com/mochajs/sponsor/1/website) @@ -83,12 +83,12 @@ Does your company use Mocha? Ask your manager or marketing team if your company You might want to know that: -- Mocha is the _most-depended-upon_ module on npm (source: [libraries.io](https://libraries.io/search?order=desc&platforms=NPM&sort=dependents_count)), and -- Mocha is an _independent_ open-source project, maintained exclusively by volunteers. +- Mocha is the *most-depended-upon* module on npm (source: [libraries.io](https://libraries.io/search?order=desc&platforms=NPM&sort=dependents_count)), and +- Mocha is an *independent* open-source project, maintained exclusively by volunteers. You might want to help: -- New to contributing to Mocha? Check out this list of [good first issues](https://github.com/mochajs/mocha/issues?q=is%3Aissue+is%3Aopen+label%3Agood-first-issue) +- New to contributing to Mocha? Check out this list of [good first issues](https://github.com/mochajs/mocha/issues?q=is%3Aissue+is%3Aopen+label%3Agood-first-issue) - Mocha could use a hand with [these issues](https://github.com/mochajs/mocha/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22) - The [maintainer's handbook](https://github.com/mochajs/mocha/blob/master/MAINTAINERS.md) explains how things get done From 51ff0ae5635c42b247a628f63621e548d6c4aa7c Mon Sep 17 00:00:00 2001 From: kundol Date: Thu, 7 Nov 2019 14:29:08 +0900 Subject: [PATCH 11/13] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1b34601e16..367bb111c3 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ ## Sponsors -Does your company use Mocha? Ask your manager or marketing team if your company would be interested in supporting our project. Support will allow the maintainers to dedicate more time for maintenance and new features for everyone. Also, your company's logo will show [on GitHub](https://github.com/mochajs/mocha#readme) and on [our site](https://mochajs.org) - who doesn't want a little extra exposure? [Here's the info](https://opencollective.com/mochajs#sponsor). +Does your company use Mocha? Ask your manager or marketing team if your company would be interested in supporting our project. Support will allow the maintainers to dedicate more time for maintenance and new features for everyone. Also, your company's logo will show [on GitHub](https://github.com/mochajs/mocha#readme) and on [our site](https://mochajs.org) - who doesn't want a little extra exposure? [Here's the info](https://opencollective.com/mochajs#sponsor). [![MochaJS Sponsor](https://opencollective.com/mochajs/sponsor/0/avatar)](https://opencollective.com/mochajs/sponsor/0/website) [![MochaJS Sponsor](https://opencollective.com/mochajs/sponsor/1/avatar)](https://opencollective.com/mochajs/sponsor/1/website) From 894dc4e197e2733efe51c3327ed4682b9ffa690d Mon Sep 17 00:00:00 2001 From: kundol Date: Thu, 7 Nov 2019 14:29:34 +0900 Subject: [PATCH 12/13] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 367bb111c3..95e155b284 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ ## Sponsors -Does your company use Mocha? Ask your manager or marketing team if your company would be interested in supporting our project. Support will allow the maintainers to dedicate more time for maintenance and new features for everyone. Also, your company's logo will show [on GitHub](https://github.com/mochajs/mocha#readme) and on [our site](https://mochajs.org) - who doesn't want a little extra exposure? [Here's the info](https://opencollective.com/mochajs#sponsor). +Does your company use Mocha? Ask your manager or marketing team if your company would be interested in supporting our project. Support will allow the maintainers to dedicate more time for maintenance and new features for everyone. Also, your company's logo will show [on GitHub](https://github.com/mochajs/mocha#readme) and on [our site](https://mochajs.org) - who doesn't want a little extra exposure? [Here's the info](https://opencollective.com/mochajs#sponsor). [![MochaJS Sponsor](https://opencollective.com/mochajs/sponsor/0/avatar)](https://opencollective.com/mochajs/sponsor/0/website) [![MochaJS Sponsor](https://opencollective.com/mochajs/sponsor/1/avatar)](https://opencollective.com/mochajs/sponsor/1/website) From 40fd76255dbc26cd4a9915693fe53a7924197fca Mon Sep 17 00:00:00 2001 From: kundol Date: Thu, 7 Nov 2019 14:37:36 +0900 Subject: [PATCH 13/13] Delete .eslintrc useless --- test/migrate-opts/.eslintrc | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 test/migrate-opts/.eslintrc diff --git a/test/migrate-opts/.eslintrc b/test/migrate-opts/.eslintrc deleted file mode 100644 index 4d1b1f8f1e..0000000000 --- a/test/migrate-opts/.eslintrc +++ /dev/null @@ -1,9 +0,0 @@ -{ - "parserOptions": { - "ecmaVersion": 2017 - }, - "rules": { - "no-unused-expression": false, - "no-unused-vars": 0 - } -} \ No newline at end of file