From dd255487c711e8f233803cce6b9ac9047b3df0e7 Mon Sep 17 00:00:00 2001 From: Saurav Khdoolia Date: Sun, 26 Jul 2020 13:55:36 +0530 Subject: [PATCH 01/11] Karma Init --- .gitignore | 1 + .travis.yml | 10 +- Gruntfile.js | 239 +++++++++++++++++++++++++----------------------- karma.config.js | 148 ++++++++++++++++++++++++++++++ package.json | 15 ++- 5 files changed, 290 insertions(+), 123 deletions(-) create mode 100644 karma.config.js diff --git a/.gitignore b/.gitignore index 2f2c1a005..49eb16ada 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ .DS_Store *.swo node_modules/ +.env .sass-cache/ npm-debug.log .grunt/ diff --git a/.travis.yml b/.travis.yml index b4b47a6b2..09a595731 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,12 +24,4 @@ before_script: - npm install -g grunt-cli script: - - npm run test:ci - -addons: - sauce_connect: true - -env: - global: - - secure: uSn+psGGU4v96aLw3egOywFLaZ1nAjwzbwpn/yUWXanPllHi7LZIe4tY41GfrE4CmD+brAQFRPkuxUnk5uOdtnwLPo5eSg/NAWEIVws2/UnPisr63YopB/LTLP9NqcUklZ8IsE3gcXrhMZWJBm5wfXj9pO+182zp6XHzID1yDAE= - - secure: On1IPA/AVPSJitzCK8XfYuYRJDi2/jNEP2Wux8S2L/AvmAQ0tUQN7ivxgoyZUb9Bez6OkxfFSDBsrIR3p7MiSIIZSPOD55/QiJyUtmH25WuIcrjyytaCEvNv2OeCNwS2EGQe0ToxdwRCCqBPJRLJTMyuvlnSkAKmKPPfdXjcCOM= + - npm run test:ci \ No newline at end of file diff --git a/Gruntfile.js b/Gruntfile.js index 8544542de..7468311d0 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -35,51 +35,51 @@ module.exports = function (grunt) { 'src/js/core.js', 'src/js/defaults/options.js', 'src/js/version.js' - ], - browsers = [{ - browserName: 'internet explorer', - version: '9', - platform: 'WIN7' - }, { - browserName: 'internet explorer', - version: '10', - platform: 'WIN8' - }, { - browserName: 'internet explorer', - version: '11', - platform: 'WIN8.1' - }, { - browserName: 'internet explorer', - version: '11', - platform: 'Windows 10' - }, { - browserName: 'MicrosoftEdge', - platform: 'Windows 10' - }, { - browserName: 'chrome', - platform: 'WIN8.1' - }, { - browserName: 'chrome', - platform: 'Windows 10' - }, { - browserName: 'googlechrome', - platform: 'OS X 10.11' - }, { - browserName: 'firefox', - platform: 'WIN8.1' - }, { - browserName: 'firefox', - platform: 'Windows 10' - }, { - browserName: 'firefox', - platform: 'OS X 10.11' - }, { - browserName: 'safari', - platform: 'OS X 10.10' - }, { - browserName: 'safari', - platform: 'OS X 10.11' - }]; + ]; + // browsers = [{ + // browserName: 'internet explorer', + // version: '9', + // platform: 'WIN7' + // }, { + // browserName: 'internet explorer', + // version: '10', + // platform: 'WIN8' + // }, { + // browserName: 'internet explorer', + // version: '11', + // platform: 'WIN8.1' + // }, { + // browserName: 'internet explorer', + // version: '11', + // platform: 'Windows 10' + // }, { + // browserName: 'MicrosoftEdge', + // platform: 'Windows 10' + // }, { + // browserName: 'chrome', + // platform: 'WIN8.1' + // }, { + // browserName: 'chrome', + // platform: 'Windows 10' + // }, { + // browserName: 'googlechrome', + // platform: 'OS X 10.11' + // }, { + // browserName: 'firefox', + // platform: 'WIN8.1' + // }, { + // browserName: 'firefox', + // platform: 'Windows 10' + // }, { + // browserName: 'firefox', + // platform: 'OS X 10.11' + // }, { + // browserName: 'safari', + // platform: 'OS X 10.10' + // }, { + // browserName: 'safari', + // platform: 'OS X 10.11' + // }]; gruntConfig.connect = { server: { @@ -119,46 +119,58 @@ module.exports = function (grunt) { } }; - gruntConfig.jasmine = { - suite: { - src: [srcFiles], - options: { - specs: ['spec/*.spec.js'], - helpers: 'spec/helpers/*.js', - vendor: [ - 'node_modules/lodash/index.js', - 'spec/vendor/jasmine-jsreporter.js', - 'spec/vendor/jasmine-jsreporter-script.js' - ], - polyfills: [ - 'src/js/polyfills.js' - ], - styles: 'dist/css/*.css', - junit: { - path: 'reports/jasmine/', - consolidate: true - }, - keepRunner: true, - template: require('grunt-template-jasmine-istanbul'), - templateOptions: { - coverage: 'reports/jasmine/coverage.json', - report: [{ - type: 'lcov', - options: { - dir: 'reports/jasmine/lcov' - } - }], - files: srcFiles.concat('!src/js/extensions/deprecated/*') - }, - summary: true - } + // gruntConfig.jasmine = { + // suite: { + // src: [srcFiles], + // options: { + // specs: ['spec/*.spec.js'], + // helpers: 'spec/helpers/*.js', + // vendor: [ + // 'node_modules/lodash/index.js', + // 'spec/vendor/jasmine-jsreporter.js', + // 'spec/vendor/jasmine-jsreporter-script.js' + // ], + // polyfills: [ + // 'src/js/polyfills.js' + // ], + // styles: 'dist/css/*.css', + // junit: { + // path: 'reports/jasmine/', + // consolidate: true + // }, + // keepRunner: true, + // template: require('grunt-template-jasmine-istanbul'), + // templateOptions: { + // coverage: 'reports/jasmine/coverage.json', + // report: [{ + // type: 'lcov', + // options: { + // dir: 'reports/jasmine/lcov' + // } + // }], + // files: srcFiles.concat('!src/js/extensions/deprecated/*') + // }, + // summary: true + // } + // }, + // spec: { + // src: 'src/js/**/*.js', + // options: { + // specs: ['spec/<%= globalConfig.file %>.spec.js'], + // helpers: 'spec/helpers/*.js' + // } + // } + // }; + + gruntConfig.karma = { + unit: { + configFile: 'karma.conf.js' }, - spec: { - src: 'src/js/**/*.js', - options: { - specs: ['spec/<%= globalConfig.file %>.spec.js'], - helpers: 'spec/helpers/*.js' - } + dev: { + configFile: 'karma.conf.js', + browsers: [ + 'Chrome' + ] } }; @@ -287,30 +299,30 @@ module.exports = function (grunt) { } }; - gruntConfig['saucelabs-jasmine'] = { - all: { - options: { - urls: ['http://localhost:9999/_SpecRunner.html'], - tunnelTimeout: 5, - build: process.env.TRAVIS_JOB_ID, - concurrency: 3, - browsers: browsers, - sauceConfig: { - public: 'public', - build: process.env.TRAVIS_JOB_ID, - name: 'medium-editor-tests', - maxDuration: 900, - idleTimeout: 600 - } - } - } - }; + // gruntConfig['saucelabs-jasmine'] = { + // all: { + // options: { + // urls: ['http://localhost:9999/_SpecRunner.html'], + // tunnelTimeout: 5, + // build: process.env.TRAVIS_JOB_ID, + // concurrency: 3, + // browsers: browsers, + // sauceConfig: { + // public: 'public', + // build: process.env.TRAVIS_JOB_ID, + // name: 'medium-editor-tests', + // maxDuration: 900, + // idleTimeout: 600 + // } + // } + // } + // }; - gruntConfig.coveralls = { - dist: { - src: 'reports/jasmine/lcov/lcov.info' - } - }; + // gruntConfig.coveralls = { + // dist: { + // src: 'reports/jasmine/lcov/lcov.info' + // } + // }; gruntConfig.bump = { options: { @@ -333,14 +345,15 @@ module.exports = function (grunt) { }); if (parseInt(process.env.TRAVIS_PULL_REQUEST, 10) > 0) { - grunt.registerTask('travis', ['jshint', 'jscs', 'jasmine:suite', 'csslint', 'coveralls']); + grunt.registerTask('travis', ['jshint', 'jscs', 'karma:dev', 'csslint']); } else { - grunt.registerTask('travis', ['connect', 'jshint', 'jscs', 'jasmine:suite', 'csslint', 'saucelabs-jasmine', 'coveralls']); + // grunt.registerTask('travis', ['connect', 'jshint', 'jscs', 'jasmine:suite', 'csslint', 'saucelabs-jasmine', 'coveralls']); + grunt.registerTask('travis', ['connect', 'jshint', 'jscs', 'csslint', 'karma:unit']); } - grunt.registerTask('test', ['jshint', 'jscs', 'concat', 'jasmine:suite', 'csslint']); - grunt.registerTask('sauce', ['connect', 'saucelabs-jasmine']); - grunt.registerTask('js', ['jshint', 'jscs', 'concat', 'jasmine:suite', 'uglify']); + grunt.registerTask('test', ['jshint', 'jscs', 'concat', 'csslint', 'karma:dev']); + // grunt.registerTask('sauce', ['connect', 'saucelabs-jasmine']); + grunt.registerTask('js', ['jshint', 'jscs', 'concat', 'karma:dev', 'uglify']); grunt.registerTask('css', ['sass', 'autoprefixer', 'cssmin', 'csslint']); grunt.registerTask('default', ['js', 'css']); @@ -353,4 +366,4 @@ module.exports = function (grunt) { grunt.registerTask('patch', ['bump', 'css', 'js']); grunt.registerTask('minor', ['bump:minor', 'css', 'js']); grunt.registerTask('major', ['bump:major', 'css', 'js']); -}; +}; \ No newline at end of file diff --git a/karma.config.js b/karma.config.js new file mode 100644 index 000000000..9bba2ecd7 --- /dev/null +++ b/karma.config.js @@ -0,0 +1,148 @@ +/* global module, process */ + +module.exports = function (config) { + config.set({ + + browserStack: { + apiClientEndpoint: 'https://api.browserstack.com' + }, + + customLaunchers: { + WIN81Chrome: { + 'base': 'BrowserStack', + 'os': 'Windows', + 'os_version': '8.1', + 'browser': 'chrome' + }, + WIN81Firefox: { + 'base': 'BrowserStack', + 'os': 'Windows', + 'os_version': '8.1', + 'browser': 'firefox' + }, + WIN81Edge: { + 'base': 'BrowserStack', + 'os': 'Windows', + 'os_version': '8.1', + 'browser': 'edge' + }, + WIN10Chrome: { + 'base': 'BrowserStack', + 'os': 'Windows', + 'os_version': '10', + 'browser': 'chrome' + }, + WIN10Firefox: { + 'base': 'BrowserStack', + 'os': 'Windows', + 'os_version': '10', + 'browser': 'firefox' + }, + WIN10Edge: { + 'base': 'BrowserStack', + 'os': 'Windows', + 'os_version': '10', + 'browser': 'edge' + }, + OSXYosemiteSafari: { + 'base': 'BrowserStack', + 'os': 'OS X', + 'os_version': 'Yosemite', + 'browser': 'safari' + }, + OSXElCapitanChrome: { + 'base': 'BrowserStack', + 'os': 'OS X', + 'os_version': 'El Capitan', + 'browser': 'chrome' + }, + OSXElCapitanSafari: { + 'base': 'BrowserStack', + 'os': 'OS X', + 'os_version': 'El Capitan', + 'browser': 'safari' + }, + OSXElCapitanFirefox: { + 'base': 'BrowserStack', + 'os': 'OS X', + 'os_version': 'El Capitan', + 'browser': 'firefox' + } + }, + + basePath: '', + frameworks: ['jasmine'], + + files: [ + 'node_modules/lodash/index.js', + 'spec/vendor/jasmine-jsreporter.js', + 'spec/vendor/jasmine-jsreporter-script.js', + 'src/js/polyfills.js', + 'src/js/globals.js', + 'src/js/util.js', + 'src/js/extension.js', + 'src/js/selection.js', + 'src/js/events.js', + 'src/js/extensions/button.js', + 'src/js/defaults/buttons.js', + 'src/js/extensions/form.js', + 'src/js/extensions/anchor.js', + 'src/js/extensions/anchor-preview.js', + 'src/js/extensions/auto-link.js', + 'src/js/extensions/file-dragging.js', + 'src/js/extensions/keyboard-commands.js', + 'src/js/extensions/fontname.js', + 'src/js/extensions/fontsize.js', + 'src/js/extensions/paste.js', + 'src/js/extensions/placeholder.js', + 'src/js/extensions/toolbar.js', + 'src/js/extensions/deprecated/image-dragging.js', + 'src/js/core.js', + 'src/js/defaults/options.js', + 'src/js/version.js', + 'spec/helpers/util.js', + 'spec/*.spec.js' + ], + + exclude: [ + 'src/js/extensions/deprecated/*' + ], + + preprocessors: { + }, + + plugins: [ + 'karma-jasmine', + 'karma-spec-reporter', + 'karma-jasmine-html-reporter', + 'karma-browserstack-launcher', + 'karma-phantomjs-launcher', + 'karma-chrome-launcher' + ], + + reporters: ['coverage', 'coveralls', 'progress', 'BrowserStack', 'dots', 'spec', 'kjhtml'], + + coverageReporter: { + type: 'lcov', + dir: 'coverage/' + }, + + port: 9876, + + logLevel: config.LOG_INFO, + colors: true, + + autoWatch: false, + + // browsers: ['WIN81Chrome', 'WIN81Edge', 'WIN81Firefox', 'WIN10Chrome', 'WIN10Edge', 'WIN10Firefox', 'OSXYosemiteSafari', 'OSXElCapitanChrome', 'OSXElCapitanFirefox', 'OSXElCapitanSafari'], + browsers: ['WIN10Chrome', 'WIN81Chrome', 'OSXElCapitanChrome'], + + client: { + clearContext: false + }, + + singleRun: true, + + concurrency: Infinity + }); +}; \ No newline at end of file diff --git a/package.json b/package.json index b87c51586..ec4f022dc 100644 --- a/package.json +++ b/package.json @@ -55,14 +55,27 @@ "grunt-contrib-watch": "1.1.0", "grunt-coveralls": "2.0.0", "grunt-jscs": "3.0.1", + "grunt-karma": "4.0.0", "grunt-plato": "1.4.0", "grunt-sass": "3.1.0", - "grunt-saucelabs": "9.0.1", "grunt-template-jasmine-istanbul": "0.4.0", + "jasmine": "3.6.1", + "jasmine-console-reporter": "3.1.0", + "jasmine-core": "3.6.0", "jshint-stylish": "2.2.1", + "karma": "5.1.0", + "karma-browserstack-launcher": "1.6.0", + "karma-chrome-launcher": "3.1.0", + "karma-coverage": "2.0.3", + "karma-coveralls": "2.1.0", + "karma-jasmine": "3.3.1", + "karma-jasmine-html-reporter": "1.5.4", + "karma-phantomjs-launcher": "1.0.4", + "karma-spec-reporter": "0.0.32", "load-grunt-tasks": "5.1.0", "lodash": "3.10.1", "open-cli": "6.0.1", + "phantomjs-prebuilt": "2.1.16", "serve-static": "1.14.1", "time-grunt": "2.0.0" }, From 810b9995c86aae77abdb88757c57190715062e09 Mon Sep 17 00:00:00 2001 From: Saurav Khdoolia Date: Sun, 26 Jul 2020 13:58:59 +0530 Subject: [PATCH 02/11] Karma Conf --- karma.config.js => karma.conf.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename karma.config.js => karma.conf.js (100%) diff --git a/karma.config.js b/karma.conf.js similarity index 100% rename from karma.config.js rename to karma.conf.js From fa3ea814d775995082665dd7160ce88775f63da2 Mon Sep 17 00:00:00 2001 From: Saurav Khdoolia Date: Sun, 26 Jul 2020 14:04:00 +0530 Subject: [PATCH 03/11] Coverage --- Gruntfile.js | 4 ++-- karma.conf.js | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 7468311d0..3f04e042c 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -345,10 +345,10 @@ module.exports = function (grunt) { }); if (parseInt(process.env.TRAVIS_PULL_REQUEST, 10) > 0) { - grunt.registerTask('travis', ['jshint', 'jscs', 'karma:dev', 'csslint']); + grunt.registerTask('travis', ['jshint', 'jscs', 'karma:unit', 'csslint']); } else { // grunt.registerTask('travis', ['connect', 'jshint', 'jscs', 'jasmine:suite', 'csslint', 'saucelabs-jasmine', 'coveralls']); - grunt.registerTask('travis', ['connect', 'jshint', 'jscs', 'csslint', 'karma:unit']); + grunt.registerTask('travis', ['jshint', 'jscs', 'csslint', 'karma:unit']); } grunt.registerTask('test', ['jshint', 'jscs', 'concat', 'csslint', 'karma:dev']); diff --git a/karma.conf.js b/karma.conf.js index 9bba2ecd7..d1bd92d36 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -117,7 +117,9 @@ module.exports = function (config) { 'karma-jasmine-html-reporter', 'karma-browserstack-launcher', 'karma-phantomjs-launcher', - 'karma-chrome-launcher' + 'karma-chrome-launcher', + 'karma-coverage', + 'karma-coveralls' ], reporters: ['coverage', 'coveralls', 'progress', 'BrowserStack', 'dots', 'spec', 'kjhtml'], From 69dae1dbefb0d5fb2bd635250cc5a36e703c45c7 Mon Sep 17 00:00:00 2001 From: Saurav Khdoolia Date: Sun, 26 Jul 2020 14:06:27 +0530 Subject: [PATCH 04/11] Coverage on Unit --- Gruntfile.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Gruntfile.js b/Gruntfile.js index 3f04e042c..925ee15d2 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -170,7 +170,16 @@ module.exports = function (grunt) { configFile: 'karma.conf.js', browsers: [ 'Chrome' - ] + ], + plugins: [ + 'karma-jasmine', + 'karma-spec-reporter', + 'karma-jasmine-html-reporter', + 'karma-browserstack-launcher', + 'karma-phantomjs-launcher', + 'karma-chrome-launcher' + ], + reporters: ['progress', 'BrowserStack', 'dots', 'spec', 'kjhtml'] } }; From 801cb749b6aa7ee1ac8902902357ab9156412bf4 Mon Sep 17 00:00:00 2001 From: Saurav Khdoolia Date: Sun, 26 Jul 2020 15:10:05 +0530 Subject: [PATCH 05/11] Tests working --- karma.conf.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/karma.conf.js b/karma.conf.js index d1bd92d36..cf9650fc3 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -4,7 +4,8 @@ module.exports = function (config) { config.set({ browserStack: { - apiClientEndpoint: 'https://api.browserstack.com' + apiClientEndpoint: 'https://api.browserstack.com', + timeout: 600 }, customLaunchers: { From 9f5f11a348f9e3938ff39799b43563fb03103587 Mon Sep 17 00:00:00 2001 From: Saurav Khdoolia Date: Sun, 26 Jul 2020 15:19:32 +0530 Subject: [PATCH 06/11] Correcting Tests --- karma.conf.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/karma.conf.js b/karma.conf.js index cf9650fc3..8269f9133 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -132,7 +132,7 @@ module.exports = function (config) { port: 9876, - logLevel: config.LOG_INFO, + logLevel: config.LOG_DEBUG, colors: true, autoWatch: false, From a8c033dde2ad90367ded7b80bd4b8605db602412 Mon Sep 17 00:00:00 2001 From: Saurav Khdoolia Date: Sun, 26 Jul 2020 17:53:05 +0530 Subject: [PATCH 07/11] Firefox Focus without Selection__Correction --- .gitignore | 4 ++++ karma.conf.js | 1 + package.json | 1 + src/js/core.js | 4 ++-- 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 49eb16ada..5d35fa2b8 100644 --- a/.gitignore +++ b/.gitignore @@ -11,7 +11,11 @@ _SpecRunner.html reports/ coverage/ ._* +local.log +browserstack.err # IDE .idea/ package-lock.json + + diff --git a/karma.conf.js b/karma.conf.js index 8269f9133..0316ae408 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -118,6 +118,7 @@ module.exports = function (config) { 'karma-jasmine-html-reporter', 'karma-browserstack-launcher', 'karma-phantomjs-launcher', + 'karma-firefox-launcher', 'karma-chrome-launcher', 'karma-coverage', 'karma-coveralls' diff --git a/package.json b/package.json index ec4f022dc..6a2990197 100644 --- a/package.json +++ b/package.json @@ -68,6 +68,7 @@ "karma-chrome-launcher": "3.1.0", "karma-coverage": "2.0.3", "karma-coveralls": "2.1.0", + "karma-firefox-launcher": "1.3.0", "karma-jasmine": "3.3.1", "karma-jasmine-html-reporter": "1.5.4", "karma-phantomjs-launcher": "1.0.4", diff --git a/src/js/core.js b/src/js/core.js index a8758d111..7bb493b16 100644 --- a/src/js/core.js +++ b/src/js/core.js @@ -957,8 +957,8 @@ } // https://github.com/yabwe/medium-editor/issues/1496 - // ensure the focus remains in the editor for Firefox - if (MediumEditor.util.isFF) { + // But only if something is selected i.e, getSelectedParentElement !== {} + if (this.getSelectedParentElement().length > 0 && MediumEditor.util.isFF) { MediumEditor.util.getContainerEditorElement(this.getSelectedParentElement()).focus(); } From ba35736eb4db57a4705c5ecfc7a96e2b3e9512d6 Mon Sep 17 00:00:00 2001 From: Saurav Khdoolia Date: Sun, 26 Jul 2020 18:01:52 +0530 Subject: [PATCH 08/11] Added Edge and Firefox to karma config --- karma.conf.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/karma.conf.js b/karma.conf.js index 0316ae408..6599f128b 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -138,8 +138,8 @@ module.exports = function (config) { autoWatch: false, - // browsers: ['WIN81Chrome', 'WIN81Edge', 'WIN81Firefox', 'WIN10Chrome', 'WIN10Edge', 'WIN10Firefox', 'OSXYosemiteSafari', 'OSXElCapitanChrome', 'OSXElCapitanFirefox', 'OSXElCapitanSafari'], - browsers: ['WIN10Chrome', 'WIN81Chrome', 'OSXElCapitanChrome'], + // TODO: 'OSXYosemiteSafari', 'OSXElCapitanSafari' + browsers: ['WIN10Edge', 'WIN10Chrome', 'WIN10Firefox', 'WIN81Edge', 'WIN81Chrome', 'WIN81Firefox', 'OSXElCapitanChrome', 'OSXElCapitanFirefox'], client: { clearContext: false From c40c28640a55a39f67d1fe79b537dbc454b793fa Mon Sep 17 00:00:00 2001 From: Saurav Khdoolia Date: Mon, 27 Jul 2020 18:01:35 +0530 Subject: [PATCH 09/11] Safari Tests Passing --- Gruntfile.js | 116 ------------------------------------------------- karma.conf.js | 10 ++--- src/js/core.js | 80 ++++++++++++++++++---------------- 3 files changed, 46 insertions(+), 160 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 925ee15d2..126df8c99 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -36,51 +36,6 @@ module.exports = function (grunt) { 'src/js/defaults/options.js', 'src/js/version.js' ]; - // browsers = [{ - // browserName: 'internet explorer', - // version: '9', - // platform: 'WIN7' - // }, { - // browserName: 'internet explorer', - // version: '10', - // platform: 'WIN8' - // }, { - // browserName: 'internet explorer', - // version: '11', - // platform: 'WIN8.1' - // }, { - // browserName: 'internet explorer', - // version: '11', - // platform: 'Windows 10' - // }, { - // browserName: 'MicrosoftEdge', - // platform: 'Windows 10' - // }, { - // browserName: 'chrome', - // platform: 'WIN8.1' - // }, { - // browserName: 'chrome', - // platform: 'Windows 10' - // }, { - // browserName: 'googlechrome', - // platform: 'OS X 10.11' - // }, { - // browserName: 'firefox', - // platform: 'WIN8.1' - // }, { - // browserName: 'firefox', - // platform: 'Windows 10' - // }, { - // browserName: 'firefox', - // platform: 'OS X 10.11' - // }, { - // browserName: 'safari', - // platform: 'OS X 10.10' - // }, { - // browserName: 'safari', - // platform: 'OS X 10.11' - // }]; - gruntConfig.connect = { server: { options: { @@ -119,49 +74,6 @@ module.exports = function (grunt) { } }; - // gruntConfig.jasmine = { - // suite: { - // src: [srcFiles], - // options: { - // specs: ['spec/*.spec.js'], - // helpers: 'spec/helpers/*.js', - // vendor: [ - // 'node_modules/lodash/index.js', - // 'spec/vendor/jasmine-jsreporter.js', - // 'spec/vendor/jasmine-jsreporter-script.js' - // ], - // polyfills: [ - // 'src/js/polyfills.js' - // ], - // styles: 'dist/css/*.css', - // junit: { - // path: 'reports/jasmine/', - // consolidate: true - // }, - // keepRunner: true, - // template: require('grunt-template-jasmine-istanbul'), - // templateOptions: { - // coverage: 'reports/jasmine/coverage.json', - // report: [{ - // type: 'lcov', - // options: { - // dir: 'reports/jasmine/lcov' - // } - // }], - // files: srcFiles.concat('!src/js/extensions/deprecated/*') - // }, - // summary: true - // } - // }, - // spec: { - // src: 'src/js/**/*.js', - // options: { - // specs: ['spec/<%= globalConfig.file %>.spec.js'], - // helpers: 'spec/helpers/*.js' - // } - // } - // }; - gruntConfig.karma = { unit: { configFile: 'karma.conf.js' @@ -308,31 +220,6 @@ module.exports = function (grunt) { } }; - // gruntConfig['saucelabs-jasmine'] = { - // all: { - // options: { - // urls: ['http://localhost:9999/_SpecRunner.html'], - // tunnelTimeout: 5, - // build: process.env.TRAVIS_JOB_ID, - // concurrency: 3, - // browsers: browsers, - // sauceConfig: { - // public: 'public', - // build: process.env.TRAVIS_JOB_ID, - // name: 'medium-editor-tests', - // maxDuration: 900, - // idleTimeout: 600 - // } - // } - // } - // }; - - // gruntConfig.coveralls = { - // dist: { - // src: 'reports/jasmine/lcov/lcov.info' - // } - // }; - gruntConfig.bump = { options: { files: ['package.json', 'src/js/version.js'], @@ -356,12 +243,10 @@ module.exports = function (grunt) { if (parseInt(process.env.TRAVIS_PULL_REQUEST, 10) > 0) { grunt.registerTask('travis', ['jshint', 'jscs', 'karma:unit', 'csslint']); } else { - // grunt.registerTask('travis', ['connect', 'jshint', 'jscs', 'jasmine:suite', 'csslint', 'saucelabs-jasmine', 'coveralls']); grunt.registerTask('travis', ['jshint', 'jscs', 'csslint', 'karma:unit']); } grunt.registerTask('test', ['jshint', 'jscs', 'concat', 'csslint', 'karma:dev']); - // grunt.registerTask('sauce', ['connect', 'saucelabs-jasmine']); grunt.registerTask('js', ['jshint', 'jscs', 'concat', 'karma:dev', 'uglify']); grunt.registerTask('css', ['sass', 'autoprefixer', 'cssmin', 'csslint']); grunt.registerTask('default', ['js', 'css']); @@ -371,7 +256,6 @@ module.exports = function (grunt) { grunt.task.run(taskName + ':spec'); }); - // release tasks grunt.registerTask('patch', ['bump', 'css', 'js']); grunt.registerTask('minor', ['bump:minor', 'css', 'js']); grunt.registerTask('major', ['bump:major', 'css', 'js']); diff --git a/karma.conf.js b/karma.conf.js index 6599f128b..a4a61af2d 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -1,4 +1,4 @@ -/* global module, process */ +/* global module */ module.exports = function (config) { config.set({ @@ -75,9 +75,8 @@ module.exports = function (config) { frameworks: ['jasmine'], files: [ + 'dist/css/*.css', 'node_modules/lodash/index.js', - 'spec/vendor/jasmine-jsreporter.js', - 'spec/vendor/jasmine-jsreporter-script.js', 'src/js/polyfills.js', 'src/js/globals.js', 'src/js/util.js', @@ -133,13 +132,12 @@ module.exports = function (config) { port: 9876, - logLevel: config.LOG_DEBUG, + logLevel: config.LOG_INFO, colors: true, autoWatch: false, - // TODO: 'OSXYosemiteSafari', 'OSXElCapitanSafari' - browsers: ['WIN10Edge', 'WIN10Chrome', 'WIN10Firefox', 'WIN81Edge', 'WIN81Chrome', 'WIN81Firefox', 'OSXElCapitanChrome', 'OSXElCapitanFirefox'], + browsers: ['WIN10Edge', 'WIN10Chrome', 'WIN10Firefox', 'WIN81Edge', 'WIN81Chrome', 'WIN81Firefox', 'OSXElCapitanChrome', 'OSXElCapitanFirefox', 'OSXElCapitanSafari', 'OSXYosemiteSafari'], client: { clearContext: false diff --git a/src/js/core.js b/src/js/core.js index 7bb493b16..0a7354aab 100644 --- a/src/js/core.js +++ b/src/js/core.js @@ -24,7 +24,7 @@ // if current text selection is empty OR previous sibling text is empty OR it is not a list if ((node && node.textContent.trim() === '' && node.nodeName.toLowerCase() !== 'li') || (node.previousElementSibling && node.previousElementSibling.nodeName.toLowerCase() !== 'br' && - node.previousElementSibling.textContent.trim() === '')) { + node.previousElementSibling.textContent.trim() === '')) { event.preventDefault(); } } @@ -60,12 +60,12 @@ isHeader = /h\d/i; if (MediumEditor.util.isKey(event, [MediumEditor.util.keyCode.BACKSPACE, MediumEditor.util.keyCode.ENTER]) && - // has a preceeding sibling - node.previousElementSibling && - // in a header - isHeader.test(tagName) && - // at the very end of the block - MediumEditor.selection.getCaretOffsets(node).left === 0) { + // has a preceeding sibling + node.previousElementSibling && + // in a header + isHeader.test(tagName) && + // at the very end of the block + MediumEditor.selection.getCaretOffsets(node).left === 0) { if (MediumEditor.util.isKey(event, MediumEditor.util.keyCode.BACKSPACE) && isEmpty.test(node.previousElementSibling.innerHTML)) { // backspacing the begining of a header into an empty previous element will // change the tagName of the current node to prevent one @@ -81,15 +81,15 @@ event.preventDefault(); } } else if (MediumEditor.util.isKey(event, MediumEditor.util.keyCode.DELETE) && - // between two sibling elements - node.nextElementSibling && - node.previousElementSibling && - // not in a header - !isHeader.test(tagName) && - // in an empty tag - isEmpty.test(node.innerHTML) && - // when the next tag *is* a header - isHeader.test(node.nextElementSibling.nodeName.toLowerCase())) { + // between two sibling elements + node.nextElementSibling && + node.previousElementSibling && + // not in a header + !isHeader.test(tagName) && + // in an empty tag + isEmpty.test(node.innerHTML) && + // when the next tag *is* a header + isHeader.test(node.nextElementSibling.nodeName.toLowerCase())) { // hitting delete in an empty element preceding a header, ex: //

