facebook-atom / jest-electron-runner

custom test runner for Jest that allows tests to be run in Electron environment
MIT License
189 stars 33 forks source link

How do you configure to run Atom package specs? #13

Closed stevenzeck closed 5 years ago

stevenzeck commented 5 years ago

Is it possible to have this act as a test runner for Atom packages? I have "atomTestRunner": "@jest-runner/electron", in my package.json and runner and testEnvironment in my jest config, but I just get this error:

Error: Cannot find module 'jest-mock'
    at Module._resolveFilename (module.js:543:15)
aaronabramov commented 5 years ago

@stevenzeck it won't work with atom test runner, you should make it a separate jest project (see Readme)

stevenzeck commented 5 years ago

Not sure what you mean. I'm just looking for a Jest test runner for Atom, runners as described here: https://flight-manual.atom.io/hacking-atom/sections/writing-specs/#customizing-your-test-runner

aaronabramov commented 5 years ago

@stevenzeck this project is independent from atom and does not use "atomTestRunner" :)

banacorn commented 5 years ago

@stevenzeck I'm also looking for a atom test runner, did you found one? :D

aaronabramov commented 5 years ago

@banacorn i built an atom runner a while ago and it's open sourced here https://github.com/facebookarchive/nuclide/tree/master/modules/jest-atom-runner

it does run tests in a full atom environment with all atom globals, however i'm not planning on maintaining it

banacorn commented 5 years ago

Thanks! This is wonderful! 😄

banacorn commented 5 years ago

@aaronabramov is there any example Atom package that is using the jest-atom-runner, because I still can't figure how to use it :(

aaronabramov commented 5 years ago

@banacorn nuclide used it https://github.com/facebookarchive/nuclide/blob/master/jest/jest.config.atom.js

wadethestealth commented 5 years ago

@aaronabramov I would be interested in maintaining something like this. But after setting up and running I get this

Service path not specified, so defaulting to ipc.config.socketRoot + ipc.config.appspace + id 
requested connection to  spec /tmp/app.spec
Connecting client on Unix Socket : /tmp/app.spec

######
error:  { Error: connect ENOENT \\.\pipe\tmp-app.spec
    at Object._errnoException (util.js:1024:11)
    at _exceptionWithHostPort (util.js:1046:20)
    at PipeConnectWrap.afterConnect [as oncomplete] (net.js:1182:14)
  code: 'ENOENT',
  errno: 'ENOENT',
  syscall: 'connect',
  address: '\\\\.\\pipe\\tmp-app.spec' }
connection closed spec /tmp/app.spec Infinity tries remaining of Infinity

I would really appreciate it if you could help me at least with the setup, so that I could do a deep dive into how the code all works

Edit: I just tried source building nuclide and I got the same result. I believe the reason for this is because the worker id remains undefined from my test cases because the path sent as test path 0 is just a folder and therefore when you .split('_') the base file path to make a worker id and server id., the worker id will be undefined since there is no underscore in the folder name. So what does a good firstpath look like? Were you sending a fake filepath via nuclide before? How can I replicate that behavior if so?

Edit 2: After rewriting utils to temporarily give me back two static ids ("served" and "worked"). It seems that the server is never started. I see where a server is supposed to be started inside index (the TestRunner) but jest never even gets to build your TestRunner because atom will await a connection to a nonexistent server for infinity. When/Where is the server supposed to be started if it is always awaiting an initial connection to run test?

~Edit 3: After temporarily starting the server directly before the awaiting connection, I connect and get it to send the initialize message. After that however, chrome (ie the Specs window) is constantly trying to reevaluate if react exists. How can I get past this evaluation?~ Seems like this isn't the route to go.