Skip to content

Upgrade superagent #224

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 19, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test(fix): fix hanhing mocha tests
Fix message actions and ReactNative tests which lead mocha to freeze.
  • Loading branch information
parfeon committed Nov 19, 2021
commit e3627b86f50794ab0521de9bbeb34f77f8bb9f85
9 changes: 9 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ addons:

stages:
- name: "test"
if: |
type != pull_request
- name: "test pr branch"
if: |
type == pull_request

jobs:
include:
Expand All @@ -28,3 +33,7 @@ jobs:
- name: 'NodeJS 12'
node_js: '12'
script: gulp test
- stage: "test pr branch"
name: 'NodeJS 12'
node_js: '12'
script: gulp test
2 changes: 1 addition & 1 deletion test/dist/objectsv2.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,4 @@ describe('Objects V2 system tests', () => {
expect(result.status).to.equal(200);
expect(result.data).to.be.null;
});
});
});
64 changes: 34 additions & 30 deletions test/dist/react-native.test.js
Original file line number Diff line number Diff line change
@@ -1,57 +1,59 @@
import fetch from 'node-fetch';
import { expect } from 'chai';
import PubNub from '../../src/react_native';
import nock from "nock";

global.fetch = fetch;

let pubnub;

let listener = null;

let channelSuffix = new Date().getTime() + (Math.random());

let myChannel1 = `mychannel1${channelSuffix}`;
let myChannel2 = `mychannel2${channelSuffix}`;
// let myChanneGroup1 = `myChannelGroup1${channelSuffix}`;

describe('#distribution test (rkt-native)', function () {
after(function () {
pubnub.destroy();
});

before(function () {
beforeEach(() => {
pubnub = new PubNub({ subscribeKey: 'demo', publishKey: 'demo' });
});

after(function () {
pubnub.destroy();
afterEach(() => {
pubnub.removeAllListeners();
pubnub.unsubscribeAll();
pubnub.stop();
});

it('should have to subscribe a channel', (done) => {
listener = {
pubnub.addListener({
status: (st) => {
expect(st.operation).to.be.equal('PNSubscribeOperation');
pubnub.unsubscribeAll()
done();
}
};

pubnub.addListener(listener);
});
pubnub.subscribe({channels: [myChannel1]});
});

it('should have to receive message from a channel', (done) => {
pubnub.disconnect();
pubnub.removeListener(listener);
pubnub.reconnect();

listener = {
pubnub.addListener({
status: (st) => {
if (st.operation === 'PNSubscribeOperation') {
pubnub.publish({ channel: myChannel2, message: { text: 'hello React-Native SDK' }});
}
},
message: (m) => {
expect(m.channel).to.be.equal(myChannel2);
expect(m.message.text).to.be.equal('hello React-Native SDK');
pubnub.unsubscribeAll()
done();
}
};

pubnub.addListener(listener);
});
pubnub.subscribe({channels: [myChannel2]});
pubnub.publish({ channel: myChannel2, message: { text: 'hello React-Native SDK' }});
});

it('should have to set state', (done) => {
Expand Down Expand Up @@ -120,24 +122,26 @@ describe('#distribution test (rkt-native)', function () {
done();
});

// TODO: fix test. it shouldn't rely on previous steps outcome.
it('should have to unsubscribe', function (done) {
pubnub.disconnect();
pubnub.removeListener(listener);
pubnub.reconnect();

let finished = false;

pubnub.addListener({
status: function (st) {
expect(st.operation).to.be.equal('PNUnsubscribeOperation');

if (!finished) {
// prevent calling done twice
finished = true;
done();
if (st.operation === 'PNSubscribeOperation') {
pubnub.unsubscribe({channels: [myChannel1]});
} else {
expect(st.operation).to.be.equal('PNUnsubscribeOperation');

if (!finished) {
// prevent calling done twice
finished = true;
pubnub.unsubscribeAll()
done();
}
}
}
});
pubnub.unsubscribe({channels: [myChannel1]});
pubnub.subscribe({channels: [myChannel1]});
});
});
});
2 changes: 2 additions & 0 deletions test/integration/endpoints/message_actions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ describe('message actions endpoints', () => {
assert.equal(messageActionEvent.data.messageTimetoken, messageTimetoken);
assert(messageActionEvent.data.actionTimetoken);
assert.equal(messageActionEvent.event, 'added');
pubnub.unsubscribeAll()

done();
}
Expand Down Expand Up @@ -489,6 +490,7 @@ describe('message actions endpoints', () => {
assert.equal(messageActionEvent.data.messageTimetoken, messageTimetokens[0]);
assert.equal(messageActionEvent.data.actionTimetoken, actionTimetokens[0]);
assert.equal(messageActionEvent.event, 'removed');
pubnub.unsubscribeAll()

done();
}
Expand Down