From 1ca663d337ce22f572b45d1aea541ab6a2a5d597 Mon Sep 17 00:00:00 2001 From: chan <22977219@qq.com> Date: Wed, 13 Mar 2019 23:52:08 +0800 Subject: [PATCH 1/4] feat: test success --- .travis.yml | 20 +++++++++++++++ karma.conf.js | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++ test/test.js | 11 +++++++- 3 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 .travis.yml create mode 100644 karma.conf.js diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..f3be6022 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,20 @@ +language: node_js +# nodejs版本 +node_js: + - '8' + +# Travis-CI Caching +cache: + directories: + - node_modules + + +# S: Build Lifecycle +install: + - npm install + +before_script: + +# 无其他依赖项所以执行npm run build 构建就行了 +script: + - npm test \ No newline at end of file diff --git a/karma.conf.js b/karma.conf.js new file mode 100644 index 00000000..0e4edad7 --- /dev/null +++ b/karma.conf.js @@ -0,0 +1,71 @@ +// Karma configuration +// Generated on Wed Mar 13 2019 21:58:35 GMT+0800 (CST) + +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 + }) +} diff --git a/test/test.js b/test/test.js index 7c01938c..26deccd0 100644 --- a/test/test.js +++ b/test/test.js @@ -30,7 +30,16 @@ describe('jQuery', function () { }) }) - it('should able to request https://raw.githubusercontent.com/FE-star/exercise1/master/test/test.js', function (done) { + 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,并验证是否拿到文件 + jQuery.ajax({ + url: 'https://raw.githubusercontent.com/FE-star/exercise1/master/test/test.js', + success: function(res){ + res.should.be.String() + done() + },fail: function(error){ + return done(err); + } + }) }) }) \ No newline at end of file From 694467f0f76d19b1e20774db350f518a8fa82b95 Mon Sep 17 00:00:00 2001 From: chan <22977219@qq.com> Date: Wed, 13 Mar 2019 23:55:51 +0800 Subject: [PATCH 2/4] fix: Cannot start Chrome --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index f3be6022..ade4e938 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,6 +12,9 @@ cache: # S: Build Lifecycle install: - npm install + - export CHROME_BIN=chromium-browser + - export DISPLAY=:99.0 + - sh -e /etc/init.d/xvfb start before_script: From b6e5990c73add34589efd47785a889bd0e11380e Mon Sep 17 00:00:00 2001 From: chan <22977219@qq.com> Date: Thu, 14 Mar 2019 00:01:13 +0800 Subject: [PATCH 3/4] feat: after succes exit --- karma.conf.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/karma.conf.js b/karma.conf.js index 0e4edad7..bdf43914 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -62,7 +62,7 @@ module.exports = function(config) { // Continuous Integration mode // if true, Karma captures browsers, runs the tests and exits - singleRun: false, + singleRun: true, // Concurrency level // how many browser should be started simultaneous From e8d02cf1ab4dfdef4ff0de64f0939bbfdd3c0a97 Mon Sep 17 00:00:00 2001 From: chan <22977219@qq.com> Date: Sun, 17 Mar 2019 09:30:37 +0800 Subject: [PATCH 4/4] feat: cdn change to modules --- karma.conf.js | 2 +- package.json | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/karma.conf.js b/karma.conf.js index bdf43914..5c171a61 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -15,7 +15,7 @@ module.exports = function(config) { // list of files / patterns to load in the browser files: [ - 'https://cdn.bootcss.com/jquery/2.2.4/jquery.js', + 'node_modules/jquery/dist/jquery.js', 'node_modules/should/should.js', 'test/**.js' ], diff --git a/package.json b/package.json index 71c96b0c..0bec0826 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ }, "homepage": "https://github.com/FE-star/exercise3#readme", "devDependencies": { + "jquery": "^3.3.1", "karma": "^1.7.0", "karma-chrome-launcher": "^2.2.0", "karma-mocha": "^1.3.0",