Skip to content

Commit a2d142d

Browse files
committed
(refactor/test): switch to cypress as test environment
- use a full browser for testing instead of running in Node and relying on JSDOM, which does not implement all of the features we use (namely worker-related stuff) - this ensures tests run without any errors - use cypress's webpack and browserify preprocessors to bundle up the code and tests for each instead of building the bundles outside of the test process - at least one of these is needed (browserify is cypress's default) because we use `require` in tests, which isn't available in a browser ofc - and actually using the browserify preprocessor on the browserify bundle caused lots of errors (it seems to use its own `require` when parsing the bundle, causing module not found errors) - no need for several package.json scripts anymore - no need for webpack-cli anymore - no need for helper files for import / export anymore - move the webpack and browserify config into the cypress preprocessor config - cypress handles input and output, so those sections can be entirely removed, basically just leaving noParse - can't use externals here because those have to be provided to the browser (otherwise will give a ReferenceError) - move the tests to cypress/integration/, cypress's default folder - and refactor them to cypress's mocha/chai style from AVA style - basically everything was (re)moved from test/ to cypress/
1 parent 713f6a9 commit a2d142d

18 files changed

+2491
-3537
lines changed

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
build/
2-
31
### Node ###
42

53
# Logs

cypress.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"video": false,
3+
"modifyObstructiveCode": false
4+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const Physijs = require('../../browserify.js')
2+
3+
describe('browserify', () => {
4+
it('should create a scene', () => {
5+
const scene = new Physijs.Scene()
6+
expect(scene.type).to.eq('Scene')
7+
})
8+
})
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const Physijs = require('../../webpack.js')
2+
3+
describe('webpack', () => {
4+
it('should create a scene', () => {
5+
const scene = new Physijs.Scene()
6+
expect(scene.type).to.eq('Scene')
7+
})
8+
})

cypress/plugins/index.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const browserify = require('@cypress/browserify-preprocessor')
2+
const webpack = require('@cypress/webpack-preprocessor')
3+
4+
const ammoPath = require.resolve('../../physijs/vendor/ammo.js')
5+
6+
const bProcess = browserify({
7+
browserifyOptions: {
8+
// don't parse ammo
9+
noParse: [ammoPath],
10+
// override the preprocessor default (which runs babelify)
11+
transform: []
12+
}
13+
})
14+
15+
const wProcess = webpack({
16+
webpackOptions: {
17+
// fast builds, build is only used for testing purposes
18+
mode: 'development',
19+
// don't parse ammo
20+
module: {
21+
noParse: ammoPath,
22+
}
23+
}
24+
})
25+
26+
module.exports = (on) => {
27+
// process webpack test w/ webpack and browserify test w/ browserify
28+
on('file:preprocessor', (file) => {
29+
if (file.filePath.includes('webpack.spec.js')) {
30+
return wProcess(file)
31+
}
32+
return bProcess(file)
33+
})
34+
}

cypress/support/commands.js

Whitespace-only changes.

cypress/support/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
require('./commands')
2+
3+
// nothing to screenshot here
4+
Cypress.Screenshot.defaults({
5+
screenshotOnRunFailure: false
6+
})

package-lock.json

Lines changed: 2427 additions & 3459 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,31 +36,19 @@
3636
],
3737
"scripts": {
3838
"changelog": "changelog-maker",
39-
"test": "npm run clean && npm run browserify && npm run webpack && ava",
40-
"test:browserify": "npm run browserify && ava test/browserify.spec.js",
41-
"test:webpack": "npm run webpack && ava test/webpack.spec.js",
42-
"browserify": "node test/build-config/_browserify.config.js",
43-
"webpack": "webpack --config test/build-config/_webpack.config.js",
44-
"clean": "rm -rf build/ && mkdir build/"
45-
},
46-
"ava": {
47-
"require": [
48-
"./test/utils/_setup-browser-env.js"
49-
]
39+
"test": "cypress run"
5040
},
5141
"peerDependencies": {
5242
"three": "^0.73.0"
5343
},
5444
"devDependencies": {
5545
"@agilgur5/changelog-maker": "^3.0.0",
56-
"@react-frontend-developer/jsdom-worker": "^0.1.1",
57-
"ava": "^2.1.0",
58-
"browser-env": "^3.2.6",
46+
"@cypress/browserify-preprocessor": "^2.1.1",
47+
"@cypress/webpack-preprocessor": "^4.1.1",
5948
"browserify": "^16.2.3",
60-
"node-fetch": "^2.6.0",
49+
"cypress": "^3.6.1",
6150
"three": "^0.73.2",
6251
"webpack": "^4.34.0",
63-
"webpack-cli": "^3.3.4",
6452
"webworkify": "^1.5.0",
6553
"worker-loader": "^2.0.0"
6654
}

test/browserify.spec.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)