diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 0000000..1e8b314 --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +6 diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..763bb0e --- /dev/null +++ b/.travis.yml @@ -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 diff --git a/karma.conf.js b/karma.conf.js index 62bdd9f..44666b3 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -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, @@ -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 diff --git a/package.json b/package.json index a76f84e..a036a19 100644 --- a/package.json +++ b/package.json @@ -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" } } diff --git a/tests/.eslintrc b/tests/.eslintrc new file mode 100644 index 0000000..5cd0463 --- /dev/null +++ b/tests/.eslintrc @@ -0,0 +1,10 @@ +{ + "env": { + "mocha": true, + "node": true, + }, + "globals": { + "assert": true, + } +} + diff --git a/tests/unit/intent-parser_test.js b/tests/unit/intent-parser_test.js new file mode 100644 index 0000000..bf1679a --- /dev/null +++ b/tests/unit/intent-parser_test.js @@ -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); + }); + }); + }); + }); +}); diff --git a/tests/unit/test-main.js b/tests/unit/test-main.js new file mode 100644 index 0000000..08ff84f --- /dev/null +++ b/tests/unit/test-main.js @@ -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', + }, +});