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

don't cache dependencies installed with file: protocol - add unit test #2443

Merged
merged 3 commits into from
Jan 25, 2017

Conversation

donaldpipowitch
Copy link
Contributor

Summary

I try to fix #2165. For now I just added a failing unit test. I've spoken with @bestander about this.

Test plan

An example is described here: #2165. And this PR contains a failing unit test. I try to install a dependency from a local file with content foo\n. Than I change the content to bar\n and install it again. It should now be bar\n, but it is still foo\n


@bestander I'm not sure this unit test works as expected. It looks like all tests assert only in the cache directory (?) given with config.cwd. In my fixtures folder no dependency is added which I could check directly. Could you review the test?
Is there any way to get a nicer test output when I only run one test? I do $ npm run -s test-only -- -t 'without cache', but the output is quite verbose (e.g. contains a lot of Unhandled promise rejection errors which seems to result from skipping the other tests).

Copy link
Member

@bestander bestander left a comment

Choose a reason for hiding this comment

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

A few nits and links needed

const fixturesLoc = path.join(__dirname, '..', '..', 'fixtures', 'install');
const compLoc = path.join(fixturesLoc, 'install-file-without-cache', 'comp', 'index.js');

return fs.writeFile(compLoc,'foo\n').then(() =>
Copy link
Member

Choose a reason for hiding this comment

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

No reason to mix promises and async/await.
await fs.writeFile would work here, too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Even better! I just followed the style of most tests returning the first promise (mostly return runInstall).

await fs.writeFile(compLoc, 'bar\n');
await runInstall({noLockfile: true}, 'install-file-without-cache');
assert.equal(
await fs.readFile(path.join(config.cwd, 'node_modules', 'comp', 'index.js')),
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 here you still read from the first install.
config.cwd comes as argument to runInstall.
Instead make this check inside the runInstall callback and double check that we are not testing the same location.

await runInstall({noLockfile: true}, 'install-file-without-cache');
assert.equal(
await fs.readFile(path.join(config.cwd, 'node_modules', 'comp', 'index.js')),
'bar\n',
Copy link
Member

Choose a reason for hiding this comment

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

We can't merge a failing test, once you make sure it works correctly, can you switch the last assert to the opposite so that this test described the current behavior and add a link to the issue?
So that it would be easy to switch the assert when working on the fix.

@donaldpipowitch
Copy link
Contributor Author

donaldpipowitch commented Jan 16, 2017

@bestander I changed the unit test... an now I'm surprised. It passes 😮 Was this fixed already? It doesn't seem so... when I make a manual test with my local version v0.20.0-0 it still install local files from cache even when they have changed.

@bestander
Copy link
Member

Ha ha, probably not.
The test passes because 2 runInstall calls are executed sandboxed.
The trick is to call runInstall once and for the second time call Install function which does not create a new sandbox.
See https://github.com/yarnpkg/yarn/blob/master/__tests__/commands/install/integration.js#L306

@donaldpipowitch
Copy link
Contributor Author

@bestander I updated the unit test so it uses Install. I used notEqual in the last assertion and linked to this pull request to have a "working" unit test. Thank you very much for your help so far.

@bestander
Copy link
Member

bestander commented Jan 24, 2017 via email

@bestander bestander merged commit fff789e into yarnpkg:master Jan 25, 2017
@bestander
Copy link
Member

Thanks, that will help to keep track of it.
Let me know if you want to collaborate on the fix next.
Feel free to cc me in a PR with some ideas.

@donaldpipowitch
Copy link
Contributor Author

Thank you a lot. Yeah, I'll try to fix the bug with another PR.

@donaldpipowitch donaldpipowitch deleted the dont-cache-local-files-2165 branch January 26, 2017 06:51
@simonbuchan
Copy link

:( the PR title is a bit misleading...

@donaldpipowitch donaldpipowitch changed the title don't cache dependencies installed with file: protocol - fixes #2165 don't cache dependencies installed with file: protocol - add unit test Jan 27, 2017
@donaldpipowitch
Copy link
Contributor Author

Yes. I changed that. I'm sorry. In the beginning thought this would be an ongoing PR, but that idea was changed to two separate PRs: the first PR just adds a unit test, the second PR will fix it.

ConAntonakos pushed a commit to ConAntonakos/yarn that referenced this pull request Jan 30, 2017
…g#2165 (yarnpkg#2443)

* added failing unit test for yarnpkg#2165

* fixed unit test

* updated unit test
@moimikey
Copy link

test for this was merged, but what's the status on the actual fix? its been mentioned in previous issues about the pain points of caching file: paths and the cache not updating to reflect new changes. the response has been to help contribute, but it's a time waster for another person to contribute if this is almost actually done.

@donaldpipowitch
Copy link
Contributor Author

As said here (#2165 (comment)) I couldn't start another PR and AFAIK no one else did.

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

Successfully merging this pull request may close these issues.

yarn probably shouldn't cache packages resolved with a file path
4 participants