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

filepath serializer #3007

Closed
wants to merge 1 commit into from

Conversation

jamiebuilds
Copy link
Contributor

@jamiebuilds jamiebuilds commented Feb 26, 2017

@codecov-io
Copy link

codecov-io commented Feb 26, 2017

Codecov Report

Merging #3007 into master will decrease coverage by -0.7%.
The diff coverage is 0%.

@@            Coverage Diff            @@
##           master    #3007     +/-   ##
=========================================
- Coverage   68.49%   67.79%   -0.7%     
=========================================
  Files         146      148      +2     
  Lines        5335     5354     +19     
=========================================
- Hits         3654     3630     -24     
- Misses       1681     1724     +43
Impacted Files Coverage Δ
packages/jest-serializer-filepath/src/index.js 0% <0%> (ø)
packages/jest-config/src/loadFromPackage.js 0% <0%> (-100%)
packages/jest-config/src/loadFromFile.js 0% <0%> (-100%)
packages/jest-runtime/src/index.js 85.02% <0%> (-2.03%)
packages/jest-snapshot/src/utils.js 96.92% <0%> (-1.54%)
packages/jest-jasmine2/src/index.js 0% <0%> (ø)
packages/jest-cli/src/runJest.js 0% <0%> (ø)
packages/jest-config/src/normalize.js 85.9% <0%> (ø)
packages/jest-cli/src/lib/validatePattern.js
...ackages/jest-cli/src/lib/getTestPathPatternInfo.js
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 34c7186...f54517f. Read the comment docs.

*/
'use strict';

const cwd = process.cwd();
Copy link
Member

Choose a reason for hiding this comment

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

This is pretty cool but I don't think using process.cwd() is sufficient. The directory can change based on where Jest is invoked which would lead to outdated snapshots all the time. I'm wondering if we could make it configurable somehow?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alternatively it can search upwards until it finds a package.json#jest

const plugin = printPlugin(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex, colors);
if (plugin) {
return plugin;
}

const basic = printBasicValue(val, printFunctionName, escapeRegex);
Copy link
Member

Choose a reason for hiding this comment

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

What does this change do to performance?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ran the perf suite, didn't notice any significant differences anywhere.

Copy link
Member

Choose a reason for hiding this comment

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

That's not the only way to specify a jest config, unfortunately. Would you mind divorcing the two changes you are making in this diff and sending a separate PR for the filepath thing? Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did you reply to the wrong thread?

Copy link
Member

Choose a reason for hiding this comment

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

Oh, oops this was supposed to be a response to the filename serializer plugin.

@jamiebuilds jamiebuilds changed the title pretty-format fix & filepath serializer filepath serializer Feb 27, 2017
@wtgtybhertgeghgtwtg
Copy link
Contributor

Can this please please please be run through slash? Windows-specific separators tend to cause issues.

@cpojer
Copy link
Member

cpojer commented Mar 2, 2017

Thanks @thejameskyle. I think we can only make this work if we find a way to pass config.rootDir from Jest into this. We could potentially do something like:

expect.addSnapshotSerializer(createFilepathSerializer(config.rootDir));

however, we don't have the rootDir available in user code either, so I'm not entirely sure how to make it work :(

@jamiebuilds
Copy link
Contributor Author

We can allow serializer configuration by changing the API to:

export default function({ rootDir }) {
  return {
    test() {...},
    print() {...},
  };
}

@cpojer
Copy link
Member

cpojer commented Mar 2, 2017

Not a huge fan of breaking this but I guess we could keep backwards compatibility. With your proposal, we could thread some Jest config options through to pretty-format which then gets passed to plugins. I like it!

SimenB added a commit to SimenB/csslint-stylish that referenced this pull request Mar 4, 2017
@cpojer
Copy link
Member

cpojer commented Mar 7, 2017

@thejameskyle are you planning on working on a way to pass the rootDir in?

@jamiebuilds
Copy link
Contributor Author

jamiebuilds commented Mar 7, 2017

In a rush to finish some other things this week. But we'll need to agree on an API first.

This is what I'm going with:

type Printer = {
  test(mixed): boolean,
  print(mixed, Print, Indent, Options, Colors): string,
};
type PrinterBuilder = ({ rootDir: string }) => Printer;
type Plugin = Printer | PrinterBuilder;

@cpojer
Copy link
Member

cpojer commented Mar 7, 2017

sounds good. Can we just call it "root"? I really dislike "rootDir" within Jest :)

We'll also need to find a way to thread this through; tests don't expose the config/rootDir at the moment and I'd like to keep it that way.

@cpojer
Copy link
Member

cpojer commented Mar 17, 2017

Happy to reopen if we decide to ship this inside of Jest with the iterated version, closing for now.

@cpojer cpojer closed this Mar 17, 2017
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants