-
Notifications
You must be signed in to change notification settings - Fork 0
Pure JavaScript
You can use ready pure-javascript scaffolding and not worry about task configurations. It's already done!
Example task structure:
pure-javascript
|-- app
| |-- app.js
|-- test
| |-- unit
| | |-- app.spec.js
| |-- karma.conf.js
|-- .gitattributes
|-- .gitignore
|-- .jshintignore
|-- .jshintrc
|-- Gruntfile.js
|-- package.json
|-- README.md
The main directory of the whole project. Here put the files constituting the task.
Put your tests inside unit folder. Don't forget about .spec.js suffix in file name. Recommended configuration: karma.conf.js
###.gitattributes With text set to "auto". The path is marked for automatic end-of-line normalization.
A .gitignore file specifies intentionally untracked files that Git should ignore.
###.jshintignore Thanks to .jshintignore JSHint can be configured to ignore files based on their location in the filesystem.
###.jshintrc Is used to specifying linting options.
Recommended configuration: Gruntfile.js
To run verify jshint:
grunt jshint:default
To start developing unit tests
grunt test:dev
Recommended configuration: package.json
To run verify jshint, tests and coverage:
npm test
Here, give instructions necessary to do the task.
module.exports = function (config)
{
'use strict';
config.set({
autoWatch: true,
basePath: '../',
frameworks: ['jasmine'],
files: ['app/**/*.js','test/unit/**/*.spec.js'],
exclude: [],
reporters: ['spec', 'coverage', 'junit'],
preprocessors: {
'app/**/*.js': 'coverage'
},
coverageReporter: {
dir: 'target/',
type: 'cobertura',
file: 'coverage.xml'
},
junitReporter: {
outputFile: 'target/test-results.xml'
},
port: 8080,
browsers: ['PhantomJS'],
plugins: ['karma-phantomjs-launcher',
'karma-jasmine',
'karma-spec-reporter',
'karma-junit-reporter',
'karma-coverage'],
singleRun: true,
colors: true,
logLevel: config.LOG_INFO,
usePolling: true
});
};
(function ()
{
'use strict';
module.exports = function (grunt)
{
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-karma');
grunt.initConfig({
karma: {
options: {
configFile: 'test/karma.conf.js'
},
unit: {
singleRun: true
},
dev: {
singleRun: false
}
},
jshint: {
default: {
options: {
jshintrc: true
},
files: {
src: ['app/**/*.js', 'test/**/*.js']
}
},
verify: {
options: {
jshintrc: true,
reporter: 'checkstyle',
reporterOutput: 'target/jshint.xml'
},
files: {src: ['app/**/*.js', 'test/**/*.js']}
}
}
});
grunt.registerTask('verify', ['jshint:verify', 'karma:unit']);
grunt.registerTask('test:dev', ['karma:dev']);
};
})();
{
"name": "pure-javascript-scaffolding",
"private": true,
"version": "0.0.0",
"dependencies": {},
"devDependencies": {
"grunt": "0.4.5",
"grunt-cli": "0.1.13",
"grunt-contrib-jshint": "0.11.2",
"grunt-karma": "0.10.1",
"jasmine": "2.3.2",
"jasmine-reporters": "2.0.7",
"karma": "0.12.16",
"karma-coverage": "0.3.1",
"karma-jasmine": "0.1.5",
"karma-junit-reporter": "0.2.2",
"karma-phantomjs-launcher": "0.1.4",
"karma-spec-reporter": "0.0.13"
},
"scripts": {
"test": "grunt verify --force"
}
}