Skip to content

Scan for test helpers causes error when non-accessible folders present #1793

@maritz

Description

@maritz

Description

When there is a directory in your project that is unaccessible by the user runnig the tests, ava runs into an error during startup and exits.

In my case this is a volume created by the postgresql docker image and it resets the directory permissions on every start.

The problem is that the defaultHelperPatterns are set in a way that tries to read all directories and cannot be changed afaict.

Error Message & Stack Trace

glob error { Error: EACCES: permission denied, scandir '/home/maritz/{redacted}/db-volume/test'
  errno: -13,
  code: 'EACCES',
  syscall: 'scandir',
  path: '/home/maritz/{redacted}/db-volume/test' }
/home/maritz/{redacted}/node_modules/ava/lib/cli.js:206
					throw err;
					^

Error: EACCES: permission denied, scandir '/home/maritz/{redacted}/db-volume/__tests__/helpers'
    at handlePaths (/home/maritz/{redacted}node_modules/ava/lib/ava-files.js:14:18)
    at AvaFiles.findTestHelpers (/home/maritz/{redacted}/node_modules/ava/lib/ava-files.js:140:10)
    at Api._precompileHelpers (/home/maritz/{redacted}node_modules/ava/api.js:140:5)
    at _setupPrecompiler.then (/home/maritz/{redacted}/node_modules/ava/api.js:167:21)
    at <anonymous>

Making it work locally

When going manually into

const defaultHelperPatterns = () => [
and changing the defaultHelperPatterns to only scan my src folder it works fine.

const defaultHelperPatterns = () => [
  'src/**/__tests__/helpers/**/*.js',
  'src/**/__tests__/**/_*.js',
  'src/**/test/helpers/**/*.js',
  'src/**/test/**/_*.js',
];

Fix options?

I see two ways to properly fix this (aside from removing inaccessible directories):

  1. Add an option to change the defaultHelperPattern (related to Too slow in large projects #1418 (comment))
    or
  2. Catch EACCES errors and print out a warning and continue

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions