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

Fix file path issues #833

Merged
merged 5 commits into from
Jan 27, 2017
Merged

Conversation

drewpc
Copy link
Collaborator

@drewpc drewpc commented Jan 14, 2017

Fixes #832 and includes tests! The fix was easy...the tests were hard to develop.

@drewpc drewpc added the bug An issue with the system label Jan 14, 2017
// add a wildcard onto the end if no file extension or wildcard
// currently present
let specGlob = "*[Ss]pec.js";
if (!specGlob.endsWith(".js") && !specGlob.endsWith("*")) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't understand this at all -- you just declared specGlob? How can it have changed already?

Copy link
Collaborator Author

@drewpc drewpc Jan 16, 2017

Choose a reason for hiding this comment

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

I just copied that from the other gulp files where jasmine was being used.

Copy link
Member

Choose a reason for hiding this comment

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

The other usage allows a CLI flag on the tests themselves to override specs (e.g. gulp test --specs Foo) and then appends a * to turn it into a glob prefix match if it isn't one already. I think here we could get rid of the if, unless we plan on supporting the CLI flag later.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, just realized this was left outstanding.

@drewpc @doug-wade Should we file a followup ticket for this?

Copy link
Contributor

Choose a reason for hiding this comment

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

Talked with @drewpc. Turns out this did get resolved. 😌

let cwd = process.cwd(),
lookupResult;

if (process.env.NODE_ENV === '__react-server-cli-unit-test__') { // eslint-disable-line no-process-env
Copy link
Collaborator

Choose a reason for hiding this comment

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

This doesn't seem right.

Copy link
Collaborator Author

@drewpc drewpc Jan 16, 2017

Choose a reason for hiding this comment

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

I agree. Got any other ideas on how to bypass callerDependency when running unit tests inside the same directory?

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure if it's better in the overall scheme of things (mockery is black magic), but could we use mockery to intercept requires of callerDependency from the spec itself? At least that way the complexity is in the spec, rather than here.

@drewpc
Copy link
Collaborator Author

drewpc commented Jan 17, 2017

This also fixes #534. I tested it specifically on Windows and it's working like a charm.

@@ -24,7 +37,11 @@ gulp.task("eslint", [], () => {
});

// there are no tests for this project :(
Copy link
Member

Choose a reason for hiding this comment

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

I think this comment can go away now :)

let cwd = process.cwd(),
lookupResult;

if (process.env.NODE_ENV === '__react-server-cli-unit-test__') { // eslint-disable-line no-process-env
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure if it's better in the overall scheme of things (mockery is black magic), but could we use mockery to intercept requires of callerDependency from the spec itself? At least that way the complexity is in the spec, rather than here.

// add a wildcard onto the end if no file extension or wildcard
// currently present
let specGlob = "*[Ss]pec.js";
if (!specGlob.endsWith(".js") && !specGlob.endsWith("*")) {
Copy link
Member

Choose a reason for hiding this comment

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

The other usage allows a CLI flag on the tests themselves to override specs (e.g. gulp test --specs Foo) and then appends a * to turn it into a glob prefix match if it isn't one already. I think here we could get rid of the if, unless we plan on supporting the CLI flag later.

@drewpc
Copy link
Collaborator Author

drewpc commented Jan 17, 2017

@roblg I can try to refactor that using a mock. That would be much cleaner, you're right.

@drewpc
Copy link
Collaborator Author

drewpc commented Jan 18, 2017

Finished refactoring the PR to use a mock of callerDependency instead of mangling it like I did before. Thanks for the ideas, guys!

Copy link
Contributor

@gigabo gigabo left a comment

Choose a reason for hiding this comment

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

This is a solid improvement and those tests are great! Thanks @drewpc!


const fileData = mockFs.toString();
filePathRegexStrings.map((regex) => {
expect(fileData).toMatch(regex.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"));
Copy link
Contributor

Choose a reason for hiding this comment

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

Wow, that's... quite a regex! 😳

let routesOutput = [];

const coreMiddleware = require.resolve("react-server-core-middleware");
const coreMiddleware = JSON.stringify(require.resolve("react-server-core-middleware"));
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, yeah, good call!

@gigabo gigabo merged commit 2e8d9c1 into redfin:master Jan 27, 2017
@drewpc drewpc modified the milestones: Production ready, 0.6.0 Jan 27, 2017
@drewpc drewpc deleted the patch-fix-file-path-issues branch February 5, 2017 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An issue with the system
Projects
None yet
Development

Successfully merging this pull request may close these issues.

File Path Issues in routes_client.js
4 participants