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

importLocal(__filename) returning an empty object, leading to local install which does not exist and skipping all ava tests #6

Closed
revelt opened this issue Jul 15, 2019 · 5 comments

Comments

@revelt
Copy link

revelt commented Jul 15, 2019

hi Sindre, maintainers and everybody else,

I would like to report a very strange issue and I hope you'll be able to shine some light on it.

I found that my ava, installed as a devdependency, was doing nothing, just silently exiting without an error. I placed some console.logs in the files in node_modules and it lead to this package, import-local — specifically, require(localFile) was returning an empty plain object:

return !filenameInLocalNodeModules && localFile && require(localFile);

now true + true + {} = empty plain object {} and it's truthy, which caused line if (importLocal(__filename)) to just do nothing:

if (importLocal(__filename)) {
	console.log('Using local version of this package');
} else {
	// Code for both global and local version here…
}

There was no globally installed package (ava) but importLocal above was returning truthy empty object and there was nowhere to run the tests on.

Do you have a clue what is going on?

By the way, if I clone this repo, npm i and run tests, they fail the "global" test:

test

What's also strange, my GItLab CI also has this issue and this morning ava unit tests seem to have silently skipped on the CI. That's Linux on a clean slate so something really strange is going on.

Maybe we should add more checks, for example, does importLocal(__filename) result object have keys (if it's an object)?

Thank you.

@gjbkz
Copy link
Contributor

gjbkz commented Jul 16, 2019

Hi @revelt, I have the same issue and I wrote #5 that will fix it. Using ava@2.1.0 is my workaround.

@revelt
Copy link
Author

revelt commented Jul 16, 2019

@Kei-Ito I'm on lerna too! So it might be a Lerna thing... I'll keep the issue open until #5 lands and then close this. Thank you very much!

@shellscape
Copy link

shellscape commented Jul 21, 2019

I'm getting the same thing using yarn workspaces. User reported that my CLI had stopped working when in a subdirectory of a repo.

Reproduction Repo: https://github.com/aaronjensen/webpack-nano-0.6.3-subdirectory-repro
Reported Issue: shellscape/webpack-nano#13

I've confirmed that the cause is the same. Returned object from require is {}.

@NetOpWibby
Copy link

Got the same issue and tracked it back to this. I had to settle for using ava 2.0.0 and getting updates to ignore ava via updates --update ./ --exclude ava.

@sindresorhus
Copy link
Owner

Fixed by #5

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

No branches or pull requests

5 participants