Skip to content

Commit

Permalink
Merge 9550425 into a0f26e3
Browse files Browse the repository at this point in the history
  • Loading branch information
outsideris committed Aug 24, 2015
2 parents a0f26e3 + 9550425 commit 4571d40
Show file tree
Hide file tree
Showing 16 changed files with 1,074 additions and 1,039 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Expand Up @@ -6,9 +6,8 @@ before_script:
- npm --version
- npm install -g grunt-cli
script:
- grunt test --verbose
- grunt test-travis --verbose
- if [[ $TRAVIS_PULL_REQUEST == "false" ]]; then grunt saucelabs-test; fi
- grunt karma:travis
- grunt coveralls:travis
before_deploy:
- npm install
Expand Down
110 changes: 67 additions & 43 deletions Gruntfile.js
Expand Up @@ -17,6 +17,51 @@ module.exports = function (grunt) {
return data;
};

var customLaunchers = {
'SL_IE8': {
base: 'SauceLabs',
browserName: 'internet explorer',
version: '8.0',
platform: 'windows XP'
},
'SL_IE9': {
base: 'SauceLabs',
browserName: 'internet explorer',
version: '9.0',
platform: 'windows 7'
},
'SL_IE10': {
base: 'SauceLabs',
browserName: 'internet explorer',
version: '10.0',
platform: 'windows 8'
},
'SL_IE11': {
base: 'SauceLabs',
browserName: 'internet explorer',
version: '11.0',
platform: 'windows 8.1'
},
'SL_CHROME': {
base: 'SauceLabs',
browserName: 'chrome',
version: '43',
platform: 'windows 8'
},
'SL_FIREFOX': {
base: 'SauceLabs',
browserName: 'firefox',
version: '38',
  platform: 'windows 8'
},
'SL_SAFARI': {
base: 'SauceLabs',
browserName: 'safari',
  version: '8.0',
  platform: 'OS X 10.10'
}
};

