Last active
November 24, 2016 13:24
-
-
Save joebartels/f984bd6c60b2bcc2229b to your computer and use it in GitHub Desktop.
Mocha + testem + es6 modules. http://joebartels.me/testing-with-mocha-testem-and-es6-modules/
This file contains hidden or 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
{ | |
"presets": ["es2015"], | |
"plugins": [ | |
"transform-es2015-modules-amd" | |
] | |
} |
This file contains hidden or 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
{ | |
"name": "testem-fun", | |
"version": "0.0.0", | |
"authors": [ | |
"joseph bartels" | |
], | |
"license": "MIT", | |
"ignore": [ | |
"**/.*", | |
"node_modules", | |
"bower_components", | |
"test", | |
"tests" | |
], | |
"dependencies": { | |
"requirejs": "~2.1.20" | |
}, | |
"devDependencies": { | |
"chai": "~3.2.0" | |
} | |
} |
This file contains hidden or 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
import { initials } from '../utils/string-tools.js'; | |
export default function Person(name) { | |
this.name = name; | |
this.initials = initials(name); | |
} |
This file contains hidden or 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
import Person from '../person.js'; | |
describe('Person properties', function() { | |
let fullName = 'Phineas Fletcher'; | |
let person; | |
beforeEach(function() { | |
person = new Person(fullName); | |
}); | |
it('assigns name properly', function() { | |
chai.assert.equal(person.name, fullName, `person's name is correct.`); | |
}); | |
it('assigns initials properly', function() { | |
let expectedInitials = 'PF'; | |
chai.assert.equal(person.initials, expectedInitials, `person's initials are correct.`); | |
}); | |
}); |
This file contains hidden or 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
export function initials(fullName) { | |
let initials = (fullName || '') | |
.split(' ') | |
.map(name => name[0]) | |
.join(''); | |
return initials || 'N/A'; | |
return f && l ? `${f}${l}` : f || l || 'N/A'; | |
}; |
This file contains hidden or 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
<!doctye html> | |
<html> | |
<head> | |
<title>Test'em</title> | |
<link rel="stylesheet" href="/testem/mocha.css"> | |
<script src="/testem/mocha.js"></script> | |
<script src="/testem.js"></script> | |
<script src="/bower_components/chai/chai.js"></script> | |
<script src="/bower_components/requirejs/require.js"></script> | |
<script>mocha.setup('bdd')</script> | |
{{#styles}}<link rel="stylesheet" href="{{.}}">{{/styles}} | |
</head> | |
<body> | |
<div id="mocha"></div> | |
<script> | |
// require.config({ | |
// baseUrl: 'test' | |
// }); | |
var files = []; | |
{{#serve_files}} | |
files.push("../{{{src}}}"); | |
{{/serve_files}} | |
require(files, function() { | |
mocha.run(); | |
}); | |
</script> | |
</body> | |
</html> |
This file contains hidden or 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
{ | |
"framework": "mocha", | |
"src_files": [ | |
"tmp/**/*-test.js" | |
], | |
"watch_files": [ | |
"lib/**/*.js" | |
], | |
"test_page": "test/index.mustache", | |
"on_start": "babel lib --out-dir tmp", | |
"on_exit": "rm -rf tmp/*.js" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
is live reload running properly in this setup? seems that files are watched properly but babel runs only once on testem start. There is "before_tests" property on testem, it seems to work.