avajs / ava

Node.js test runner that lets you develop with confidence 🚀
MIT License
20.74k stars 1.41k forks source link

ava requires sudo to run #1128

Closed tonyeung closed 7 years ago

tonyeung commented 7 years ago

Description

Ava has permissions issues when trying to read/write the node_modules/.cache folder and sub folders. Manually creating the folders and running ava again will cause the next fs operation to fail. Running ava with sudo (sudo ava) will let ava run as expected.

Is it intended for ava to run with su permissions or require the user to give ava rw permissions to the .cache/ava folder?

Test Source

import test from 'ava';
test('smoke test', (t) => {
    t.deepEqual(true, true)
});

Error Message & Stack Trace

# EACCES: permission denied, mkdir '/home/ton/Documents/ng2-frontend/node_modules/.cache'
not ok 1 - EACCES: permission denied, mkdir '/home/ton/Documents/ng2-frontend/node_modules/.cache'
  ---
    name: Error
    at: at Object.fs.mkdirSync (fs.js:846:18)
  ...

1..0
# tests 0
# pass 0
# fail 1

Config

Copy the relevant section from package.json:

{
  "ava": {
    "files": [
      "app/**/*-test.js"
    ],
    "source": [
      "!app/**/*-test.js",
      "app/**/*.js"
    ],
    "concurrency": 5,
    "failFast": true,
    "tap": true,
    "powerAssert": false
  }
}

Command-Line Arguments

Copy your npm build scripts or the ava command used:

ava 

// no command line arguments are passed

Relevant Links

Environment

Tell us which operating system you are using, as well as which versions of Node.js, npm, and AVA. Run the following to get it quickly:

node -e "var os=require('os');console.log('Node.js ' + process.version + '\n' + os.platform() + ' ' + os.release())"
Node.js v7.1.0
linux 4.4.0-47-generic

ava --version
0.17.0
npm --version
4.0.2
tonyeung commented 7 years ago

opened an issue here first https://github.com/avajs/find-cache-dir/issues/4

tonyeung commented 7 years ago

not sure why this was happening but it works fine without sudo now

tonyeung commented 7 years ago

okay, so i screwed up the test file name so ava coudn't find anything to test. After fixing the issue, the same errors are happening again.

ORESoftware commented 7 years ago

Try this:

sudo chown -R $(whoami) $(npm root -g) $(npm root) ~/.npm

after that, you probably won't need to use sudo anymore

tonyeung commented 7 years ago

@ORESoftware thanks for the advice. I'm going to close these issues since I don't intend on using ava anymore.

novemberborn commented 7 years ago

For future reference, I suspect the issue here is that dependencies were installed using sudo npm install. That causes node_modules to be created with unhelpful permissions. There's ways to change those but really you should avoid using npm with sudo.

If you've gotten into this habit for other reasons, perhaps see https://docs.npmjs.com/getting-started/fixing-npm-permissions on how to fix it.

JJ commented 4 years ago

That might be the issue, but still the problem is that ava is creating a node_modules local dir if there's none create or if it's been installed globally. Captura de pantalla de 2020-10-26 19-33-35 This seems to be a genuine issue. In this case, there's no problem since the docker user is privileged to write in the mounted directory. It might be, however. You don't necessarily need to have sudo access, but you do need to have write access to the directory where ava is running.

novemberborn commented 3 years ago

@JJ fair enough, https://github.com/avajs/ava/pull/2628 should help if you use plain AVA (no Babel or TypeScript providers).