Skip to content
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
wants to merge 15 commits into from
Closed

Conversation

wnghdcjfe
Copy link
Contributor

@wnghdcjfe wnghdcjfe commented Oct 15, 2019

Description of the Change

add mocha migrate command in cli.
To make mocha migrate -file ./mocha.opts -type [yml | json | js | yaml] possible

Benefits

Help mocha.opts to .mocharc.json, js, yml, yaml

Interface

//test - version
node ./mocha/bin/mocha migrate-opts -file ./mocha.opts -type json
//real - version
mocha migrate -file ./mocha.opts -type yml
mocha migrate -file ./mocha.opts -type yaml
mocha migrate -file ./mocha.opts -type json
mocha migrate -file ./mocha.opts -type js

and then file create like this

{
 "_": [],
 "reporter": "dot",
 "R": "dot",
 "growl": true,
 "G": true,
 "extension": [
  "mjs",
  "js"
 ]
}

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

@coveralls
Copy link

coveralls commented Oct 15, 2019

Coverage Status

Coverage increased (+0.05%) to 92.792% when pulling 40fd762 on wnghdcjfe:migrate into ec8e2f8 on mochajs:master.

package-scripts.js Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
@wnghdcjfe wnghdcjfe changed the title Create migrate script to change mocha.opts to json, js, yml, yaml Create migrate script to change mocha.opts to [json | js | yml | yaml] Oct 19, 2019
@outsideris outsideris added the type: feature enhancement proposal label Oct 24, 2019
@azu
Copy link

azu commented Feb 14, 2020

What is the status of this Pull Request?
Is there anything that I can help with?
(For me, Migration script is blocker to update Mocha@7)

@wnghdcjfe
Copy link
Contributor Author

@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.

Copy link

@azu azu left a 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});
Copy link

@azu azu Mar 29, 2020

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'
}

Copy link

@azu azu Mar 29, 2020

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.

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);

@JoshuaKGoldberg
Copy link
Member

JoshuaKGoldberg commented Dec 2, 2023

👋 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!

@JoshuaKGoldberg
Copy link
Member

Closing out to keep the queue small, as this is a migration for a feature removed 3-4 years ago. Cheers! 🤎

@wnghdcjfe
Copy link
Contributor Author

I just checked this now, I'll join in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature enhancement proposal
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Soft deprecate "mocha.opts"
7 participants