Skip to content

Commit

Permalink
Add eslint. and pass test files, karma confand grunt through it
Browse files Browse the repository at this point in the history
  • Loading branch information
umakantp committed Aug 31, 2017
1 parent bf84c19 commit b91d4dc
Show file tree
Hide file tree
Showing 13 changed files with 444 additions and 431 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
indent_size = 4
indent_size = 2
17 changes: 17 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"root": true,
"extends": "standard",
"env": {
"es6": false,
"node": true,
"amd": true,
"browser": true
},
"globals": {
"expect": true,
"getData": true
},
"rules": {
"new-cap": ["error", { "newIsCapExceptions": ["jSmart"] }]
}
}
75 changes: 38 additions & 37 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
module.exports = function(grunt) {
"use strict";
module.exports = function (grunt) {
'use strict'

grunt.option("filename", "jsmart.js");
if (!grunt.option('filename')) {
grunt.option('filename', 'jsmart.js')
}

grunt.initConfig({
pkg: grunt.file.readJSON("package.json"),
pkg: grunt.file.readJSON('package.json'),
build: {
all: {
dest: "dist/<%= grunt.option('filename') %>",
minimum: [
"core",
"selector"
]
dest: "dist/<%= grunt.option('filename') %>"
}
},
eslint: {
src: ['src/**/*.js', 'Gruntfile.js', 'karma.conf.js', 'test/**/*.js', 'build/*.js']
},
karma: {
unit: {
configFile: "karma.conf.js"
}
unit: {
configFile: 'karma.conf.js'
}
},
uglify: {
all : {
all: {
options: {
preserveComments: false,
sourceMap: true,
sourceMapName: "dist/<%= grunt.option('filename').replace('.js', '.min.map') %>",
report: "min",
banner: "/*!\n" +
" * jSmart JavaScript template engine (v<%= pkg.version %>)\n" +
" * https://github.com/umakantp/jsmart\n" +
" * https://opensource.org/licenses/MIT\n" +
" *\n" +
" * Copyright 2011-2017, Umakant Patil <me @ umakantpatil dot com>\n" +
" * Max Miroshnikov <miroshnikov at gmail dot com>\n" +
" */\n"
sourceMap: false,
report: 'min',
banner: '/*!\n' +
' * jSmart JavaScript template engine (v<%= pkg.version %>)\n' +
' * https://github.com/umakantp/jsmart\n' +
' * https://opensource.org/licenses/MIT\n' +
' *\n' +
' * Copyright 2011-2017, Umakant Patil <me at umakantpatil dot com>\n' +
' * Max Miroshnikov <miroshnikov at gmail dot com>\n' +
' */\n'
},
files: {
"dist/<%= grunt.option('filename').replace('.js', '.min.js') %>": ["dist/<%= grunt.option('filename') %>"]
Expand All @@ -45,31 +45,32 @@ module.exports = function(grunt) {
files: [
{
src: "dist/<%= grunt.option('filename').replace('.js', '.min.js') %>",
dest: "examples/simple/<%= pkg.name %>.min.js"
dest: 'examples/simple/<%= pkg.name %>.min.js'
},
{
src: "dist/<%= grunt.option('filename').replace('.js', '.min.js') %>",
dest: "examples/requirejs/js/<%= pkg.name %>.min.js"
dest: 'examples/requirejs/js/<%= pkg.name %>.min.js'
},
{
src: "dist/<%= grunt.option('filename').replace('.js', '.min.js') %>",
dest: "examples/node/<%= pkg.name %>.min.js"
dest: 'examples/node/<%= pkg.name %>.min.js'
}
]
}
}
});
})

// Load grunt tasks from NPM packages
require("load-grunt-tasks")(grunt);

// Integrate jQuery specific tasks
grunt.loadTasks("build/tasks");
require('load-grunt-tasks')(grunt)

grunt.loadNpmTasks('grunt-karma');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-copy');
// Integrate jSmart specific tasks
grunt.loadTasks('build/tasks')

grunt.registerTask('default', ['karma', 'build', 'uglify', 'copy']);
// Register tasks from karma, uglify and copy.
grunt.loadNpmTasks('grunt-karma')
grunt.loadNpmTasks('grunt-contrib-uglify')
grunt.loadNpmTasks('grunt-contrib-copy')

};
// Order goes as test, compile, compress and distribute.
grunt.registerTask('default', ['eslint', 'karma', 'build', 'uglify', 'copy'])
}
5 changes: 3 additions & 2 deletions build/tasks/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module.exports = function(grunt) {

config = {
baseUrl: "src",

name: "jsmart",

// Allow strict mode
Expand Down Expand Up @@ -105,8 +105,9 @@ module.exports = function(grunt) {
// yyyy-mm-ddThh:mmZ
.replace( /@DATE/g, ( new Date() ).toISOString().replace( /:\d+\.\d+Z$/, "Z" ) );

name = name ? ( "dist/" + name ) : this.data.dest;
// Write concatenated source to file
grunt.file.write('dist/'+name, compiled);
grunt.file.write(name, compiled);
};

// Trace dependencies and concatenate files
Expand Down
16 changes: 4 additions & 12 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
// Karma configuration
// Generated on Sat Aug 12 2017 12:43:17 GMT+0530 (India Standard Time)

module.exports = function(config) {
module.exports = function (config) {
'use strict'

config.set({

// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',


// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine', 'requirejs'],


// list of files / patterns to load in the browser
files: [
'test/test-main.js',
Expand All @@ -23,47 +23,39 @@ module.exports = function(config) {
{pattern: 'test/*spec.js', included: false}
],


// list of files to exclude
exclude: [
'src/wrapper.js'
],


// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
},


// test results reporter to use
// possible values: 'spec', 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
//reporters: ['progress'],
// reporters: ['progress'],
reporters: ['spec'],

// web server port
port: 9876,


// enable / disable colors in the output (reporters and logs)
colors: true,


// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,


// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,


// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['PhantomJS'],


// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: true,
Expand Down
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,15 @@
"license": "MIT",
"dependencies": {},
"devDependencies": {
"eslint-config-standard": "^10.2.1",
"eslint-plugin-import": "^2.7.0",
"eslint-plugin-node": "^5.1.1",
"eslint-plugin-promise": "^3.5.0",
"eslint-plugin-standard": "^3.0.1",
"grunt": "^1.0.1",
"grunt-contrib-copy": "^1.0.0",
"grunt-contrib-uglify": "^3.0.1",
"grunt-eslint": "^20.0.0",
"grunt-karma": "^2.0.0",
"jasmine-core": "^2.7.0",
"karma": "^0.13.13",
Expand Down
7 changes: 7 additions & 0 deletions test/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"root": true,
"extends": "../.eslintrc.json",
"env": {
"mocha": true
}
}
125 changes: 62 additions & 63 deletions test/basic-spec.js
Original file line number Diff line number Diff line change
@@ -1,63 +1,62 @@
define(['jSmart', 'text!./templates/var.tpl', 'text!./output/var.tpl'], function(jSmart, smartyTpl, outputTpl) {
jSmart.prototype.registerPlugin(
'function',
'sayHello',
function (params, data) {
var s = 'Hello ';
s += params.to;
return s;
}
);

describe("Test Syntax", function() {

it("test plain text", function() {
var t = new jSmart('Hello world');
expect(t.fetch()).toBe('Hello world');
});

it("test variable", function() {
var t = new jSmart('Hello {$name}, how are you?');
expect(t.fetch({name: 'world'})).toBe('Hello world, how are you?');
});

it("test array/object variable", function() {
// Objects.
var t = new jSmart('1. Hello {$user.name.first}, how are you?');
expect(t.fetch({user: {name: { first: 'Uma'}}})).toBe('1. Hello Uma, how are you?');

// Arrays.
var t = new jSmart("2. Hello {$user['name']['first']}, how are you?");
expect(t.fetch({user: {name: { first: 'Uma'}}})).toBe('2. Hello Uma, how are you?');

// Objects.
var t = new jSmart("3. Hello {$user->name->first}, how are you?");
expect(t.fetch({user: {name: { first: 'Uma'}}})).toBe('3. Hello Uma, how are you?');
});

it("test comment", function() {
var t = new jSmart('Testing {*comments yo *}, does it work?');
expect(t.fetch()).toBe('Testing , does it work?');
});

it("test assigning variable", function() {
var t = new jSmart("{$foo = 'bar'} print foo {$foo}");
expect(t.fetch()).toBe(' print foo bar');
});

it("test double quotes strings", function() {
var t = new jSmart('{$foo="bar"} {$bar = "value of foo is \'$foo\'"} {$bar}');
expect(t.fetch()).toBe(" value of foo is 'bar'");

// back tick test.
var t = new jSmart('{$foo = "`$person.name.first` has `$person[\'favorite gadget\']`"} {$foo}');
expect(t.fetch({person: {name: {first: 'Umakant'}, 'favorite gadget': 'ipad'}})).toBe(" Umakant has ipad");
});

it("test complex template", function() {
// Insert complex statements in the template and test them.
var t = new jSmart(smartyTpl);
expect(t.fetch(getData())).toBe(outputTpl);
});
});
});
define(['jSmart', 'text!./templates/var.tpl', 'text!./output/var.tpl'], function (jSmart, smartyTpl, outputTpl) {
jSmart.prototype.registerPlugin(
'function',
'sayHello',
function (params, data) {
var s = 'Hello '
s += params.to
return s
}
)

describe('Test Syntax', function () {
it('test plain text', function () {
var t = new jSmart('Hello world')
expect(t.fetch()).toBe('Hello world')
})

it('test variable', function () {
var t = new jSmart('Hello {$name}, how are you?')
expect(t.fetch({name: 'world'})).toBe('Hello world, how are you?')
})

it('test array/object variable', function () {
// Objects.
var t = new jSmart('1. Hello {$user.name.first}, how are you?')
expect(t.fetch({user: {name: {first: 'Uma'}}})).toBe('1. Hello Uma, how are you?')

// Arrays.
t = new jSmart("2. Hello {$user['name']['first']}, how are you?")
expect(t.fetch({user: {name: {first: 'Uma'}}})).toBe('2. Hello Uma, how are you?')

// Objects.
t = new jSmart('3. Hello {$user->name->first}, how are you?')
expect(t.fetch({user: {name: {first: 'Uma'}}})).toBe('3. Hello Uma, how are you?')
})

it('test comment', function () {
var t = new jSmart('Testing {*comments yo *}, does it work?')
expect(t.fetch()).toBe('Testing , does it work?')
})

it('test assigning variable', function () {
var t = new jSmart("{$foo = 'bar'} print foo {$foo}")
expect(t.fetch()).toBe(' print foo bar')
})

it('test double quotes strings', function () {
var t = new jSmart('{$foo="bar"} {$bar = "value of foo is \'$foo\'"} {$bar}')
expect(t.fetch()).toBe(" value of foo is 'bar'")

// back tick test.
t = new jSmart('{$foo = "`$person.name.first` has `$person[\'favorite gadget\']`"} {$foo}')
expect(t.fetch({person: {name: {first: 'Umakant'}, 'favorite gadget': 'ipad'}})).toBe(' Umakant has ipad')
})

it('test complex template', function () {
// Insert complex statements in the template and test them.
var t = new jSmart(smartyTpl)
expect(t.fetch(getData())).toBe(outputTpl)
})
})
})
Loading

0 comments on commit b91d4dc

Please sign in to comment.