-
-
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
Conversation
whether test is success or not, the files in the migrateOpts testing is will be removed.`
useless
What is the status of this Pull Request? |
@azu I really appreciate your mind once. Based on some feedback from some people,I fixed my code and I think there is no code problems But, I think the maintainers are busy. so This PR has no progress. |
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.
I've created a standalone migration script.
npx @azu/mocha-migrate migrate-opts -file ./test/mocha.opts -type json
For more details, see README
This script is based on @wnghdcjfe work, Thanks!
However, It is better that mocha has built-in migration script.
husky does it and it looks like success.
}; | ||
|
||
exports.init = (filepath, type, _path = process.cwd()) => { | ||
const content = loadMochaOpts({opts: filepath}); |
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
--require ts-node-test-register
--reporter spec
it's content
will be
{
_: [],
require: [ 'ts-node-test-register' ],
r: [ 'ts-node-test-register' ],
reporter: 'spec',
R: 'spec'
}
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.
My patch that filtering by types
.
mocha/lib/cli/run-option-metadata.js
Line 15 in c5fc2be
exports.types = { |
const content = loadMochaOpts({opts: filepath});
const types = require("./run-option-metadata").types;
// filtering by types that remove alias and yargs property
const allowPropertyNames = Object.values(types).reduce((names, flagNames) => {
return names.concat(flagNames);
}, []);
const normalizedContent = Object.keys(content)
.filter(key => allowPropertyNames.includes(key))
.reduce((obj, key) => {
obj[key] = content[key];
return obj;
}, {});
writeConfig(type, normalizedContent, _path);
👋 coming back to this @wnghdcjfe, are you still interested in working on this PR? As of #5027 there are again maintainers who can review it now. No worries if you no longer have time - but if you do that'd be great! |
Closing out to keep the queue small, as this is a migration for a feature removed 3-4 years ago. Cheers! 🤎 |
I just checked this now, I'll join in. |
Description of the Change
add
mocha migrate
command in cli.To make
mocha migrate -file ./mocha.opts -type [yml | json | js | yaml]
possibleBenefits
Help mocha.opts to .mocharc.json, js, yml, yaml
Interface
and then file create like this
For your information, I used the existing code for the most safe results.
require('../lib/cli/options.js').loadMochaOpts
so"_": [],"G": true, ...
lefted but that is no problem with performance.Applicable issues
close #3910