-
Notifications
You must be signed in to change notification settings - Fork 482
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds babel for supporting older node versions (#95)
* build for lambda * adds legacy object to index * removes legacy object, adds dev for running examples using lib * removes dev index * adds npmignore file * adds publish.sh and tests * adds missing line breaks * adds missing line break * removes unnecessary dev dependencies
- Loading branch information
Showing
11 changed files
with
160 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"presets": [ | ||
"es2015", | ||
"stage-0" | ||
], | ||
"comments": true, | ||
"sourceMaps": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
dist | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
language: node_js | ||
node_js: | ||
- '6.9.0' | ||
script: | ||
- npm test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ | |
], | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "mocha ./tests/lib.js" | ||
}, | ||
"repository": "https://github.com/wit-ai/node-wit", | ||
"author": "The Wit Team <[email protected]>", | ||
|
@@ -23,5 +23,13 @@ | |
}, | ||
"engines": { | ||
"node": ">=4.0.0" | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "^6.16.0", | ||
"babel-preset-es2015": "^6.16.0", | ||
"babel-preset-stage-0": "^6.16.0", | ||
"chai": "^3.5.0", | ||
"mocha": "^3.1.2", | ||
"sinon": "^1.17.6" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/bin/bash | ||
|
||
set -ex | ||
|
||
mkdir -p dist | ||
cp package.json dist | ||
babel lib --out-dir dist/lib | ||
babel index.js --out-file dist/index.js | ||
mocha ./tests/dist.js | ||
( | ||
cd dist | ||
npm publish | ||
) | ||
rm -rf dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict'; | ||
|
||
describe('dist', () => { | ||
require('./shared').runTests(require('../dist/index')); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict'; | ||
|
||
describe('lib', () => { | ||
require('./shared').runTests(require('../index')); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
'use strict'; | ||
|
||
const expect = require('chai').expect; | ||
const sinon = require('sinon'); | ||
|
||
module.exports.runTests = (wit) => { | ||
const log = wit.log; | ||
const Wit = wit.Wit; | ||
const interactive = wit.interactive; | ||
|
||
describe('logger', () => { | ||
let loggerStub; | ||
|
||
it('tests log flags', () => { | ||
expect(log.DEBUG).to.be.equal('debug'); | ||
expect(log.INFO).to.be.equal('info'); | ||
expect(log.WARN).to.be.equal('warn'); | ||
expect(log.ERROR).to.be.equal('error'); | ||
}); | ||
|
||
it('tests logger (DEBUG)', () => { | ||
const logger = new log.Logger(log.DEBUG); | ||
loggerStub = sinon.stub(logger, 'info').returns(Promise.resolve()); | ||
logger.info('one', 'two', 'three'); | ||
expect(loggerStub.calledOnce).to.be.true; | ||
expect(loggerStub.thisValues[0].level).to.be.equal('debug'); | ||
expect(loggerStub.calledWith('one', 'two', 'three')).to.be.true; | ||
}); | ||
|
||
it('tests logger (INFO)', () => { | ||
const logger = new log.Logger(log.INFO); | ||
loggerStub = sinon.stub(logger, 'info').returns(Promise.resolve()); | ||
logger.info('one', 'two', 'three'); | ||
expect(loggerStub.calledOnce).to.be.true; | ||
expect(loggerStub.thisValues[0].level).to.be.equal('info'); | ||
expect(loggerStub.calledWith('one', 'two', 'three')).to.be.true; | ||
}); | ||
|
||
it('tests logger (WARN)', () => { | ||
const logger = new log.Logger(log.WARN); | ||
loggerStub = sinon.stub(logger, 'info').returns(Promise.resolve()); | ||
logger.info('one', 'two', 'three'); | ||
expect(loggerStub.calledOnce).to.be.true; | ||
expect(loggerStub.thisValues[0].level).to.be.equal('warn'); | ||
expect(loggerStub.calledWith('one', 'two', 'three')).to.be.true; | ||
}); | ||
|
||
it('tests logger (ERROR)', () => { | ||
const logger = new log.Logger(log.ERROR); | ||
loggerStub = sinon.stub(logger, 'info').returns(Promise.resolve()); | ||
logger.info('one', 'two', 'three'); | ||
expect(loggerStub.calledOnce).to.be.true; | ||
expect(loggerStub.thisValues[0].level).to.be.equal('error'); | ||
expect(loggerStub.calledWith('one', 'two', 'three')).to.be.true; | ||
}); | ||
}); | ||
|
||
describe('Wit', () => { | ||
let client = new Wit({ | ||
accessToken: process.env.WIT_TOKEN | ||
}); | ||
|
||
it('tests that Wit has correct functions', () => { | ||
const witFunctions = Object.keys(client); | ||
expect(witFunctions).to.eql(['config', '_sessions', 'message', 'converse', 'runActions']); | ||
}); | ||
|
||
it('tests message', () => { | ||
return client.message('Hello', {}) | ||
.then((data) => { | ||
expect(data.entities.intent[0].value).to.be.equal('greet'); | ||
expect(data._text).to.be.equal('Hello'); | ||
}); | ||
}); | ||
|
||
it('tests converse', () => { | ||
return client.converse(`session-${Date.now()}`, 'Hello', {}) | ||
.then((data) => { | ||
expect(data.entities.intent[0].value).to.be.equal('greet'); | ||
expect(data.msg).to.be.equal('Hello to you too!'); | ||
}); | ||
}); | ||
|
||
it('tests runActions', () => { | ||
const actions = { | ||
send: (request, response) => new Promise((resolve) => { | ||
expect(request.entities.intent[0].value).to.be.equal('greet'); | ||
expect(request.text).to.be.equal('Hello'); | ||
expect(response.text).to.be.equal('Hello to you too!'); | ||
resolve(); | ||
}) | ||
}; | ||
client = new Wit({ | ||
accessToken: process.env.WIT_TOKEN, | ||
actions | ||
}); | ||
return client.runActions(`session-${Date.now()}`, 'Hello', {}, 2); | ||
}); | ||
}); | ||
|
||
describe('interactive', () => { | ||
it('checks that interactive exists', () => { | ||
expect(interactive).to.exists; | ||
}); | ||
}); | ||
}; |
Binary file not shown.