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

Use root project's Electron so native modules resolve correctly #8

Closed aguynamedben closed 5 years ago

aguynamedben commented 5 years ago

Prefer the Electron installed in the project's root directory. This allows the user's Electron version to be used when resolving native native module paths. Example: (notice v3.0 vs. v2.0) node_modules/sqlite3/lib/binding/electron-v3.0-darwin-x64/node_sqlite3.node vs. node_modules/sqlite3/lib/binding/electron-v2.0-darwin-x64/node_sqlite3.node For development, the Electron version in jest-electron-runner's package.json will be used. https://github.com/facebook-atom/jest-electron-runner/issues/6

facebook-github-bot commented 5 years ago

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed.

If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks!

aaronabramov commented 5 years ago

thanks @aguynamedben! i think we already have a root path somewhere in the config, but we can always fix it later!

aaronabramov commented 5 years ago

actually, do you mind signing the CLA for this PR @aguynamedben ?

aguynamedben commented 5 years ago

I just signed it, then I saw it revert... should be good now.

aguynamedben commented 5 years ago

Since this wont be merged into the packaged @jest-runner/electron immediately, I'm trying to include it in my project like this...

package.json devDependencies points to the specific commit sha1:

    "jest-electron-runner": "https://github.com/facebook-atom/jest-electron-runner.git#f629d50b1531c9defcee2975545ce08e0d534ba2",

When I run yarn everything installs. When I run my tests they fail with ./node_modules/jest-electron-runner has not had yarn build run on it. Do you know how I can automatically run the build command after my sha1 version of jest-electron-runner is installed?

$ cross-env NODE_ENV=test BABEL_DISABLE_CACHE=1 node --trace-warnings -r babel-register ./internals/scripts/RunTests.js
Error: Cannot find module './build/TestRunner.js'

Furthermore, when I do manually try to build, I get a flow error:

$ node_modules/jest-electron-runner
$ yarn
$ yarn build
yarn run v1.12.1
$ flow-node ./scripts/build
/Users/ben/code/tesla/node_modules/jest-electron-runner/scripts/build.js:50
  const columns: number = process.stdout.columns || 80;
        ^^^^^^^

SyntaxError: Missing initializer in const declaration

I can manually hack line 50 of build.js to get rid of the flow problem:

  const columns = process.stdout.columns || 80;

After hacking this line up, yarn build runs (within ./node_modules as a hack) and my tests work. But obviously that's a lot of manual steps for a workaround. Any workaround ideas are appreciated!

aaronabramov commented 5 years ago

i'm waiting for the CI to pass and if it's green i can release the new version in 10 min :)

aguynamedben commented 5 years ago

Worddd!!! Where do I send beer money, haha.

aaronabramov commented 5 years ago

@aguynamedben you can always contribute to jest open collective haha https://opencollective.com/jest