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

Tests using jest sometimes fails for generated app on windows platform #1667

Closed
2 tasks
stephane303 opened this issue Nov 5, 2019 · 3 comments
Closed
2 tasks

Comments

@stephane303
Copy link

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

@stephane303 stephane303 changed the title Tests sometimes fails for generated app on windows platform Tests using jest sometimes fails for generated app on windows platform Nov 5, 2019
@stephane303
Copy link
Author

stephane303 commented Nov 5, 2019

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.

@soullivaneuh
Copy link

@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. 👍

@clintonb
Copy link

clintonb commented Apr 18, 2021

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.

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

4 participants