-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 7a441ee
Showing
15 changed files
with
1,745 additions
and
0 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,3 @@ | ||
/node_modules | ||
/coverage | ||
/test/results |
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,9 @@ | ||
language: node_js | ||
node_js: | ||
- '6' | ||
install: | ||
- npm install -g codecov | ||
- npm install | ||
script: | ||
- npm test | ||
- codecov |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,75 @@ | ||
module.exports = function(grunt) { | ||
|
||
// Project configuration. | ||
grunt.initConfig({ | ||
pkg: grunt.file.readJSON('package.json'), | ||
browserify: { | ||
options: { | ||
browserifyOptions : { | ||
debug: true | ||
} | ||
}, | ||
dist: { | ||
src: "src/main.js", | ||
dest: "dist/<%= pkg.name %>.js" | ||
}, | ||
test: { | ||
files: { | ||
"test/test.js": ["test/src/*.js"] | ||
}, | ||
options: { | ||
browserifyOptions: { | ||
transform: [["browserify-istanbul", {ignore:["**/lib/**"]}]], | ||
debug: true | ||
} | ||
} | ||
} | ||
}, | ||
uglify: { | ||
options: { | ||
banner: '/*! <%= pkg.name %> <%= pkg.version %> <%= grunt.template.today("yyyy-mm-dd") %>\n' | ||
}, | ||
build: { | ||
src: 'dist/<%= pkg.name %>.js', | ||
dest: 'dist/<%= pkg.name %>.min.js' | ||
} | ||
}, | ||
watch: { | ||
source: { | ||
files: ["src/**/*", "test/**/*"], | ||
tasks: ["test"] | ||
} | ||
}, | ||
mocha_phantomjs: { | ||
options: { | ||
config: { | ||
"hooks": __dirname + '/test/src/phantom_hooks.js' | ||
} | ||
}, | ||
all: 'test/test.html' | ||
}, | ||
makeReport: { | ||
src: 'coverage/coverage.json', | ||
options: { | ||
type: 'lcov', | ||
dir: 'coverage', | ||
print: 'detail' | ||
} | ||
} | ||
}); | ||
|
||
// Load plugins | ||
grunt.loadNpmTasks('grunt-browserify'); | ||
grunt.loadNpmTasks('grunt-jsdoc'); | ||
grunt.loadNpmTasks('grunt-contrib-uglify'); | ||
grunt.loadNpmTasks('grunt-contrib-copy'); | ||
grunt.loadNpmTasks('grunt-contrib-watch'); | ||
grunt.loadNpmTasks('grunt-mocha-phantomjs'); | ||
grunt.loadNpmTasks('grunt-istanbul'); | ||
// Default task(s). | ||
grunt.registerTask('build', ['browserify', 'uglify']); | ||
grunt.registerTask("build-test", ['browserify:test']); | ||
grunt.registerTask("test", ["build-test", "mocha_phantomjs", "makeReport"]) | ||
grunt.registerTask('default', ['watch:source']); | ||
|
||
}; |
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,40 @@ | ||
{ | ||
"name": "MyLib", | ||
"version": "1.0.0", | ||
"description": "A template to write robust client-side javascript libraries", | ||
"main": "src/main.js", | ||
"scripts": { | ||
"test": "mocha-phantomjs ./test/test.html --hooks ./test/src/phantom_hooks.js -R xunit -f test/results/result.xml", | ||
"coverage-report": "istanbul report --root coverage lcov" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/rte-antares-rpackage/js-client-tmpl.git" | ||
}, | ||
"keywords": [ | ||
"javascript", | ||
"client", | ||
"side", | ||
"template", | ||
"unit testing", | ||
"code coverage" | ||
], | ||
"author": "Francois Guillem", | ||
"license": "MIT", | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"browserify-istanbul": "^2.0.0", | ||
"grunt": "^1.0.1", | ||
"grunt-browserify": "^5.0.0", | ||
"grunt-contrib-uglify": "^2.0.0", | ||
"grunt-contrib-watch": "^1.0.0", | ||
"grunt-istanbul": "^0.8.0", | ||
"grunt-mocha-phantomjs": "^4.0.0", | ||
"istanbul": "^0.4.5", | ||
"mocha-phantomjs": "^4.1.0" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/rte-antares-rpackage/js-client-tmpl/issues" | ||
}, | ||
"homepage": "https://github.com/rte-antares-rpackage/js-client-tmpl#readme" | ||
} |
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,9 @@ | ||
(function() { | ||
'use strict'; | ||
|
||
module.exports = bar; | ||
|
||
function bar() { | ||
return "world!"; | ||
} | ||
}()); |
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,10 @@ | ||
(function() { | ||
'use strict'; | ||
|
||
module.exports = foo; | ||
|
||
function foo() { | ||
return "Hello"; | ||
} | ||
|
||
}()); |
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,29 @@ | ||
(function() { | ||
'use strict'; | ||
|
||
module.exports.getMessage = getMessage; | ||
module.exports.sayHello = sayHello; | ||
module.exports.sayHelloAsync = sayHelloAsync; | ||
|
||
// If we are in a browser, define a global variable. | ||
if (window) window.MyLib = module.exports; | ||
|
||
var foo = require("./foo.js"); | ||
var bar = require("./bar.js"); | ||
|
||
function getMessage() { | ||
return foo() + " " + bar(); | ||
} | ||
|
||
function sayHello(el) { | ||
$(el).html(getMessage()); | ||
} | ||
|
||
function sayHelloAsync(el, delay, callback) { | ||
setTimeout(function() { | ||
sayHello(el); | ||
callback(); | ||
}, delay); | ||
} | ||
|
||
}()); |
Large diffs are not rendered by default.
Oops, something went wrong.
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,17 @@ | ||
// You should not move or edit this file | ||
|
||
module.exports = { | ||
afterEnd: function(runner) { | ||
var fs = require('fs'); | ||
var coverage = runner.page.evaluate(function() { | ||
return window.__coverage__; | ||
}); | ||
|
||
if (coverage) { | ||
console.log('Writing coverage to coverage/coverage.json'); | ||
fs.write('coverage/coverage.json', JSON.stringify(coverage), 'w'); | ||
} else { | ||
console.log('No coverage data generated'); | ||
} | ||
} | ||
}; |
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,31 @@ | ||
(function() { | ||
'use strict'; | ||
|
||
var assert = require("assert"); | ||
require("../../src/main.js"); | ||
|
||
describe("MyLib", function() { | ||
beforeEach(function() { | ||
$("#message").html(""); | ||
}); | ||
|
||
it("returns an important message", function() { | ||
assert.equal(MyLib.getMessage(), "Hello world!"); | ||
}); | ||
|
||
it("displays the message in the desired element", function() { | ||
MyLib.sayHello("#message"); | ||
assert.equal($("#message").html(), MyLib.getMessage()); | ||
}) | ||
|
||
it("asynchronously displays the message in the desired element", function(done) { | ||
MyLib.sayHelloAsync("#message", 10, function() { | ||
assert.equal($("#message").html(), MyLib.getMessage()); | ||
done(); | ||
}); | ||
}) | ||
|
||
|
||
}); | ||
|
||
}()); |
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,19 @@ | ||
(function() { | ||
'use strict'; | ||
|
||
var assert = require("assert"); | ||
var foo = require("../../src/foo.js"); | ||
var bar = require("../../src/bar.js"); | ||
|
||
describe("foo()", function() { | ||
it("returns 'Hello'", function() { | ||
assert.equal(foo(), "Hello"); | ||
}); | ||
}); | ||
|
||
describe("bar()", function() { | ||
it("returns 'world!'", function() { | ||
assert.equal(bar(), "world!"); | ||
}) | ||
}) | ||
}()); |
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,26 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Test MyLib</title> | ||
<link rel="stylesheet" href="../node_modules/mocha/mocha.css"> | ||
<script src="../node_modules/mocha/mocha.js" charset="utf-8"></script> | ||
<!-- Other external dependencies --> | ||
<script src="lib/jquery-3.1.1.min.js" charset="utf-8"></script> | ||
</head> | ||
<body> | ||
<!-- Custom html elements required by the tests --> | ||
<div id="message"></div> | ||
|
||
<!-- Run tests. You should not modify the following lines. --> | ||
<div id="mocha"></div> | ||
<script type="text/javascript"> | ||
mocha.ui('bdd'); | ||
</script> | ||
<script src="test.js" charset="utf-8"></script> | ||
<script type="text/javascript"> | ||
mocha.run(); | ||
</script> | ||
|
||
</body> | ||
</html> |
Oops, something went wrong.