Skip to content

Commit 3ba6ac2

Browse files
committed
Add basic flow for ES6 tests with Karma and Jasmine
1 parent ab1dabe commit 3ba6ac2

File tree

6 files changed

+83
-2
lines changed

6 files changed

+83
-2
lines changed

.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["es2015"]
3+
}

.karma.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
module.exports = function(config) {
2+
config.set({
3+
basePath: '',
4+
browsers: [
5+
"Chrome"
6+
],
7+
frameworks: [
8+
'browserify',
9+
'jasmine'
10+
],
11+
files: [
12+
'src/**/*.js',
13+
'test/**/*.js'
14+
],
15+
exclude: [
16+
17+
],
18+
preprocessors: {
19+
'src/**/*.js': [
20+
'browserify'
21+
],
22+
'test/**/*.js': [
23+
'browserify'
24+
]
25+
},
26+
browserify: {
27+
debug: false,
28+
transform: [
29+
'babelify'
30+
]
31+
}
32+
});
33+
};

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
karma:
2+
./node_modules/.bin/karma start .karma.js --single-run --reporters progress --log-level disable
3+
4+
karma-watch:
5+
./node_modules/.bin/karma start .karma.js --reporters progress --log-level disable

package.json

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "With Timesheet.js you can easily create simple time and data sheets or timelines using HTML5, JavaScript and CSS3. Yep, it's a Vanilla JS library!",
55
"main": "index.js",
66
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1"
7+
"test": "make karma"
88
},
99
"repository": {
1010
"type": "git",
@@ -18,5 +18,25 @@
1818
"bugs": {
1919
"url": "https://github.com/sbstjn/timesheet.js/issues"
2020
},
21-
"homepage": "https://github.com/sbstjn/timesheet.js#readme"
21+
"homepage": "https://github.com/sbstjn/timesheet.js#readme",
22+
"devDependencies": {
23+
"babel": "^6.5.2",
24+
"babel-polyfill": "^6.16.0",
25+
"babel-preset-es2015": "^6.16.0",
26+
"babel-preset-react": "^6.16.0",
27+
"babelify": "^7.3.0",
28+
"browserify": "^13.1.0",
29+
"jasmine-core": "^2.5.2",
30+
"karma": "^1.3.0",
31+
"karma-browserify": "^5.1.0",
32+
"karma-chrome-launcher": "^2.0.0",
33+
"karma-jasmine": "^1.0.2",
34+
"karma-phantomjs-launcher": "^1.0.2",
35+
"watchify": "^3.7.0"
36+
},
37+
"browserify": {
38+
"transform": [
39+
"babelify"
40+
]
41+
}
2242
}

src/main.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class Timesheet {
2+
constructor(name) {
3+
this.name = name
4+
}
5+
}
6+
7+
export default Timesheet;

test/main.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import Timesheet from '../src/main.js';
2+
3+
describe('Timesheet', function () {
4+
let foo;
5+
6+
beforeEach(() => {
7+
foo = new Timesheet('custom');
8+
});
9+
10+
it('name should be set to "custom"', () => {
11+
expect(foo.name).toEqual('custom');
12+
});
13+
});

0 commit comments

Comments
 (0)