Skip to content

Use Jest w/ Electron Runner so tests run & pass in a real browser #15

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
language: node_js
# default is apparently 0.10.48 for some reason O.O
node_js: '8.9'
node_js: '10.16.0'

# cache folder with Electron binary (https://github.com/electron/electron/blob/master/docs/tutorial/installation.md#cache)
cache:
directories:
- ~/.cache

# run with xvfb bc it's needed for Electron (https://docs.travis-ci.com/user/gui-and-headless-browsers/#using-the-xvfb-run-wrapper)
script: xvfb-run npm test
7 changes: 7 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
runner: '@jest-runner/electron',
testEnvironment: '@jest-runner/electron/environment',
// don't need to run babel on anything
// (and browserify bundle takes very long and sometimes errors out if we do)
transform: {}
}
11,766 changes: 7,534 additions & 4,232 deletions package-lock.json

Large diffs are not rendered by default.

16 changes: 4 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,20 @@
],
"scripts": {
"changelog": "changelog-maker",
"test": "npm run clean && npm run browserify && npm run webpack && ava",
"test:browserify": "npm run browserify && ava test/browserify.spec.js",
"test:webpack": "npm run webpack && ava test/webpack.spec.js",
"test": "npm run clean && npm run browserify && npm run webpack && jest",
"browserify": "node test/build-config/_browserify.config.js",
"webpack": "webpack --config test/build-config/_webpack.config.js",
"clean": "rm -rf build/ && mkdir build/"
},
"ava": {
"require": [
"./test/utils/_setup-browser-env.js"
]
},
"peerDependencies": {
"three": "^0.73.0"
},
"devDependencies": {
"@agilgur5/changelog-maker": "^3.0.0",
"@react-frontend-developer/jsdom-worker": "^0.1.1",
"ava": "^2.1.0",
"browser-env": "^3.2.6",
"@jest-runner/electron": "^2.0.2",
"browserify": "^16.2.3",
"node-fetch": "^2.6.0",
"electron": "^7.1.2",
"jest": "^24.9.0",
"three": "^0.73.2",
"webpack": "^4.34.0",
"webpack-cli": "^3.3.4",
Expand Down
12 changes: 6 additions & 6 deletions test/browserify.spec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import test from 'ava'
const Physijs = require('./utils/browserify/_import-bundle-to-module.js')

import Physijs from './utils/browserify/_import-bundle-to-module.js'

test('Scene creation', t => {
const scene = new Physijs.Scene()
t.is(scene.type, 'Scene')
describe('browserify', () => {
it('should create a scene', () => {
const scene = new Physijs.Scene()
expect(scene.type).toBe('Scene')
})
})
2 changes: 0 additions & 2 deletions test/utils/_setup-browser-env.js

This file was deleted.

12 changes: 6 additions & 6 deletions test/webpack.spec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import test from 'ava'
const Physijs = require('./utils/webpack/_import-bundle-to-module.js')

import Physijs from './utils/webpack/_import-bundle-to-module.js'

test('Scene creation', t => {
const scene = new Physijs.Scene()
t.is(scene.type, 'Scene')
describe('webpack', () => {
it('should create a scene', () => {
const scene = new Physijs.Scene()
expect(scene.type).toBe('Scene')
})
})