You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by da...@apache.org on 2017/07/03 03:44:51 UTC
[02/13] incubator-weex git commit: * [html5] modify websocket unit
test code.
* [html5] modify websocket unit test code.
Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/7bfa9438
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/7bfa9438
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/7bfa9438
Branch: refs/heads/0.15-dev
Commit: 7bfa9438f7fb0d967ffb9871151565d6a0ecfc3b
Parents: d804e1f
Author: erha19 <fa...@gmail.com>
Authored: Tue Jun 27 16:18:24 2017 +0800
Committer: erha19 <fa...@gmail.com>
Committed: Tue Jun 27 16:18:24 2017 +0800
----------------------------------------------------------------------
html5/test/render/vue/modules/websocket.js | 124 ++++++++++++++++++++++--
1 file changed, 114 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/7bfa9438/html5/test/render/vue/modules/websocket.js
----------------------------------------------------------------------
diff --git a/html5/test/render/vue/modules/websocket.js b/html5/test/render/vue/modules/websocket.js
index f3534ef..c82fde8 100644
--- a/html5/test/render/vue/modules/websocket.js
+++ b/html5/test/render/vue/modules/websocket.js
@@ -1,11 +1,115 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
import websocket from '../../../../render/vue/modules/websocket/websocket'
-describe('webSocket module', function () {
- afterEach(function (done) {
- // Cleanup
- websocket.close()
- done()
- })
- it('should have connection lifecycle constants defined on the instance', () => {
- expect(websocket.WebSocket('wss://echo.websocket.org').CONNECTING).to.be.equal(0)
- })
-})
+const TestUrl = 'ws://echo.websocket.org';
+/** @test {webSocket module} */
+describe('webSocket module', function() {
+ after(function(done) {
+ const ws = new WebSocket(TestUrl);
+ ws.addEventListener('open', function() {
+ ws.send('shutdown');
+ done();
+ });
+ });
+ describe('extends Standard WebSocket API', function() {
+ context('should inherit', function() {
+ let ws = websocket.WebSocket(TestUrl);
+ it('methods', function() {
+ expect(websocket.close, 'to be defined');
+ expect(websocket.send, 'to be defined');
+ });
+ it('attributes', function() {
+ expect(websocket.onerror, 'to be defined');
+ expect(websocket.onmessage, 'to be defined');
+ expect(websocket.onopen, 'to be defined');
+ expect(websocket.onclose, 'to be defined');
+ expect(ws.binaryType, 'to be defined');
+ expect(ws.bufferedAmount, 'to be defined');
+ expect(ws.extensions, 'to be defined');
+ expect(ws.protocol, 'to be defined');
+ expect(ws.readyState, 'to be defined');
+ expect(ws.url, 'to be defined');
+ });
+
+ it('constants', function() {
+ expect(websocket.INSTANCE, 'to be defined');
+ });
+ });
+
+ context('should forward native events', function() {
+ let ws;
+
+ beforeEach(function() {
+ ws = websocket.WebSocket(TestUrl);
+ });
+
+ afterEach(function() {
+ websocket.close();
+ });
+
+ it('open', function(done) {
+ websocket.onopen = function(){
+ done();
+ }
+ });
+ it('close', function(done) {
+ let closed = false;
+ ws.onclose = function(){
+ if (!closed) {
+ done();
+ closed = true;
+ }
+ }
+ websocket.onopen = function(){
+ websocket.close()
+ }
+ });
+
+ it('message', function(done) {
+ const message = 'Test';
+ websocket.onmessage = function(e){
+ expect(e.data).to.be.equal(message);
+ done();
+ }
+ websocket.onopen = function(){
+ websocket.send(message);
+ }
+ });
+ });
+ describe('should ignore',function(){
+ it('protocol is undefined', function(done) {
+ let ws = websocket.WebSocket(TestUrl)
+ expect(websocket.INSTANCE).not.to.be.null;
+ done();
+ });
+
+ it('url is undefined', function(done) {
+ let ws = websocket.WebSocket('')
+ expect(websocket.INSTANCE).to.be.null;
+ done();
+ });
+
+ it('both url and protocol is defined', function(done) {
+ let ws = websocket.WebSocket(TestUrl,'ws')
+ expect(websocket.INSTANCE).not.to.be.null;
+ done();
+ });
+ })
+ });
+});
\ No newline at end of file