[CURSOR]

Header

// Will cause the h1 to become a paragraph. @@ -102,16 +102,16 @@ event.preventDefault(); } else if (MediumEditor.util.isKey(event, MediumEditor.util.keyCode.BACKSPACE) && - tagName === 'li' && - // hitting backspace inside an empty li - isEmpty.test(node.innerHTML) && - // is first element (no preceeding siblings) - !node.previousElementSibling && - // parent also does not have a sibling - !node.parentElement.previousElementSibling && - // is not the only li in a list - node.nextElementSibling && - node.nextElementSibling.nodeName.toLowerCase() === 'li') { + tagName === 'li' && + // hitting backspace inside an empty li + isEmpty.test(node.innerHTML) && + // is first element (no preceeding siblings) + !node.previousElementSibling && + // parent also does not have a sibling + !node.parentElement.previousElementSibling && + // is not the only li in a list + node.nextElementSibling && + node.nextElementSibling.nodeName.toLowerCase() === 'li') { // backspacing in an empty first list element in the first list (with more elements) ex: //
  • [CURSOR]
  • List Item 2
// will remove the first
  • but add some extra element before (varies based on browser) @@ -133,16 +133,16 @@ event.preventDefault(); } else if (MediumEditor.util.isKey(event, MediumEditor.util.keyCode.BACKSPACE) && - (MediumEditor.util.getClosestTag(node, 'blockquote') !== false) && - MediumEditor.selection.getCaretOffsets(node).left === 0) { + (MediumEditor.util.getClosestTag(node, 'blockquote') !== false) && + MediumEditor.selection.getCaretOffsets(node).left === 0) { // when cursor is at the begining of the element and the element is
    // then pressing backspace key should change the
    to a

    tag event.preventDefault(); MediumEditor.util.execFormatBlock(this.options.ownerDocument, 'p'); } else if (MediumEditor.util.isKey(event, MediumEditor.util.keyCode.ENTER) && - (MediumEditor.util.getClosestTag(node, 'blockquote') !== false) && - MediumEditor.selection.getCaretOffsets(node).right === 0) { + (MediumEditor.util.getClosestTag(node, 'blockquote') !== false) && + MediumEditor.selection.getCaretOffsets(node).right === 0) { // when cursor is at the end of

    , // then pressing enter key should create

    tag, not

    @@ -155,10 +155,10 @@ event.preventDefault(); } else if (MediumEditor.util.isKey(event, MediumEditor.util.keyCode.BACKSPACE) && - MediumEditor.util.isMediumEditorElement(node.parentElement) && - !node.previousElementSibling && - node.nextElementSibling && - isEmpty.test(node.innerHTML)) { + MediumEditor.util.isMediumEditorElement(node.parentElement) && + !node.previousElementSibling && + node.nextElementSibling && + isEmpty.test(node.innerHTML)) { // when cursor is in the first element, it's empty and user presses backspace, // do delete action instead to get rid of the first element and move caret to 2nd @@ -334,8 +334,8 @@ // If any of the elements don't have the toolbar disabled // We need a toolbar if (this.elements.every(function (element) { - return !!element.getAttribute('data-disable-toolbar'); - })) { + return !!element.getAttribute('data-disable-toolbar'); + })) { return false; } @@ -968,7 +968,11 @@ getSelectedParentElement: function (range) { if (range === undefined) { - range = this.options.contentWindow.getSelection().getRangeAt(0); + try { + range = this.options.contentWindow.getSelection().getRangeAt(0); + } catch (err) { + return {}; + } } return MediumEditor.selection.getSelectedParentElement(range); }, @@ -1123,7 +1127,7 @@ 0, parentElement.lastChild, parentElement.lastChild.nodeType === 3 ? - parentElement.lastChild.nodeValue.length : parentElement.lastChild.childNodes.length + parentElement.lastChild.nodeValue.length : parentElement.lastChild.childNodes.length ); } else { MediumEditor.selection.select( From 390fac606705e405d1a6c8a44dca96ad806e629b Mon Sep 17 00:00:00 2001 From: Saurav Khdoolia Date: Mon, 27 Jul 2020 18:10:51 +0530 Subject: [PATCH 10/11] Maxm Log length resolve: Different karma conffiles --- Gruntfile.js | 14 +-------- karma.conf.js | 2 +- karma.dev.conf.js | 74 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+), 14 deletions(-) create mode 100644 karma.dev.conf.js diff --git a/Gruntfile.js b/Gruntfile.js index 126df8c99..c8c7c3203 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -79,19 +79,7 @@ module.exports = function (grunt) { configFile: 'karma.conf.js' }, dev: { - configFile: 'karma.conf.js', - browsers: [ - 'Chrome' - ], - plugins: [ - 'karma-jasmine', - 'karma-spec-reporter', - 'karma-jasmine-html-reporter', - 'karma-browserstack-launcher', - 'karma-phantomjs-launcher', - 'karma-chrome-launcher' - ], - reporters: ['progress', 'BrowserStack', 'dots', 'spec', 'kjhtml'] + configFile: 'karma.dev.conf.js' } }; diff --git a/karma.conf.js b/karma.conf.js index a4a61af2d..5c2b14931 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -132,7 +132,7 @@ module.exports = function (config) { port: 9876, - logLevel: config.LOG_INFO, + logLevel: config.LOG_ERROR, colors: true, autoWatch: false, diff --git a/karma.dev.conf.js b/karma.dev.conf.js new file mode 100644 index 000000000..fb18893f8 --- /dev/null +++ b/karma.dev.conf.js @@ -0,0 +1,74 @@ +/* global module */ + +module.exports = function (config) { + config.set({ + + basePath: '', + frameworks: ['jasmine'], + + files: [ + 'dist/css/*.css', + 'node_modules/lodash/index.js', + 'src/js/polyfills.js', + 'src/js/globals.js', + 'src/js/util.js', + 'src/js/extension.js', + 'src/js/selection.js', + 'src/js/events.js', + 'src/js/extensions/button.js', + 'src/js/defaults/buttons.js', + 'src/js/extensions/form.js', + 'src/js/extensions/anchor.js', + 'src/js/extensions/anchor-preview.js', + 'src/js/extensions/auto-link.js', + 'src/js/extensions/file-dragging.js', + 'src/js/extensions/keyboard-commands.js', + 'src/js/extensions/fontname.js', + 'src/js/extensions/fontsize.js', + 'src/js/extensions/paste.js', + 'src/js/extensions/placeholder.js', + 'src/js/extensions/toolbar.js', + 'src/js/extensions/deprecated/image-dragging.js', + 'src/js/core.js', + 'src/js/defaults/options.js', + 'src/js/version.js', + 'spec/helpers/util.js', + 'spec/*.spec.js' + ], + + exclude: [ + 'src/js/extensions/deprecated/*' + ], + + preprocessors: { + }, + + browsers: [ + 'Chrome' + ], + plugins: [ + 'karma-jasmine', + 'karma-spec-reporter', + 'karma-jasmine-html-reporter', + 'karma-browserstack-launcher', + 'karma-phantomjs-launcher', + 'karma-chrome-launcher' + ], + reporters: ['progress', 'BrowserStack', 'dots', 'spec', 'kjhtml'], + + port: 9876, + + logLevel: config.LOG_INFO, + colors: true, + + autoWatch: false, + + client: { + clearContext: false + }, + + singleRun: true, + + concurrency: Infinity + }); +}; \ No newline at end of file From a7161c0090de1eb6787c785fc301f65b5c3736cf Mon Sep 17 00:00:00 2001 From: Saurav Khdoolia Date: Mon, 27 Jul 2020 18:26:22 +0530 Subject: [PATCH 11/11] Removing Extra browsers --- karma.conf.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/karma.conf.js b/karma.conf.js index 5c2b14931..79cfd93bf 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -123,7 +123,7 @@ module.exports = function (config) { 'karma-coveralls' ], - reporters: ['coverage', 'coveralls', 'progress', 'BrowserStack', 'dots', 'spec', 'kjhtml'], + reporters: ['coverage', 'coveralls', 'BrowserStack', 'dots', 'spec', 'kjhtml'], coverageReporter: { type: 'lcov', @@ -137,7 +137,7 @@ module.exports = function (config) { autoWatch: false, - browsers: ['WIN10Edge', 'WIN10Chrome', 'WIN10Firefox', 'WIN81Edge', 'WIN81Chrome', 'WIN81Firefox', 'OSXElCapitanChrome', 'OSXElCapitanFirefox', 'OSXElCapitanSafari', 'OSXYosemiteSafari'], + browsers: ['WIN10Edge', 'WIN10Chrome', 'WIN10Firefox', 'OSXElCapitanChrome', 'OSXElCapitanFirefox', 'OSXYosemiteSafari'], client: { clearContext: false