grunt.initConfig({
// package File
pkg: grunt.file.readJSON('package.json'),
Expand Down Expand Up @@ -132,55 +177,31 @@ module.exports = function (grunt) {
}
},

'saucelabs-qunit': {
'all': {
options: {
urls: ['http://localhost:3000/test/unit.html'],
build: process.env.TRAVIS_BUILD_NUMBER,
tags: [process.env.TRAVIS_BRANCH, process.env.TRAVIS_PULL_REQUEST],
browsers: [{
browserName: 'internet explorer',
version: '8.0',
platform: 'windows XP'
}, {
browserName: 'internet explorer',
version: '9.0',
platform: 'windows 7'
}, {
browserName: 'internet explorer',
version: '10.0',
platform: 'windows 8'
}, {
browserName: 'internet explorer',
version: '11.0',
platform: 'windows 8.1'
}, {
browserName: 'chrome',
version: '43',
platform: 'windows 8'
}, {
     browserName: 'firefox',
     version: '38',
     platform: 'windows 8'
   }, {
     browserName: 'safari',
     version: '8.0',
     platform: 'OS X 10.10'
   }],
testname: 'unit test for summernote',
'public': 'public'
}
}
},

karma: {
options: {
configFile: './test/karma.conf.js'
},
all: {
// Chrome, ChromeCanary, Firefox, Opera, Safari, PhantomJS, IE
browsers: ['PhantomJS'],
reporters: ['progress']
},
travis: {
singleRun: true,
browsers: ['PhantomJS'],
reporters: ['progress', 'coverage']
},
saucelabs: {
reporters: ['saucelabs'],
sauceLabs: {
testName: 'unit tests for summernote',
build: process.env.TRAVIS_BUILD_NUMBER,
tags: [process.env.TRAVIS_BRANCH, process.env.TRAVIS_PULL_REQUEST]
},
captureTimeout: 120000,
customLaunchers: customLaunchers,
browsers: Object.keys(customLaunchers),
singleRun: true
}
},

Expand All @@ -204,10 +225,13 @@ module.exports = function (grunt) {
grunt.registerTask('server', ['connect', 'watch']);

// test: unit test on test folder
grunt.registerTask('test', ['jshint', 'qunit']);
grunt.registerTask('test', ['jshint', 'karma:all']);

// test: unit test on travis
grunt.registerTask('test-travis', ['jshint', 'karma:travis']);

// test: saucelabs test
grunt.registerTask('saucelabs-test', ['connect', 'saucelabs-qunit']);
grunt.registerTask('saucelabs-test', ['karma:saucelabs']);

// dist: make dist files
grunt.registerTask('dist', ['build', 'test', 'uglify', 'recess', 'compress']);
Expand Down
16 changes: 15 additions & 1 deletion README.md
Expand Up @@ -155,10 +155,24 @@ grunt dist
At this point, you should now have a `build/` directory populated with everything you need to use summernote.

#### test summernote
run tests with PhantomJS
run tests with Karma and PhantomJS
```bash
grunt test
```
If you want run tests on other browser,
change the values for `broswers` properties in `Gruntfile.js`.

```
karma: {
all: {
browsers: ['PhantomJS'],
reporters: ['progress']
}
}
```
You can use `Chrome`, `ChromeCanary`, `Firefox`, `Opera`, `Safari`, `PhantomJS` and `IE` beside `PhantomJS`.
Once you run `grunt test`, it will watch all javascript file. Therefore karma run tests every time you chage code.

#### start local server for developing summernote.
run local server with connect and watch.
Expand Down
10 changes: 8 additions & 2 deletions package.json
Expand Up @@ -18,11 +18,11 @@
},
"main": "dist/summernote.js",
"devDependencies": {
"chai": "^3.2.0",
"grunt": "*",
"grunt-contrib-compress": "*",
"grunt-contrib-connect": "*",
"grunt-contrib-jshint": "0.7.2",
"grunt-contrib-qunit": "0.5.2",
"grunt-contrib-uglify": "~0.2.2",
"grunt-contrib-watch": "*",
"grunt-coveralls": "^1.0.0",
Expand All @@ -31,10 +31,16 @@
"grunt-recess": "*",
"grunt-saucelabs": "*",
"karma": "^0.13.3",
"karma-chrome-launcher": "^0.2.0",
"karma-coverage": "^0.4.2",
"karma-firefox-launcher": "^0.1.6",
"karma-ie-launcher": "^0.2.0",
"karma-mocha": "^0.2.0",
"karma-opera-launcher": "^0.2.0",
"karma-phantomjs-launcher": "^0.2.0",
"karma-qunit": "^0.1.5",
"karma-requirejs": "^0.2.2",
"karma-safari-launcher": "^0.1.1",
"karma-sauce-launcher": "^0.2.14",
"load-grunt-tasks": "0.2.0",
"open": "0.0.4",
"phantomjs": "^1.9.17",
Expand Down
42 changes: 42 additions & 0 deletions test/.jshintrc
@@ -0,0 +1,42 @@
{
"camelcase": true,
"curly": true,
"eqeqeq": true,
"immed": true,
"indent": 2,
"newcap": true,
"noarg": true,
"quotmark": "single",
"undef": true,
"unused": true,
"trailing": true,
"white": true,
"maxparams": 20,
"maxdepth": 5,
"maxstatements": 300,
"maxlen": 140,
"evil": true,
"browser": true,
"devel": true,
"jquery": true,
"node": true,
"worker": true,
"expr": true,
"predef": [
"define",
"describe",
"before",
"beforeEach",
"after",
"afterEach",
"it"
],
"globals": {
"JSON": true,
"define": true,
"test": true,
"ok": true,
"equal": true,
"deepEqual": true
}
}
6 changes: 4 additions & 2 deletions test/karma.conf.js
Expand Up @@ -4,7 +4,7 @@ module.exports = function (config) {

config.set({
basePath: '../',
frameworks: ['requirejs', 'qunit'],
frameworks: ['requirejs', 'mocha'],
exclude: [],
reporters: ['progress', 'coverage'],
port: 9876,
Expand All @@ -14,9 +14,11 @@ module.exports = function (config) {
files: [
{pattern: 'src/js/**/*.js', included: false},
{pattern: 'test/**/*.js', included: false},
{pattern: 'node_modules/chai/*.js', included: false},
'test/test-main.js'
],
browsers: ['PhantomJS'],
// Chrome, ChromeCanary, Firefox, Opera, Safari, PhantomJS, IE
browsers: ['Chrome'],
captureTimeout: 60000,
singleRun: false,
preprocessors: { 'src/js/**/!(app|intro|outro).js': 'coverage' },
Expand Down
81 changes: 4 additions & 77 deletions test/test-main.js
Expand Up @@ -12,7 +12,9 @@ requirejs.config({

paths: {
jquery: '../../test/libs/jquery-1.9.1.min',
CodeMirror: '../../test/libs/codemirror'
CodeMirror: '../../test/libs/codemirror',
chai: '../../node_modules/chai/chai',
helper: '../../test/test-util'
},

shim: {
Expand All @@ -28,80 +30,5 @@ requirejs.config({
// ask Require.js to load these files (all our tests)
deps: tests,

callback: function () {
require([
'summernote/core/agent',
'../../test/unit/func.spec',
'../../test/unit/key.spec',
'../../test/unit/dom.spec',
'../../test/unit/list.spec',
'../../test/unit/range.spec',
'../../test/unit/style.spec'
], function (agent, funcSpec, keySpec, domSpec, listSpec, rangeSpec, styleSpec) {

var helper = {
equalsToUpperCase: function (actual, expected, comment) {
actual = actual.toUpperCase();
expected = expected.toUpperCase();

// [workaround] IE8-10 use   instead of bogus br
if (agent.isMSIE && agent.browserVersion < 11) {
expected = expected.replace(/<BR>/g, '&NBSP;');
}

// [workaround] IE8 actual markup has newline between tags
if (agent.isMSIE && agent.browserVersion < 9) {
actual = actual.replace(/\r\n/g, '');
}

equal(actual, expected, comment);
}
};

module('unit/func');
funcSpec(helper);
module('unit/key');
keySpec(helper);
module('unit/dom');
domSpec(helper);
module('unit/list');
listSpec(helper);
module('unit/range');
rangeSpec(helper);
module('unit/styleSpec');
styleSpec();
});


/* jshint ignore:start */
var log = [];
QUnit.done(function (test_results) {
var tests = [];
for(var i = 0, len = log.length; i < len; i++) {
var details = log[i];
tests.push({
name: details.name,
result: details.result,
expected: details.expected,
actual: details.actual,
source: details.source
});
}
test_results.tests = tests;

window.global_test_results = test_results;
});
QUnit.testStart(function(testDetails){
QUnit.log(function(details){
if (!details.result) {
details.name = testDetails.name;
log.push(details);
}
});
});
/* jshint ignore:end */

// start test run, once Require.js is done
window.__karma__.start();
}
callback: window.__karma__.start
});
22 changes: 22 additions & 0 deletions test/test-util.js
@@ -0,0 +1,22 @@
define([
'summernote/core/agent'
], function (agent) {
return {
equalsToUpperCase: function (actual, expected, assert) {
actual = actual.toUpperCase();
expected = expected.toUpperCase();

// [workaround] IE8-10 use &nbsp; instead of bogus br
if (agent.isMSIE && agent.browserVersion < 11) {
expected = expected.replace(/<BR>/g, '&NBSP;');
}

// [workaround] IE8 actual markup has newline between tags
if (agent.isMSIE && agent.browserVersion < 9) {
actual = actual.replace(/\r\n/g, '');
}

assert(actual).to.equal(expected);
}
};
});

0 comments on commit 4571d40

Please sign in to comment.