From 6c2c29cada2c75a164cd312ab30f7d31e64ae304 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=89=8D=E7=AB=AF=E5=B0=8F=E6=AD=A6?=
Date: Fri, 1 Sep 2017 20:28:59 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=B5=8F=E8=A7=88=E5=99=A8?=
=?UTF-8?q?=E7=AB=AF=E6=B5=8B=E8=AF=95=20(#55)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* 添加浏览器测试
* 添加静态文件引用, 解决测试时404
* 关闭ie8测试
* 恢复代码
* 添加sauce配置
* 删除sauce配置
* 添加系统配置
* 测试链接sauce
* 删除token
* 添加编译状态图标
* 添加 layui.js 测试用例
---
.travis.yml | 12 +--
README.md | 9 ++
karma.conf.base.js | 11 +-
karma.conf.sauce.js | 14 +--
package.json | 17 ++-
test/{ => lay/modules}/laytpl.js | 5 +-
test/layui.js | 174 +++++++++++++++++++++++++++++++
7 files changed, 216 insertions(+), 26 deletions(-)
rename test/{ => lay/modules}/laytpl.js (97%)
create mode 100644 test/layui.js
diff --git a/.travis.yml b/.travis.yml
index 249cc3e..af00f55 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,17 +1,15 @@
language: node_js
-dist: trusty
-addons:
- chrome: stable
node_js:
- node
-#addons:
-# sauce_connect: true
+dist: trusty
+addons:
+ sauce_connect: true
sudo: false
cache:
directories:
- node_modules
script:
- npm run test:cov
- #- npm run test:sauce
-after_script:
+ - npm run test:sauce
+after_script:
- npm install coveralls && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage
\ No newline at end of file
diff --git a/README.md b/README.md
index 1d32f8e..820faad 100644
--- a/README.md
+++ b/README.md
@@ -7,6 +7,15 @@
经典模块化前端UI框架
+
+
+
+
+
+
+
+
+
---
Layui 是一款采用自身模块规范编写的情怀型前端UI框架,遵循原生HTML/CSS/JS的书写与组织形式,门槛极低,拿来即用。其外在极简,却又不失饱满的内在,体积轻盈,组件丰盈,从核心代码到API的每一处细节都经过精心雕琢,非常适合界面的快速开发。Layui 首个版本发布于2016年金秋,她区别于那些基于MVVM底层的UI框架,却并非逆道而行,而是信奉返璞归真之道。准确地说,她更多是为服务端程序员量身定做,你无需涉足各种前端工具的复杂配置,只需面对浏览器本身,让一切你所需要的元素与交互,从这里信手拈来。
diff --git a/karma.conf.base.js b/karma.conf.base.js
index 42e4d9a..bf3ebf1 100644
--- a/karma.conf.base.js
+++ b/karma.conf.base.js
@@ -57,7 +57,16 @@ module.exports = function (config) {
// list of files / patterns to load in the browser
- files: sourceFileMap.concat('test/**/*.js'),
+ files: sourceFileMap.concat('test/**/*.js').concat({
+ pattern: 'src/css/**/*',
+ included: false
+ }, {
+ pattern: 'src/font/**/*',
+ included: false
+ }, {
+ pattern: 'src/images/**/*',
+ included: false
+ }),
// list of files to exclude
diff --git a/karma.conf.sauce.js b/karma.conf.sauce.js
index 4cd9569..10aed8e 100644
--- a/karma.conf.sauce.js
+++ b/karma.conf.sauce.js
@@ -35,11 +35,11 @@ var customLaunchers = {
browserName: 'chrome'
},
- sl_ie_8: {
- base: 'SauceLabs',
- browserName: 'internet explorer',
- version: '8'
- },
+ // sl_ie_8: {
+ // base: 'SauceLabs',
+ // browserName: 'internet explorer',
+ // version: '8'
+ // },
sl_ie_9: {
base: 'SauceLabs',
browserName: 'internet explorer',
@@ -84,7 +84,7 @@ module.exports = function (config) {
var options = Object.assign(base(config), {
reporters: ['mocha', 'saucelabs'],
sauceLabs: {
- 'testName': 'layui test case',
+ 'testName': 'layui',
'recordVideo': false,
'recordScreenshots': false,
'startConnect': false,
@@ -92,7 +92,7 @@ module.exports = function (config) {
'no-ssl-bump-domains': 'all'
},
'public': 'public',
- 'build': process.env.CIRCLE_BUILD_NUM || process.env.SAUCE_BUILD_ID || 'build-' + Date.now(),
+ 'build': 'layui-build-' + process.env.TRAVIS_BUILD_NUMBER,
'tunnelIdentifier': process.env.TRAVIS_JOB_NUMBER
},
customLaunchers: customLaunchers,
diff --git a/package.json b/package.json
index 28267bf..aaa5cae 100644
--- a/package.json
+++ b/package.json
@@ -18,28 +18,28 @@
"author": "贤心",
"homepage": "http://www.layui.com",
"devDependencies": {
+ "chai": "^4.1.1",
+ "del": "^2.2.2",
"gulp": "^3.9.1",
- "gulp-uglify": "^1.5.4",
"gulp-concat": "^2.6.0 ",
"gulp-header": "^1.8.8",
"gulp-if": "^2.0.1",
"gulp-minify-css": "^1.2.4",
"gulp-rename": "^1.2.2",
- "del": "^2.2.2",
+ "gulp-uglify": "^1.5.4",
"gulp-zip": "^4.0.0",
- "minimist": "^1.2.0",
- "chai": "^3.5.0",
"karma": "^1.5.0",
"karma-chai": "^0.1.0",
"karma-chai-sinon": "^0.1.5",
"karma-coverage": "^1.1.1",
"karma-mocha": "^1.3.0",
- "karma-sauce-launcher": "^1.1.0",
"karma-mocha-reporter": "^2.2.3",
"karma-phantomjs-launcher": "^1.0.4",
+ "karma-sauce-launcher": "^1.1.0",
+ "minimist": "^1.2.0",
"mocha": "^3.2.0",
- "sinon": "^2.0.0",
- "sinon-chai": "^2.8.0"
+ "sinon": "^3.2.1",
+ "sinon-chai": "^2.13.0"
},
"bugs": {
"url": "https://github.com/sentsin/layui/issues"
@@ -48,8 +48,7 @@
"doc": "doc",
"test": "test"
},
- "dependencies": {
- },
+ "dependencies": {},
"keywords": [
"layui",
"ui"
diff --git a/test/laytpl.js b/test/lay/modules/laytpl.js
similarity index 97%
rename from test/laytpl.js
rename to test/lay/modules/laytpl.js
index cb047a6..1533e90 100644
--- a/test/laytpl.js
+++ b/test/lay/modules/laytpl.js
@@ -213,7 +213,8 @@ describe('laytpl', function () {
it('error var', function () {
var result = laytpl('{{ data.xxoo }}').render({});
- expect(result).to.have.string('Can\'t find variable: data');
+ expect(result).to.have.string('data');
+ expect(result).to.have.string('ReferenceError');
expect(result).to.have.string('Laytpl Error');
});
@@ -221,7 +222,7 @@ describe('laytpl', function () {
var result = laytpl('{{# var xxoo = ; }}').render({});
expect(result).to.have.string('Laytpl Error');
- expect(result).to.have.string('Unexpected token \';\'');
+ expect(result).to.have.string('SyntaxError');
});
});
});
diff --git a/test/layui.js b/test/layui.js
new file mode 100644
index 0000000..0a26190
--- /dev/null
+++ b/test/layui.js
@@ -0,0 +1,174 @@
+/**
+ * @file layui - 测试
+ * @author xuexb
+ */
+
+/* global layui */
+/* eslint-disable max-nested-callbacks */
+
+var $ = layui.$;
+
+describe('layui', function () {
+ it('version', function () {
+ expect(layui.v).to.be.a('string');
+ expect(layui.v).to.not.be.empty;
+ });
+
+ it('layui.config', function () {
+ expect(layui.config()).to.deep.equal(layui);
+ expect(layui.config({
+ testName: 'layui'
+ })).to.deep.equal(layui);
+ expect(layui.cache.testName).to.equal('layui');
+ });
+
+ describe('layui.router', function () {
+ var defaultData = {
+ path: [],
+ search: {},
+ hash: ''
+ };
+
+ it('default params', function () {
+ expect(layui.router).to.be.a('function');
+ expect(layui.router()).to.be.a('object').and.deep.equal(defaultData);
+ });
+
+ it('error router', function () {
+ [
+ null,
+ '',
+ '#123',
+ '123',
+ '##'
+ ].forEach(function (key) {
+ expect(layui.router(key)).to.deep.equal(defaultData);
+ });
+ });
+
+ it('router querystring', function () {
+ expect(layui.router('#/a=1/b=2/c=')).to.deep.equal($.extend({}, defaultData, {
+ search: {
+ a: '1',
+ b: '2',
+ c: ''
+ }
+ }));
+
+ expect(layui.router('#/a=测试/b=2').search).to.deep.equal({
+ a: '测试',
+ b: '2'
+ });
+
+ // todo
+ // urlencode
+ // urldecode
+ });
+
+ it('router hash', function () {
+ expect(layui.router('#/name#layui')).to.deep.equal($.extend({}, defaultData, {
+ hash: '#layui',
+ path: ['name']
+ }));
+ expect(layui.router('#/name#layui').hash).to.equal('#layui');
+ expect(layui.router('#/name#layui=1').hash).to.equal('#layui=1');
+ expect(layui.router('#/name##layui').hash).to.equal('##layui');
+ expect(layui.router('#/name=1#layui').hash).to.equal('#layui');
+ expect(layui.router('#/name=1/b=2#layui').hash).to.equal('#layui');
+ });
+
+ it('router path', function () {
+ expect(layui.router('#/a/b/c=2#hash')).to.deep.equal({
+ path: ['a', 'b'],
+ search: {
+ c: '2'
+ },
+ hash: '#hash'
+ });
+ });
+ });
+
+ describe('layui.each', function () {
+ it('check params', function () {
+ expect(layui.each).to.be.a('function');
+ expect(layui.each()).to.deep.equal(layui);
+ expect(layui.each({})).to.deep.equal(layui);
+ expect(layui.each([])).to.deep.equal(layui);
+ expect(layui.each({}, function () {})).to.deep.equal(layui);
+ expect(layui.each([], function () {})).to.deep.equal(layui);
+ });
+
+ it('null params', function (done) {
+ var index = 0;
+ layui.each(null, function (index) {
+ index += 1;
+ });
+ setTimeout(function () {
+ expect(index).to.equal(0);
+ done();
+ });
+ });
+
+ it('object each', function (done) {
+ layui.each({
+ name: 'layui'
+ }, function (key, value) {
+ expect(this + '').to.deep.equal(value).and.equal('layui');
+ expect(key).to.equal('name');
+ done();
+ });
+ });
+
+ it('array each', function (done) {
+ layui.each([
+ 'layui'
+ ], function (index, value) {
+ expect(this + '').to.deep.equal(value).and.equal('layui')
+ expect(index).to.equal(0);
+ done();
+ });
+ });
+
+ it('break array each', function () {
+ var arr = new Array(100).join(',').split(',');
+ var flag = -1;
+ layui.each(arr, function (index) {
+ flag = index;
+ if (index > 5) {
+ return true;
+ }
+ });
+ expect(flag).to.equal(6);
+
+ flag = -1;
+ layui.each(arr, function (index) {
+ flag = index;
+ if (index > 5) {
+ return false;
+ }
+ });
+ expect(flag).to.equal(99);
+ });
+
+ it('break object each', function () {
+ var obj = {
+ name: 'layui',
+ version: '2.x'
+ };
+ var flag = null;
+ layui.each(obj, function (key) {
+ flag = key;
+ return true;
+ });
+ expect(flag).to.equal('name');
+
+ flag = null;
+ layui.each(obj, function (key) {
+ flag = key;
+ return false;
+ });
+ expect(flag).to.equal('version');
+ });
+ });
+});
+/* eslint-enable max-nested-callbacks */