From 332ceb0da65ad935e5f85c109a37979099abad86 Mon Sep 17 00:00:00 2001 From: Tyler Long Date: Tue, 18 Apr 2017 22:14:02 +0800 Subject: [PATCH] Replace karma + PhantomJS with karma + Chrome headless --- karma.conf.js | 22 ++++++++++++++-------- package.json | 4 ++-- src/utils.spec.js | 20 ++++++++++---------- todo.md | 2 ++ yarn.lock | 48 ++++++++++++++++++++++++++++------------------- 5 files changed, 57 insertions(+), 39 deletions(-) diff --git a/karma.conf.js b/karma.conf.js index 44a702118..07c9efffb 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -26,12 +26,8 @@ module.exports = function (config) { 'src/**/*.spec.js': ['browserify'] }, - // list of files to exclude - // exclude: ['src/diagrams/*.js'], - browserify: { debug: true, - // plugin: ['proxyquireify/plugin'] extensions: ['.js'], configure: function (bundle) { bundle.on('prebundle', function () { @@ -40,8 +36,6 @@ module.exports = function (config) { }) } }, - // preprocess matching files before serving them to the browser - // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor // test results reporter to use // possible values: 'dots', 'progress' @@ -61,12 +55,24 @@ module.exports = function (config) { // enable / disable watching file and executing tests whenever any file changes autoWatch: true, + customLaunchers: { + ChromeCanaryHeadless: { + base: 'ChromeCanary', + flags: [ + '--headless', + '--disable-gpu', + // Without a remote debugging port, Google Chrome exits immediately. + '--remote-debugging-port=9222' + ] + } + }, + // start these browsers // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher - browsers: ['PhantomJS'], + browsers: ['ChromeCanaryHeadless'], plugins: [ 'karma-jasmine', - 'karma-phantomjs-launcher', + 'karma-chrome-launcher', 'karma-browserify', 'karma-babel-preprocessor' ], diff --git a/package.json b/package.json index c6130ab68..c6f0ca5ea 100644 --- a/package.json +++ b/package.json @@ -124,13 +124,13 @@ "karma": "^1.6.0", "karma-babel-preprocessor": "^6.0.1", "karma-browserify": "^5.1.1", + "karma-chrome-launcher": "^2.0.0", "karma-jasmine": "^1.1.0", - "karma-phantomjs-launcher": "^1.0.4", "live-server": "^1.2.0", "map-stream": "0.0.7", "marked": "^0.3.6", "mock-browser": "^0.92.14", - "npm-check-updates": "^2.10.5", + "npm-check-updates": "^2.11.0", "npm-watch": "^0.1.8", "phantomjs": "^2.1.7", "proxyquire": "^1.7.11", diff --git a/src/utils.spec.js b/src/utils.spec.js index 420c6bede..a978b9b38 100644 --- a/src/utils.spec.js +++ b/src/utils.spec.js @@ -64,13 +64,13 @@ describe('when cloning CSS ', function () { function addStyleToDocument () { var s = document.createElement('style') - s.innerHTML = '.node { stroke:#eeeeee; }\n.node-square { stroke:#bbbbbb; }\n' + s.innerHTML = '.node { stroke:rgb(238, 238, 238); }\n.node-square { stroke:rgb(187, 187, 187); }\n' document.body.appendChild(s) } function addSecondStyleToDocument () { var s = document.createElement('style') - s.innerHTML = '.node2 { stroke:#eeeeee; }\n.node-square { stroke:#beb; }\n' + s.innerHTML = '.node2 { stroke:rgb(238, 238, 238); }\n.node-square { stroke:#beb; }\n' document.body.appendChild(s) } @@ -146,7 +146,7 @@ describe('when cloning CSS ', function () { var svg = generateSVG() addStyleToDocument() utils.cloneCssStyles(svg, {}) - expect(stylesToArray(svg)).toEqual(['.node { stroke: #eeeeee;}', '.node-square { stroke: #bbbbbb;}']) + expect(stylesToArray(svg)).toEqual(['.node { stroke: rgb(238, 238, 238);}', '.node-square { stroke: rgb(187, 187, 187);}']) }) it('should handle multiple stylesheets in document with classes in SVG', function () { @@ -154,7 +154,7 @@ describe('when cloning CSS ', function () { addStyleToDocument() addSecondStyleToDocument() utils.cloneCssStyles(svg, {}) - expect(stylesToArray(svg)).toEqual(['.node { stroke: #eeeeee;}', '.node-square { stroke: #bbbbbb;}', '.node-square { stroke: #bbeebb;}']) + expect(stylesToArray(svg)).toEqual(['.node { stroke: rgb(238, 238, 238);}', '.node-square { stroke: rgb(187, 187, 187);}', '.node-square { stroke: rgb(187, 238, 187);}']) }) it('should handle multiple stylesheets + ignore styles in other mermaid SVG', function () { @@ -163,14 +163,14 @@ describe('when cloning CSS ', function () { addSecondStyleToDocument() addMermaidSVGwithStyleToDocument() utils.cloneCssStyles(svg, {}) - expect(stylesToArray(svg)).toEqual(['.node { stroke: #eeeeee;}', '.node-square { stroke: #bbbbbb;}', '.node-square { stroke: #bbeebb;}']) + expect(stylesToArray(svg)).toEqual(['.node { stroke: rgb(238, 238, 238);}', '.node-square { stroke: rgb(187, 187, 187);}', '.node-square { stroke: rgb(187, 238, 187);}']) }) it('should handle a default class together with stylesheet in document with classes in SVG', function () { var svg = generateSVG() addStyleToDocument() utils.cloneCssStyles(svg, { 'default': { 'styles': ['stroke:#ffffff', 'stroke-width:1.5px'] } }) - expect(stylesToArray(svg)).toEqual(['#mermaid-01 .node>rect { stroke:#ffffff; stroke-width:1.5px; }', '.node { stroke: #eeeeee;}', '.node-square { stroke: #bbbbbb;}']) + expect(stylesToArray(svg)).toEqual(['#mermaid-01 .node>rect { stroke:#ffffff; stroke-width:1.5px; }', '.node { stroke: rgb(238, 238, 238);}', '.node-square { stroke: rgb(187, 187, 187);}']) }) it('should handle a default class together with stylesheet in document and classDefs', function () { @@ -178,13 +178,13 @@ describe('when cloning CSS ', function () { addStyleToDocument() utils.cloneCssStyles(svg, { 'default': { 'styles': ['stroke:#ffffff', 'stroke-width:1.5px'] }, - 'node-square': { 'styles': ['fill:#eeeeee', 'stroke:#aaaaaa'] }, + 'node-square': { 'styles': ['fill:rgb(238, 238, 238)', 'stroke:#aaaaaa'] }, 'node-circle': { 'styles': ['fill:#444444', 'stroke:#111111'] } }) expect(stylesToArray(svg)).toEqual(['#mermaid-01 .node>rect { stroke:#ffffff; stroke-width:1.5px; }', - '.node { stroke: #eeeeee;}', - '.node-square { stroke: #bbbbbb;}', - '#mermaid-01 .node-square>rect, .node-square>polygon, .node-square>circle, .node-square>ellipse { fill:#eeeeee; stroke:#aaaaaa; }', + '.node { stroke: rgb(238, 238, 238);}', + '.node-square { stroke: rgb(187, 187, 187);}', + '#mermaid-01 .node-square>rect, .node-square>polygon, .node-square>circle, .node-square>ellipse { fill:rgb(238, 238, 238); stroke:#aaaaaa; }', '#mermaid-01 .node-circle>rect, .node-circle>polygon, .node-circle>circle, .node-circle>ellipse { fill:#444444; stroke:#111111; }' ]) }) diff --git a/todo.md b/todo.md index 358a48d79..3a0c65ffd 100644 --- a/todo.md +++ b/todo.md @@ -12,3 +12,5 @@ - d3 v3 doesn't support 'use strict' - babel-plugin-transform-remove-strict-mode - need to remove it after upgrading to d3 v4 +- use headless chrome provided by karma-chrome-launcher +- https://github.com/karma-runner/karma-chrome-launcher diff --git a/yarn.lock b/yarn.lock index d8d15cc5c..93c531950 100644 --- a/yarn.lock +++ b/yarn.lock @@ -116,8 +116,8 @@ ajv-keywords@^1.0.0, ajv-keywords@^1.1.1: resolved "https://registry.yarnpkg.com/ajv-keywords/-/ajv-keywords-1.5.1.tgz#314dd0a4b3368fad3dfcdc54ede6171b886daf3c" ajv@^4.7.0, ajv@^4.9.1: - version "4.11.6" - resolved "https://registry.yarnpkg.com/ajv/-/ajv-4.11.6.tgz#947e93049790942b2a2d60a8289b28924d39f987" + version "4.11.7" + resolved "https://registry.yarnpkg.com/ajv/-/ajv-4.11.7.tgz#8655a5d86d0824985cc471a1d913fb6729a0ec48" dependencies: co "^4.6.0" json-stable-stringify "^1.0.1" @@ -244,8 +244,8 @@ arr-diff@^2.0.0: arr-flatten "^1.0.1" arr-flatten@^1.0.1: - version "1.0.2" - resolved "https://registry.yarnpkg.com/arr-flatten/-/arr-flatten-1.0.2.tgz#1ec1e63439c54f67d6f72bb4299c3d4f73b2d996" + version "1.0.3" + resolved "https://registry.yarnpkg.com/arr-flatten/-/arr-flatten-1.0.3.tgz#a274ed85ac08849b6bd7847c4580745dc51adfb1" arr-union@^2.0.1: version "2.1.0" @@ -3356,6 +3356,12 @@ front-matter@^2.0.0, front-matter@^2.1.2: dependencies: js-yaml "^3.4.6" +fs-access@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/fs-access/-/fs-access-1.0.1.tgz#d6a87f262271cefebec30c553407fb995da8777a" + dependencies: + null-check "^1.0.0" + fs-exists-sync@^0.1.0: version "0.1.0" resolved "https://registry.yarnpkg.com/fs-exists-sync/-/fs-exists-sync-0.1.0.tgz#982d6893af918e72d08dec9e8673ff2b5a8d6add" @@ -4979,17 +4985,17 @@ karma-browserify@^5.1.1: minimatch "^3.0.0" os-shim "^0.1.3" +karma-chrome-launcher@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/karma-chrome-launcher/-/karma-chrome-launcher-2.0.0.tgz#c2790c5a32b15577d0fff5a4d5a2703b3b439c25" + dependencies: + fs-access "^1.0.0" + which "^1.2.1" + karma-jasmine@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/karma-jasmine/-/karma-jasmine-1.1.0.tgz#22e4c06bf9a182e5294d1f705e3733811b810acf" -karma-phantomjs-launcher@^1.0.4: - version "1.0.4" - resolved "https://registry.yarnpkg.com/karma-phantomjs-launcher/-/karma-phantomjs-launcher-1.0.4.tgz#d23ca34801bda9863ad318e3bb4bd4062b13acd2" - dependencies: - lodash "^4.0.1" - phantomjs-prebuilt "^2.1.7" - karma@^1.6.0: version "1.6.0" resolved "https://registry.yarnpkg.com/karma/-/karma-1.6.0.tgz#0e871d4527d5eac56c41d181f03c5c0a7e6dbf3e" @@ -5539,7 +5545,7 @@ lodash@^3.10.0, lodash@^3.10.1, lodash@^3.3.1, lodash@^3.7.0, lodash@^3.8.0: version "3.10.1" resolved "https://registry.yarnpkg.com/lodash/-/lodash-3.10.1.tgz#5bf45e8e49ba4189e17d482789dfd15bd140b7b6" -lodash@^4.0.0, lodash@^4.0.1, lodash@^4.11.1, lodash@^4.12.0, lodash@^4.13.1, lodash@^4.14.0, lodash@^4.15.0, lodash@^4.17.4, lodash@^4.2.0, lodash@^4.3.0, lodash@^4.5, lodash@^4.5.0: +lodash@^4.0.0, lodash@^4.11.1, lodash@^4.12.0, lodash@^4.13.1, lodash@^4.14.0, lodash@^4.15.0, lodash@^4.17.4, lodash@^4.2.0, lodash@^4.3.0, lodash@^4.5, lodash@^4.5.0: version "4.17.4" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae" @@ -6068,9 +6074,9 @@ npm-cache-filename@~1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/npm-cache-filename/-/npm-cache-filename-1.0.2.tgz#ded306c5b0bfc870a9e9faf823bc5f283e05ae11" -npm-check-updates@^2.10.5: - version "2.10.5" - resolved "https://registry.yarnpkg.com/npm-check-updates/-/npm-check-updates-2.10.5.tgz#2d047e3a24d676e0c99cf7221361088dcc247a6a" +npm-check-updates@^2.11.0: + version "2.11.0" + resolved "https://registry.yarnpkg.com/npm-check-updates/-/npm-check-updates-2.11.0.tgz#6073a2c022eaf27352e2a8b08de931776207b818" dependencies: bluebird "^3.4.3" chalk "^1.1.3" @@ -6233,6 +6239,10 @@ npmlog@^4.0.2, npmlog@~4.0.0: gauge "~2.7.1" set-blocking "~2.0.0" +null-check@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/null-check/-/null-check-1.0.0.tgz#977dffd7176012b9ec30d2a39db5cf72a0439edd" + number-is-nan@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/number-is-nan/-/number-is-nan-1.0.1.tgz#097b602b53422a522c1afb8790318336941a011d" @@ -6637,7 +6647,7 @@ pff@~1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/pff/-/pff-1.0.0.tgz#ea5f09ee6571cae292a78fc280905a3865668e78" -phantomjs-prebuilt@^2.1.3, phantomjs-prebuilt@^2.1.7: +phantomjs-prebuilt@^2.1.3: version "2.1.14" resolved "https://registry.yarnpkg.com/phantomjs-prebuilt/-/phantomjs-prebuilt-2.1.14.tgz#d53d311fcfb7d1d08ddb24014558f1188c516da0" dependencies: @@ -7776,8 +7786,8 @@ snyk-try-require@^1.1.1, snyk-try-require@^1.2.0: then-fs "^2.0.0" snyk@^1.25.1: - version "1.28.1" - resolved "https://registry.yarnpkg.com/snyk/-/snyk-1.28.1.tgz#ae0faed0fcee7d5dbc0fa8a7a8c9ebacb03b6151" + version "1.29.0" + resolved "https://registry.yarnpkg.com/snyk/-/snyk-1.29.0.tgz#20be4eaddc9641ca004fb24368dc33d6f82d17dc" dependencies: abbrev "^1.0.7" ansi-escapes "^1.3.0" @@ -8860,7 +8870,7 @@ which-module@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/which-module/-/which-module-1.0.0.tgz#bba63ca861948994ff307736089e3b96026c2a4f" -which@1, which@^1.1.1, which@^1.2.12, which@^1.2.14, which@~1.2.10, which@~1.2.11, which@~1.2.2: +which@1, which@^1.1.1, which@^1.2.1, which@^1.2.12, which@^1.2.14, which@~1.2.10, which@~1.2.11, which@~1.2.2: version "1.2.14" resolved "https://registry.yarnpkg.com/which/-/which-1.2.14.tgz#9a87c4378f03e827cecaf1acdf56c736c01c14e5" dependencies: