From 6b8a25e40f681c45b06256da966ad5b0d4ca3a3f Mon Sep 17 00:00:00 2001 From: Zeshi Zheng Date: Wed, 13 Mar 2019 19:34:14 -0400 Subject: [PATCH 1/6] karma --- .travis.yml | 5 +++++ test/test.js | 7 +++++++ 2 files changed, 12 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..f5da1e12 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,5 @@ +language: node_js +node_js: + - node +before_script: + - npm i \ No newline at end of file diff --git a/test/test.js b/test/test.js index 7c01938c..44c8d0f4 100644 --- a/test/test.js +++ b/test/test.js @@ -32,5 +32,12 @@ describe('jQuery', function () { it('should able to request https://raw.githubusercontent.com/FE-star/exercise1/master/test/test.js', function (done) { // 使用 jQuery.ajax 请求 https://raw.githubusercontent.com/FE-star/exercise1/master/test/test.js,并验证是否拿到文件 + window.jQuery.ajax({ + type: 'GET', + url: 'https://raw.githubusercontent.com/FE-star/exercise1/master/test/test.js', + success: function (msg) { + done(); + } + }) }) }) \ No newline at end of file From c53374efd482fa76f7f0a51d6be0cdba67f77245 Mon Sep 17 00:00:00 2001 From: Zeshi Zheng Date: Wed, 13 Mar 2019 19:34:49 -0400 Subject: [PATCH 2/6] karma config --- karma.conf.js | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 karma.conf.js diff --git a/karma.conf.js b/karma.conf.js new file mode 100644 index 00000000..e2c7bd78 --- /dev/null +++ b/karma.conf.js @@ -0,0 +1,71 @@ +// Karma configuration +// Generated on Wed Mar 13 2019 18:15:34 GMT-0400 (Eastern Daylight Time) + +module.exports = function(config) { + 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: ['mocha'], + + + // list of files / patterns to load in the browser + files: [ + 'https://cdn.bootcss.com/jquery/2.2.4/jquery.js', + 'node_modules/should/should.js', + 'test/**.js' + ], + + + // list of files to exclude + exclude: [ + ], + + + // 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: 'dots', 'progress' + // available reporters: https://npmjs.org/browse/keyword/karma-reporter + reporters: ['progress'], + + + // 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: ['Chrome'], + + + // Continuous Integration mode + // if true, Karma captures browsers, runs the tests and exits + singleRun: false, + + // Concurrency level + // how many browser should be started simultaneous + concurrency: Infinity + }) +} From 3c3547e3f538dee7722a4c19d531a07453673e4c Mon Sep 17 00:00:00 2001 From: Zeshi Zheng Date: Wed, 13 Mar 2019 19:36:37 -0400 Subject: [PATCH 3/6] trigger --- test/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test.js b/test/test.js index 44c8d0f4..d05915a2 100644 --- a/test/test.js +++ b/test/test.js @@ -35,7 +35,7 @@ describe('jQuery', function () { window.jQuery.ajax({ type: 'GET', url: 'https://raw.githubusercontent.com/FE-star/exercise1/master/test/test.js', - success: function (msg) { + success: function () { done(); } }) From f195bdb7979da89ed9f024d6aabf1eead2eeea80 Mon Sep 17 00:00:00 2001 From: Zeshi Zheng Date: Wed, 13 Mar 2019 19:42:12 -0400 Subject: [PATCH 4/6] addon chrome --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f5da1e12..19f7d09d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,4 +2,6 @@ language: node_js node_js: - node before_script: - - npm i \ No newline at end of file + - npm i +addons: + chrome: stable \ No newline at end of file From 6a3c34f4116f929a4f998c6dd6ff6e5f22febc39 Mon Sep 17 00:00:00 2001 From: Zeshi Zheng Date: Wed, 13 Mar 2019 20:05:54 -0400 Subject: [PATCH 5/6] set up chrome for CI --- .travis.yml | 4 +++ karma.conf.js | 97 +++++++++++++++++++++++++++++---------------------- 2 files changed, 59 insertions(+), 42 deletions(-) diff --git a/.travis.yml b/.travis.yml index 19f7d09d..ddd1104b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,10 @@ language: node_js node_js: - node before_script: + # set up chrome for travis karma test + - export CHROME_BIN=chromium-browser + - export DISPLAY=:99.0 + - sh -e /etc/init.d/xvfb start - npm i addons: chrome: stable \ No newline at end of file diff --git a/karma.conf.js b/karma.conf.js index e2c7bd78..a33f2353 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -2,70 +2,83 @@ // Generated on Wed Mar 13 2019 18:15:34 GMT-0400 (Eastern Daylight Time) module.exports = function(config) { - config.set({ + const conditionalConfig = { - // base path that will be used to resolve all patterns (eg. files, exclude) - basePath: '', + // 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: ['mocha'], + // frameworks to use + // available frameworks: https://npmjs.org/browse/keyword/karma-adapter + frameworks: ['mocha'], - // list of files / patterns to load in the browser - files: [ - 'https://cdn.bootcss.com/jquery/2.2.4/jquery.js', - 'node_modules/should/should.js', - 'test/**.js' - ], + // list of files / patterns to load in the browser + files: [ + 'https://cdn.bootcss.com/jquery/2.2.4/jquery.js', + 'node_modules/should/should.js', + 'test/**.js' + ], - // list of files to exclude - exclude: [ - ], + // list of files to exclude + exclude: [ + ], - // preprocess matching files before serving them to the browser - // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor - preprocessors: { - }, + // 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: 'dots', 'progress' - // available reporters: https://npmjs.org/browse/keyword/karma-reporter - reporters: ['progress'], + // test results reporter to use + // possible values: 'dots', 'progress' + // available reporters: https://npmjs.org/browse/keyword/karma-reporter + reporters: ['progress'], - // web server port - port: 9876, + // web server port + port: 9876, - // enable / disable colors in the output (reporters and logs) - colors: true, + // 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, + // 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, + // 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: ['Chrome'], + // start these browsers + // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher + browsers: ['Chrome'], + customLaunchers: { // special setup for travis karma test + Chrome_travis_ci: { + base: 'Chrome', + flags: ['--no-sandbox'] + } + }, + // Continuous Integration mode + // if true, Karma captures browsers, runs the tests and exits + singleRun: false, - // Continuous Integration mode - // if true, Karma captures browsers, runs the tests and exits - singleRun: false, + // Concurrency level + // how many browser should be started simultaneous + concurrency: Infinity + } - // Concurrency level - // how many browser should be started simultaneous - concurrency: Infinity - }) + // set up chrome for travis karma test + if (process.env.TRAVIS) { + conditionalConfig.browsers = ['Chrome_travis_ci']; + conditionalConfig.singleRun = true; // exit after a npm test, otherwise travis won't npm run github + } + + config.set(conditionalConfig); } From 5f1f97b6f22564066ddecb4eb3f7e8e40bae54cf Mon Sep 17 00:00:00 2001 From: Zeshi Zheng Date: Wed, 13 Mar 2019 20:16:07 -0400 Subject: [PATCH 6/6] set up chrome for CI --- .travis.yml | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index ddd1104b..0c068cb8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,9 +3,6 @@ node_js: - node before_script: # set up chrome for travis karma test - - export CHROME_BIN=chromium-browser - - export DISPLAY=:99.0 - - sh -e /etc/init.d/xvfb start - - npm i -addons: - chrome: stable \ No newline at end of file + - "export DISPLAY=:99.0" + - "sh -e /etc/init.d/xvfb start" + - sleep 3 # give xvfb some time to start