Skip to content
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

Make tests work with Karma and Chrome (Closes #60) #67

Merged
merged 2 commits into from
Aug 2, 2016
Merged
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
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
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

otherwise an older chromium is used

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,
},
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can have nice things


// 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"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

waiting for mishoo/UglifyJS#1229

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Can we make a GitHub issue and mention the related issue?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

filed #68

}
}
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',
},
});