Feathers: Tests using jest sometimes fails for generated app on windows platform

Created on 5 Nov 2019  ·  3Comments  ·  Source: feathersjs/feathers

Steps to reproduce

  • [ ] Tell us what broke. The more detailed the better.
    After generating and app and not changing anything, the jest test suite is not working all the time on windows.

  • [ ] If you can, please create a simple example that reproduces the issue and link to a gist, jsbin, repo, etc. This makes it much easier for us to debug and issues that have a reproducable example will get higher priority.

feathers generate app
? Do you want to use JavaScript or TypeScript? JavaScript
? Project name feathers
? Description
? What folder should the source files live in? src
? Which package manager are you using (has to be installed globally)? Yarn
? What type of API are you making? (Press <space> to select, <a> to toggle all, <i> to invert selection)REST, Realtime v
ia Socket.io
? Which testing framework do you prefer? Jest
? This app uses authentication Yes
? What authentication strategies do you want to use? (See API docs for all 180+ supported oAuth providers) Username + Pa
ssword (Local)
? What is the name of the user (entity) service? users
? What kind of service is it? NeDB
? What is the database connection string? nedb://../data

yarn jest

Expected behavior

All the tests pass all the time.

Actual behavior

I always get this:

\feathers\node_modules\nedb\lib\datastore.js:77
    if (err) { throw err; }
               ^

[Error: EPERM: operation not permitted, rename 'C:\Users\stef\feathers\data\users.db~' -> 'C:\Users\stef\feathers\data\users.db'] {
  errno: -4048,
  code: 'EPERM',
  syscall: 'rename',
  path: 'C:\\Users\\stef\\feathers\\data\\users.db~',
  dest: 'C:\\Users\\stef\\feathers\\data\\users.db'
}

And then sometimes the tests pass and sometimes not (! I tried with a 30000ms timeout, same result)

    : Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.Error:

      20 |     });
      21 |
    > 22 |     it('authenticates user and creates accessToken', async () => {
         |     ^
      23 |       const { user, accessToken } = await app.service('authentication').create({
      24 |         strategy: 'local',
      25 |         ...userInfo

      at new Spec (node_modules/jest-jasmine2/build/jasmine/Spec.js:116:22)
      at Suite.<anonymous> (test/authentication.test.js:22:5)
      at Suite.<anonymous> (test/authentication.test.js:8:3)
      at Object.<anonymous> (test/authentication.test.js:3:1)

Test Suites: 1 failed, 2 passed, 3 total
Tests:       1 failed, 5 passed, 6 total
Snapshots:   0 total
Time:        25.515s

System configuration

NodeJS version:
v12.13.0

Operating System:
Windows 10

Most helpful comment

I ran some test on Ubuntu and I noticed the same kind of random problems.
I think I found the culprit. It's probably NeDB which uses a file. And as it is configured now, jest run the tests in parallel which causes random conflicts.
Running jest with the --runInBand option , I do not have any more problems.
This issue can be closed.

All 3 comments

I ran some test on Ubuntu and I noticed the same kind of random problems.
I think I found the culprit. It's probably NeDB which uses a file. And as it is configured now, jest run the tests in parallel which causes random conflicts.
Running jest with the --runInBand option , I do not have any more problems.
This issue can be closed.

@daffl I think this issue should be re-open for more investigation.

I tried --runInBand option but I still have the same issue:

[Error: ENOENT: no such file or directory, rename '/home/sullivan/p/gitlab.com/project/api/test/data/rides.db~' -> '/home/sullivan/p/gitlab.com/project/api/test/data/rides.db'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'rename',
  path: '/home/sullivan/p/gitlab.com/data/api/test/data/rides.db~',
  dest: '/home/sullivan/p/gitlab.com/data/api/test/data/rides.db'
}

I would love to add useful additional information, but I will need some clues about what you want to debug. :+1:

I also see a similar issue when using Jest with GitHub Action runners. The tests run fine on my local machine with macOS. I suspect the tests need to be updated to either (a) use an in-memory database, or (b) use a dynamic filename for each test. I am new to the Fathers ecosystem, so have no idea how to implement either.

At a minimum, it would be great if the docs were updated to better reflect the limited support for Jest. I remember there being a tutorial, or the wizard that suggested choosing Mocha; however, I have more experience with Jest, so I went with it. I would have made a different decision if the docs better explained the tradeoffs.

Update 1: I followed the steps at https://burnedikt.com/feathers-and-nedb-for-testing/ to update my tests to use the in-memory database.

Update 2: Feathers CLI assumes the connectionString is a single string (e.g., the path). You'll need to revert the changes made to config/default.json so that nedb is a string in order to use the service generator with an NeDB-backed service.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

eric-burel picture eric-burel  ·  3Comments

codeus-de picture codeus-de  ·  4Comments

Mattchewone picture Mattchewone  ·  4Comments

rstegg picture rstegg  ·  3Comments

arve0 picture arve0  ·  4Comments