Skip to content

Commit

Permalink
Make tests work with Karma and Chrome (Closes #60) (#67)
Browse files Browse the repository at this point in the history
* Make tests work with Karma and Chrome (Closes #60)

* Fix the version of UglifyJS to prevent an issue with our files
  • Loading branch information
julienw authored and samgiles committed Aug 2, 2016
1 parent c12d9dd commit 7947e3e
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 2 deletions.
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6
14 changes: 14 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
language: node_js
sudo: required
dist: trusty
addons:
apt:
sources:
google-chrome
packages:
google-chrome-stable
before_install:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
- sleep 3 # give xvfb some time to start
- export CHROME_BIN=google-chrome
9 changes: 8 additions & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,19 @@ module.exports = function(config) {
},
{ pattern: 'node_modules/react-dom/dist/react-dom.js', included: false },
{ pattern: 'node_modules/rxjs/bundles/Rx.umd.js', included: false },
{ pattern: 'node_modules/chrono-node/chrono.min.js', included:false },
{ pattern: 'node_modules/moment/moment.js', included: false },
{ pattern: 'node_modules/twitter_cldr/min/*.js', included: false },
'tests/unit/test-main.js',
],

// Test results reporter to use.
reporters: ['mocha'],

mochaReporter: {
showDiff: true,
},

// Web server port.
port: 9876,

Expand All @@ -42,7 +49,7 @@ module.exports = function(config) {

// Start these browsers, available browser launchers:
// https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Firefox'],
browsers: ['Chrome'],


// Continuous Integration mode, if true, Karma captures browsers, runs the
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,6 @@
"sinon-chai": "^2.8.0",
"stylelint": "^6.5.1",
"stylelint-config-standard": "^8.0.0",
"uglify-js": "github:mishoo/UglifyJS2#harmony"
"uglify-js": "github:mishoo/UglifyJS2#766fafda8baefe6d150df27dfad7e99857c08557"
}
}
10 changes: 10 additions & 0 deletions tests/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"env": {
"mocha": true,
"node": true,
},
"globals": {
"assert": true,
}
}

38 changes: 38 additions & 0 deletions tests/unit/intent-parser_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import moment from 'components/moment';
import IntentParser from 'js/lib/intent-parser';

describe('intent-parser', function() {
describe('Properly parses expected reminder sentences', function() {
const fixtures = [
{
sentence: 'Remind me to go to the office by 5pm',
parsed: {
users: ['me'],
action: 'go to the office',
confirmation:
'OK, I\'ll remind you to go to the office at 5 PM today.',
time: moment({ hour: 17 }).toDate(),
},
},
{
sentence: 'Remind John by tomorrow to take out trash',
parsed: {
users: ['John'],
action: 'take out trash',
confirmation:
'OK, I\'ll remind John to take out trash at 12 PM tomorrow.',
time: moment({ hour: 12 }).add(1, 'day').toDate(),
},
},
];

fixtures.forEach(({ sentence, parsed }) => {
it(sentence, function() {
const intentParser = new IntentParser();
return intentParser.parse(sentence).then((result) => {
assert.deepEqual(result, parsed);
});
});
});
});
});
38 changes: 38 additions & 0 deletions tests/unit/test-main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* eslint no-var: "off" */

var allTestFiles = [];
var TEST_REGEXP = /(spec|test)\.js$/i;

// Get a list of all the test files to include
Object.keys(window.__karma__.files).forEach(function(file) {
if (TEST_REGEXP.test(file)) {
// Normalize paths to RequireJS module names.
allTestFiles.push(file.replace(/^\/base\/|\.js$/g, ''));
}
});

require.config({
// Karma serves files under /base, which is the basePath from config file.
baseUrl: '/base',
deps: allTestFiles,
callback: window.__karma__.start,

// ReactDOM expects "react" module to be defined, but it is not.
map: {
'*': {
'react': 'components/react',
},
},

paths: {
'js': 'dist/tests/unit',
// Addons include React TestUtils.
'components/react': 'node_modules/react/dist/react-with-addons',
'components/react-dom': 'node_modules/react-dom/dist/react-dom',
'components/chrono': 'node_modules/chrono-node/chrono.min',
'components/moment': 'node_modules/moment/moment',
'components/cldr/core': 'node_modules/twitter_cldr/min/core.min',
'components/cldr/en': 'node_modules/twitter_cldr/min/en.min',
'rxjs': 'node_modules/rxjs/bundles/Rx.umd',
},
});

0 comments on commit 7947e3e

Please sign in to comment.