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

feat(test function name): get function name from config #50

Merged
merged 7 commits into from
Feb 24, 2019

Conversation

ZimGil
Copy link
Member

@ZimGil ZimGil commented Feb 5, 2019

Getting test function name from config

related #38

@vercel
Copy link

vercel bot commented Feb 5, 2019

This pull request is automatically deployed with Now.
To access deployments, click Details below or on the icon next to each push.

@coveralls
Copy link

coveralls commented Feb 5, 2019

Coverage Status

Coverage increased (+0.3%) to 11.111% when pulling 706dd80 on test-function-name-config into 373a9ae on master.

@vercel vercel bot temporarily deployed to staging February 6, 2019 11:13 Inactive
Copy link
Member

@thatkookooguy thatkookooguy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few nits.

I suggest you run these changes at least once.
Until we have tests (which you can write if you want), you can run it by adding a call to the function when working on the file locally, and removing it once you know it works.

If I didn't check it myself we might have broken the bot by changing the regex, and even though I should test your code as a reviewer, you should test your code as the submitter even more :-P

config.yml Outdated Show resolved Hide resolved
lib/tests-from-pull-request.js Outdated Show resolved Hide resolved
lib/tests-from-pull-request.js Outdated Show resolved Hide resolved
lib/tests-from-pull-request.js Outdated Show resolved Hide resolved
lib/tests-from-pull-request.js Outdated Show resolved Hide resolved
lib/tests-from-pull-request.js Outdated Show resolved Hide resolved
return getPullRequestFiles()
return getConfig(context)
.then((userConfig) => {
config = userConfig;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this file, the only attribute you use from config is tdd1tTestFunctionName.

I think you can save a testFunctionName instead in the getTestsFromPR function's scope and not save a reference to the config itself

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mother of all nits: getPullRequestFiles(); is unrelated to the "config" function.

I would create a function inside the getTestsFromPR scope called getTestFunctionName which gets the config and saved it to the scope, while keeping getPullRequestFiles(); in a separate function in this flow (even though not all the functions in the flow are defined as named functions, but basically the anonymous functions should still be atomic if we can.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean like this:

  return getConfig(context)
    .then((userConfig) => getTestFunctionName(userConfig))
    .then((userTestFunctionName) => {
      testFunctionName = userTestFunctionName;
      return getPullRequestFiles();
    })
    .then((files) => files.map((file) => file.patch))
    .then((patches) => patches.join('\n'))
    .then((prPatch) => getTestNames(prPatch, testFunctionName))
    .then((testNames) => {
      context.log.debug({ data: testNames }, 'test names from pull request');

      return testNames;
    });
function getTestFunctionName(config) {
  return _.get(config, 'tdd1tTestFunctionName', 'it');
}

function getTestName(line, config) {
  const testFunctionName = _.get(config, 'tdd1tTestFunctionName', 'it');
  const getTestNameRegex = new RegExp(`${testFunctionName}\\((.*),`);
  const regexTestResult = getTestNameRegex.exec(line);

  return regexTestResult && regexTestResult[1].trim().slice(1, -1);
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant like this:

function getTestsFromPR(context) {
  let testFunctionName;

  return getTestFunctionName()
    // .then(...)
    // ...

  function getTestFunctionName() {
    return context.config('config.yml')
      .then((config) => _.get(config, 'tdd1tTestFunctionName', 'it'))
      .then((nameFromConfig) => testFunctionName = nameFromConfig);
  }
}

or like this:

function getTestsFromPR(context) {
  let testFunctionName;

  return getTestFunctionName(context)
    .then((functionName) => testFunctionName = functionName)
    // .then(...)
    // ...
}

function getTestFunctionName(context) {
  return context.config('config.yml')
    .then((config) => _.get(config, 'tdd1tTestFunctionName', 'it'));
}

Basically, the first one is defined inside getTestsFromPR so it has access to the context and can set the scope's variable inside the function, while the second one is defined outside of the function, which means it needs the context passed into it and to output the functionName.

Each of them is legit and not too intrusive. The rest of the flow should stay as-is besides passing the testFunctionName instead of the config along to getTestNames & getTestName.

config.yml Outdated Show resolved Hide resolved
@thatkookooguy thatkookooguy merged commit 3024d3c into master Feb 24, 2019
@thatkookooguy thatkookooguy deleted the test-function-name-config branch February 24, 2019 13:56
@thatkookooguy
Copy link
Member

🎉 This PR is included in version 1.7.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants