-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create migrate script to change mocha.opts to [json | js | yml | yaml] #4069
Closed
Closed
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
7d560c2
Merge pull request #1 from mochajs/master
wnghdcjfe a6c87f6
create migrate-opts
wnghdcjfe c1cb897
create migrate-opts
wnghdcjfe 928780e
fix coverage
wnghdcjfe 74711df
fix coverage
wnghdcjfe 33cf825
fix conflict
wnghdcjfe 2f46fc7
fix coverage
wnghdcjfe 413c352
fix coverage
wnghdcjfe 4700a17
fix coverage
wnghdcjfe f0110e4
Clean up files in the after test
wnghdcjfe 2fdea4d
Update .mocharc.yml
wnghdcjfe ea81f2e
Update README.md
wnghdcjfe 51ff0ae
Update README.md
wnghdcjfe 894dc4e
Update README.md
wnghdcjfe 40fd762
Delete .eslintrc
wnghdcjfe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
'use strict'; | ||
/** | ||
* Exports Yargs commands | ||
* @see https://git.io/fpJ0G | ||
* @private | ||
* @module | ||
*/ | ||
exports.init = require('./migrate-opts.js'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
'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, _path) => | ||
fs.writeFileSync(path.join(_path, `.mocharc.yaml`), setYamlType(content)), | ||
yml: (content, _path) => | ||
fs.writeFileSync(path.join(_path, `.mocharc.yml`), setYamlType(content)), | ||
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 | ||
}) | ||
}; | ||
const writeConfig = (type, content, _path) => { | ||
if (type === 'yaml') { | ||
writeFile.yaml(content, _path); | ||
} else if (type === 'yml') { | ||
writeFile.yml(content, _path); | ||
} else if (type === 'js') { | ||
writeFile.js(content, _path); | ||
} else { | ||
writeFile.json(content, _path); | ||
} | ||
return content; | ||
}; | ||
|
||
exports.init = (filepath, type, _path = process.cwd()) => { | ||
const content = loadMochaOpts({opts: filepath}); | ||
writeConfig(type, content, _path); | ||
}; | ||
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; | ||
this.init(filepath, type); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() {}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
'use strict'; | ||
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']; | ||
|
||
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); | ||
}); | ||
}); | ||
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); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--reporter dot | ||
--growl | ||
--extension mjs | ||
--extension js |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
content
includes alias and yargs's property like_
.We need to filter by mocha's options and normalize it.
For example
it's
content
will beThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My patch that filtering by
types
.mocha/lib/cli/run-option-metadata.js
Line 15 in c5fc2be