Skip to content

Commit

Permalink
new unit tests with karma + webpack + react + mocha
Browse files Browse the repository at this point in the history
  • Loading branch information
ngokevin committed Mar 27, 2017
1 parent a80d717 commit 6b2a273
Show file tree
Hide file tree
Showing 6 changed files with 6,097 additions and 27 deletions.
23 changes: 21 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
sudo: required
dist: trusty
language: node_js
addons:
firefox: 'latest'
apt:
sources:
- google-chrome
packages:
- google-chrome-stable

node_js:
- '4.6'

install:
- npm install
# Firefox.
- ./node_modules/.bin/mozilla-download ./firefox/ --product firefox --branch mozilla-aurora
- export FIREFOX_NIGHTLY_BIN="./firefox/firefox/firefox-bin"
# Chrome.
- export CHROME_BIN=/usr/bin/google-chrome

before_script:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start

script:
- $CI_ACTION
Expand All @@ -13,8 +31,9 @@ env:
global:
- TEST_SUITE=unit
matrix:
# - CI_ACTION="npm run test:react:ci"
- CI_ACTION="npm run test:ci"
- CI_ACTION="jest"
- CI_ACTION="npm run test:chrome -- --single-run"
- CI_ACTION="npm run test:firefox -- --single-run"

branches:
only:
Expand Down
27 changes: 21 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,45 @@
"scripts": {
"build": "babel src -d dist",
"prepublish": "npm run build",
"test:ci": "mocha --compilers js:babel-register tests/unit",
"test": "npm run test:ci -- --watch",
"test:react:ci": "jest",
"test:react": "npm run test:react:ci -- --watch"
"test": "karma start ./tests/browser/karma.conf.js",
"test:chrome": "karma start ./tests/browser/karma.conf.js --browsers Chrome",
"test:firefox": "karma start ./tests/browser/karma.conf.js --browsers Firefox",
"test:react": "jest --watch"
},
"jest": {
"testPathDirs": [
"tests/react"
]
},
"devDependencies": {
"aframe": "^0.5.0",
"babel": "^6.3.13",
"babel-cli": "^6.3.15",
"babel-jest": "^16.0.0",
"babel-loader": "^6.4.1",
"babel-preset-es2015": "^6.3.13",
"babel-preset-react": "^6.3.13",
"babel-preset-stage-0": "^6.3.13",
"babel-register": "^6.16.3",
"enzyme": "^2.8.0",
"chai": "^3.5.0",
"chai-shallow-deep-equal": "^1.4.6",
"jest": "^16.0.1",
"karma": "^0.13.15",
"karma-chai-shallow-deep-equal": "0.0.4",
"karma-chrome-launcher": "2.0.0",
"karma-firefox-launcher": "^0.1.7",
"karma-mocha": "^0.2.1",
"karma-mocha-reporter": "^1.1.3",
"karma-sinon-chai": "^1.1.0",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^2.0.3",
"mocha": "^3.1.2",
"react": "^15.3.2",
"react-dom": "^15.3.2",
"react-test-renderer": "^15.3.2"
"react-test-renderer": "^15.3.2",
"sinon": "1.17.5",
"sinon-chai": "2.8.0",
"webpack": "^2.3.2"
},
"peerDependencies": {
"react": "*",
Expand Down
34 changes: 34 additions & 0 deletions tests/browser/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import 'aframe';
import React from 'react';
import ReactDOM from 'react-dom';
import {Entity, Scene} from '../../src/index.js';

suite('test', () => {
const div = document.createElement('div');
document.body.appendChild(div);

teardown(() => {
div.innerHTML = '';
});

test('scene and entity are rendered', () => {
ReactDOM.render(<Scene><Entity/></Scene>, div);
assert.ok(div.querySelector('a-scene a-entity'));
});

test('entity has component passed as string', () => {
ReactDOM.render(<Scene><Entity position="1 2 3"/></Scene>, div);
div.querySelector('a-scene').addEventListener('loaded', () => {
assert.shallowDeepEqual(div.querySelector('a-entity').getAttribute('position'),
{x: 1, y: 2, z: 3});
});
});

test('entity has component passed as object', () => {
ReactDOM.render(<Scene><Entity position={{x: 1, y: 2, z: 3}}/></Scene>, div);
div.querySelector('a-scene').addEventListener('loaded', () => {
assert.shallowDeepEqual(div.querySelector('a-entity').getAttribute('position'),
{x: 1, y: 2, z: 3});
});
});
});
38 changes: 38 additions & 0 deletions tests/browser/karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Karma configuration.
module.exports = function (config) {
config.set({
basePath: '../',
browsers: ['Firefox', 'Chrome'],
client: {
captureConsole: true,
mocha: {ui: 'tdd'}
},
files: [
// Define test files.
{pattern: 'browser/**/*.test.js'}
],
frameworks: ['mocha', 'sinon-chai', 'chai-shallow-deep-equal'],
preprocessors: {
'src/**/*.js': ['webpack'],
'browser/**/*.js': ['webpack']
},
reporters: ['mocha'],
webpack: {
devtool: 'inline-source-map',
module: {
rules: [
{
test: /\.js?$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['es2015', 'react', 'stage-0']
}
}
}
]
}
}
});
};
19 changes: 0 additions & 19 deletions tests/unit/index.test.js

This file was deleted.

Loading

0 comments on commit 6b2a273

Please sign in to comment.