Skip to content

Commit

Permalink
use chrome to run tests (ElemeFE#7521)
Browse files Browse the repository at this point in the history
* use chrome to run tests

* fix karma config lint

* remove phantomjs
  • Loading branch information
Leopoldthecoder authored Oct 17, 2017
1 parent 7ceecce commit 8586891
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 136 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ sudo: false
language: node_js
node_js: stable
before_install:
- export CHROME_BIN=chromium-browser
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
- export TRAVIS_COMMIT_MSG="[deploy] $(git log --format='%h - %B' --no-merges -n 1)"
- export TRAVIS_COMMIT_USER="$(git log --no-merges -n 1 --format=%an)"
- export TRAVIS_COMMIT_EMAIL="$(git log --no-merges -n 1 --format=%ae)"
Expand Down
2 changes: 1 addition & 1 deletion build/bin/version.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var fs = require('fs');
var path = require('path');
var version = process.env.VERSION || require('../../package.json').version;
var content = { '1.0.9': '1.0', '1.1.6': '1.1', '1.2.9': '1.2', '1.3.7': '1.3', '1.4.6': '1.4' };
var content = { '1.0.9': '1.0', '1.1.6': '1.1', '1.2.9': '1.2', '1.3.7': '1.3', '1.4.7': '1.4' };
if (!content[version]) content[version] = '2.0';
fs.writeFileSync(path.resolve(__dirname, '../../examples/versions.json'), JSON.stringify(content));
2 changes: 1 addition & 1 deletion examples/versions.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"1.0.9":"1.0","1.1.6":"1.1","1.2.9":"1.2","1.3.7":"1.3","1.4.7":"1.4","2.0.0-alpha.3":"2.0"}
{"1.0.9":"1.0","1.1.6":"1.1","1.2.9":"1.2","1.3.7":"1.3","1.4.6":"1.4","2.0.0-alpha.3":"2.0"}
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@
"json-loader": "^0.5.7",
"json-templater": "^1.0.4",
"karma": "^1.3.0",
"karma-chrome-launcher": "^2.2.0",
"karma-coverage": "^1.1.1",
"karma-mocha": "^1.2.0",
"karma-phantomjs-launcher": "^1.0.2",
"karma-sinon-chai": "^1.2.4",
"karma-sourcemap-loader": "^0.3.7",
"karma-spec-reporter": "0.0.26",
Expand All @@ -111,7 +111,6 @@
"markdown-it-container": "^2.0.0",
"mocha": "^3.1.1",
"node-sass": "^4.5.3",
"phantomjs-prebuilt": "^2.1.13",
"postcss": "^5.1.2",
"postcss-loader": "0.11.1",
"postcss-salad": "^1.0.8",
Expand Down
18 changes: 15 additions & 3 deletions test/unit/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@ var webpackConfig = require('../../build/cooking.test');
// delete webpackConfig.entry;

module.exports = function(config) {
config.set({
var configuration = {
// to run in additional browsers:
// 1. install corresponding karma launcher
// http://karma-runner.github.io/0.13/config/browsers.html
// 2. add it to the `browsers` array below.
browsers: ['PhantomJS'],
browsers: ['Chrome'],
customLaunchers: {
Chrome_travis_ci: {
base: 'Chrome',
flags: ['--no-sandbox']
}
},
frameworks: ['mocha', 'sinon-chai'],
reporters: ['spec', 'coverage'],
files: ['./index.js'],
Expand All @@ -32,5 +38,11 @@ module.exports = function(config) {
timeout: 4000
}
}
});
};

if (process.env.TRAVIS) {
configuration.browsers = ['Chrome_travis_ci'];
}

config.set(configuration);
};
51 changes: 25 additions & 26 deletions test/unit/specs/upload.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,26 +85,22 @@ describe('Upload', () => {
props: {
action: '/upload',
onSuccess(res, file, fileList) {
console.log('onSuccess', res);
if (handlers.onSuccess) {
handlers.onSuccess(res, file, fileList);
}
},
onError(err, file, fileList) {
console.log('onError', err, file, fileList);
if (handlers.onError) {
handlers.onError(err, file, fileList);
}
},
onPreview(file) {
console.log('onPreview', file);
if (handlers.onPreview) {
handlers.onPreview(file);
}
},
limit: 2,
onExceed(files, fileList) {
console.log('onExceed', files, fileList);
if (handlers.onExceed) {
handlers.onExceed(files, fileList);
}
Expand All @@ -130,10 +126,11 @@ describe('Upload', () => {
});

it('upload success', done => {
const files = [{
name: 'success.png',
type: 'xml'
}];
const file = new Blob([JSON.stringify({}, null, 2)], {
type: 'application/json'
});
file.name = 'success.png';
const files = [file];

handlers.onSuccess = (res, file, fileList) => {
expect(file.name).to.equal('success.png');
Expand All @@ -150,10 +147,11 @@ describe('Upload', () => {
});

it('upload fail', done => {
const files = [{
name: 'fail.png',
type: 'xml'
}];
const file = new Blob([JSON.stringify({}, null, 2)], {
type: 'application/json'
});
file.name = 'fail.png';
const files = [file];

handlers.onError = (err, file, fileList) => {
expect(err instanceof Error).to.equal(true);
Expand All @@ -168,10 +166,11 @@ describe('Upload', () => {
}, 100);
});
it('preview file', done => {
const files = [{
name: 'success.png',
type: 'xml'
}];
const file = new Blob([JSON.stringify({}, null, 2)], {
type: 'application/json'
});
file.name = 'success.png';
const files = [file];

handlers.onPreview = (file) => {
expect(file.response).to.equal('success.png');
Expand All @@ -191,10 +190,11 @@ describe('Upload', () => {
}, 100);
});
it('file remove', done => {
const files = [{
name: 'success.png',
type: 'xml'
}];
const file = new Blob([JSON.stringify({}, null, 2)], {
type: 'application/json'
});
file.name = 'success.png';
const files = [file];

handlers.onSuccess = (res, file, fileList) => {
uploader.$el.querySelector('.el-upload-list .el-icon-close').click();
Expand All @@ -211,10 +211,11 @@ describe('Upload', () => {
}, 100);
});
it('clear files', done => {
const files = [{
name: 'success.png',
type: 'xml'
}];
const file = new Blob([JSON.stringify({}, null, 2)], {
type: 'application/json'
});
file.name = 'success.png';
const files = [file];

handlers.onSuccess = (res, file, fileList) => {
uploader.clearFiles();
Expand Down Expand Up @@ -252,8 +253,6 @@ describe('Upload', () => {
});
};

console.log(uploader.$refs['upload-inner'].limit, uploader.$refs['upload-inner'].fileList, uploader.$refs['upload-inner'].onExceed);

uploader.$nextTick(_ => uploader.$refs['upload-inner'].handleChange({ target: { files }}));
});
});
Expand Down
Loading

0 comments on commit 8586891

Please sign in to comment.