commit 78b2c94f86e6c7c3f2a6ebbbd67881b4da8c783c Author: sipp11 Date: Mon Dec 28 00:00:03 2015 +0700 Init diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..d55ba80 --- /dev/null +++ b/.babelrc @@ -0,0 +1,6 @@ +{ + "presets": [ + "es2015", + "stage-0" + ] +} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c928726 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +node_modules/ +npm-debug.log +.DS_Store +bower_components diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..d0acfde --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,15 @@ + +v1.1 / 2015-12-14 +================= + + * Support ES2015 & Stage 0 + +v1.0 / 2015-11-17 +================= + + * Add support info + * Fixed path to register.js + * Clear dependencies + * Add docs about install, test and license + * Support Babel.js in Jasmine specs + * Initial commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..8b34201 --- /dev/null +++ b/README.md @@ -0,0 +1,39 @@ +# test-jasmine-babel + +> Test project which use Babel.js as ES6 compiler to write unit tests + +## Setup + +``` +npm install +``` + +## Test + +Before you should have global installation of `jasmine` package. + +``` +npm test +``` + +## Support + +Current support version: + + - `Babel ^6.3.17` + +Previously support: + + - `Babel ^5.8.29` + +## Build changelog + +Use https://github.com/tj/git-extras/blob/master/Commands.md#git-changelog: + +``` +git changelog -a -n +``` + +## License + +[The MIT License](http://piecioshka.mit-license.org) diff --git a/app/scripts/core/Counter.es6.js b/app/scripts/core/Counter.es6.js new file mode 100644 index 0000000..99d9864 --- /dev/null +++ b/app/scripts/core/Counter.es6.js @@ -0,0 +1,13 @@ +export const INCREMENT_COUNTER = 'INCREMENT_COUNTER' +export const DECREMENT_COUNTER = 'DECREMENT_COUNTER' + +export default function counter(state = 0, action) { + switch (action.type) { + case INCREMENT_COUNTER: + return state + 1 + case DECREMENT_COUNTER: + return state - 1 + default: + return state + } +} diff --git a/app/scripts/core/Foo.es6.js b/app/scripts/core/Foo.es6.js new file mode 100644 index 0000000..0e80616 --- /dev/null +++ b/app/scripts/core/Foo.es6.js @@ -0,0 +1,7 @@ +class Foo { + static bar() { + return 'bar'; + } +} + +export default Foo; diff --git a/package.json b/package.json new file mode 100644 index 0000000..c9f606c --- /dev/null +++ b/package.json @@ -0,0 +1,14 @@ +{ + "private": true, + "name": "test-jasmine-babel", + "scripts": { + "clear": "rm -rf node_modules/", + "test": "jasmine JASMINE_CONFIG_PATH=test/jasmine.json" + }, + "devDependencies": { + "babel-core": "^6.3.26", + "babel-preset-es2015": "^6.3.13", + "babel-preset-stage-0": "^6.3.13", + "jasmine": "^2.4.1" + } +} diff --git a/test/jasmine.json b/test/jasmine.json new file mode 100644 index 0000000..0a6474a --- /dev/null +++ b/test/jasmine.json @@ -0,0 +1,9 @@ +{ + "spec_dir": "test", + "spec_files": [ + "spec/test.*.es6.js" + ], + "helpers": [ + "../node_modules/babel-core/register.js" + ] +} diff --git a/test/spec/test.Counter.es6.js b/test/spec/test.Counter.es6.js new file mode 100644 index 0000000..b1f2bfd --- /dev/null +++ b/test/spec/test.Counter.es6.js @@ -0,0 +1,29 @@ +import counter from '../../app/scripts/core/Counter.es6'; + + +describe('counter', () => { + it('should handle initial state', () => { + expect ( + counter(0, { type: 'INCREMENT_COUNTER' }) + ).toEqual(1); + }); + + it('should handle INCREMENT_COUNTER', () => { + expect ( + counter(1, { type: 'INCREMENT_COUNTER' }) + ).toEqual(2); + }); + + it('should handle DECREMENT_COUNTER', () => { + expect ( + counter(2, { type: 'DECREMENT_COUNTER' }) + ).toEqual(1); + }); + + it('should handle unknown action type', () => { + expect ( + counter(1, { type: 'SOMETHING_ELSE' }) + ).toEqual(1); + }); +}); + diff --git a/test/spec/test.Foo.es6.js b/test/spec/test.Foo.es6.js new file mode 100644 index 0000000..5cd1c35 --- /dev/null +++ b/test/spec/test.Foo.es6.js @@ -0,0 +1,7 @@ +import Foo from '../../app/scripts/core/Foo.es6'; + +describe('Foo', () => { + it('bar', () => { + expect(Foo.bar()).toEqual('bar'); + }); +});