transform-async-to-promises: get rid of bluebird

This commit is contained in:
Michael Telatynski 2019-11-04 12:46:28 +00:00
parent eab6ffe7db
commit 10e1d9093e
10 changed files with 38 additions and 55 deletions

View file

@ -24,9 +24,6 @@ require('skin-sdk');
const jssdk = require('matrix-js-sdk');
const sdk = require('matrix-react-sdk');
const peg = require('matrix-react-sdk/lib/MatrixClientPeg');
const dis = require('matrix-react-sdk/lib/dispatcher');
const PageTypes = require('matrix-react-sdk/lib/PageTypes');
const MatrixChat = sdk.getComponent('structures.MatrixChat');
const RoomDirectory = sdk.getComponent('structures.RoomDirectory');
const RoomPreviewBar = sdk.getComponent('rooms.RoomPreviewBar');
@ -36,9 +33,9 @@ const React = require('react');
const ReactDOM = require('react-dom');
const ReactTestUtils = require('react-dom/test-utils');
const expect = require('expect');
import Promise from 'bluebird';
import {makeType} from "matrix-react-sdk/lib/utils/TypeUtils";
import {ValidatedServerConfig} from "matrix-react-sdk/lib/utils/AutoDiscoveryUtils";
import {sleep} from "../test-utils";
const test_utils = require('../test-utils');
const MockHttpBackend = require('matrix-mock-request');
@ -173,7 +170,7 @@ describe('joining a room', function() {
matrixChat, RoomView);
// the preview bar may take a tick to be displayed
return Promise.delay(1);
return sleep(1);
}).then(() => {
const previewBar = ReactTestUtils.findRenderedComponentWithType(
roomView, RoomPreviewBar);
@ -187,14 +184,14 @@ describe('joining a room', function() {
.respond(200, {room_id: ROOM_ID});
}).then(() => {
// wait for the join request to be made
return Promise.delay(1);
return sleep(1);
}).then(() => {
// and again, because the state update has to go to the store and
// then one dispatch within the store, then to the view
// XXX: This is *super flaky*: a better way would be to declare
// that we expect a certain state transition to happen, then wait
// for that transition to occur.
return Promise.delay(1);
return sleep(1);
}).then(() => {
// the roomview should now be loading
expect(roomView.state.room).toBe(null);
@ -209,7 +206,7 @@ describe('joining a room', function() {
}).then(() => {
httpBackend.verifyNoOutstandingExpectation();
return Promise.delay(1);
return sleep(1);
}).then(() => {
// NB. we don't expect the 'joining' flag to reset at any point:
// it will stay set and we observe whether we have Room object for

View file

@ -25,7 +25,6 @@ import React from 'react';
import ReactDOM from 'react-dom';
import ReactTestUtils from 'react-dom/test-utils';
import expect from 'expect';
import Promise from 'bluebird';
import MatrixReactTestUtils from 'matrix-react-test-utils';
import jssdk from 'matrix-js-sdk';
@ -41,6 +40,7 @@ import MockHttpBackend from 'matrix-mock-request';
import {parseQs, parseQsFromFragment} from '../../src/vector/url_utils';
import {makeType} from "matrix-react-sdk/lib/utils/TypeUtils";
import {ValidatedServerConfig} from "matrix-react-sdk/lib/utils/AutoDiscoveryUtils";
import {sleep} from "../test-utils";
const DEFAULT_HS_URL='http://my_server';
const DEFAULT_IS_URL='http://my_is';
@ -216,7 +216,7 @@ describe('loading:', function() {
it('gives a welcome page by default', function(done) {
loadApp();
Promise.delay(1).then(() => {
sleep(1).then(() => {
// at this point, we're trying to do a guest registration;
// we expect a spinner
assertAtLoadingSpinner(matrixChat);
@ -231,7 +231,7 @@ describe('loading:', function() {
return awaitWelcomeComponent(matrixChat);
}).then(() => {
expect(windowLocation.hash).toEqual("#/welcome");
}).done(done, done);
}).then(done, done);
});
it('should follow the original link after successful login', function(done) {
@ -243,7 +243,7 @@ describe('loading:', function() {
httpBackend.when("GET", "/versions").respond(200, {versions: ["r0.4.0"]});
httpBackend.when("GET", "/api/v1").respond(200, {});
Promise.delay(1).then(() => {
sleep(1).then(() => {
// at this point, we're trying to do a guest registration;
// we expect a spinner
assertAtLoadingSpinner(matrixChat);
@ -255,7 +255,7 @@ describe('loading:', function() {
return httpBackend.flush();
}).then(() => {
// Wait for another trip around the event loop for the UI to update
return Promise.delay(10);
return sleep(10);
}).then(() => {
return moveFromWelcomeToLogin(matrixChat);
}).then(() => {
@ -272,7 +272,7 @@ describe('loading:', function() {
expect(localStorage.getItem('mx_access_token')).toEqual('access_token');
expect(localStorage.getItem('mx_hs_url')).toEqual(DEFAULT_HS_URL);
expect(localStorage.getItem('mx_is_url')).toEqual(DEFAULT_IS_URL);
}).done(done, done);
}).then(done, done);
});
it('should not register as a guest when using a #/login link', function() {
@ -365,7 +365,7 @@ describe('loading:', function() {
ReactTestUtils.findRenderedComponentWithType(
matrixChat, sdk.getComponent('structures.EmbeddedPage'));
expect(windowLocation.hash).toEqual("#/home");
}).done(done, done);
}).then(done, done);
});
it('shows a room view if we followed a room link', function(done) {
@ -385,7 +385,7 @@ describe('loading:', function() {
}).then(() => {
httpBackend.verifyNoOutstandingExpectation();
expect(windowLocation.hash).toEqual("#/room/!room:id");
}).done(done, done);
}).then(done, done);
});
describe('/#/login link:', function() {
@ -445,7 +445,7 @@ describe('loading:', function() {
it('shows a welcome page by default', function(done) {
loadApp();
Promise.delay(1).then(() => {
sleep(1).then(() => {
// at this point, we're trying to do a guest registration;
// we expect a spinner
assertAtLoadingSpinner(matrixChat);
@ -469,13 +469,13 @@ describe('loading:', function() {
ReactTestUtils.findRenderedComponentWithType(
matrixChat, sdk.getComponent('auth.Welcome'));
expect(windowLocation.hash).toEqual("#/welcome");
}).done(done, done);
}).then(done, done);
});
it('uses the default homeserver to register with', function(done) {
loadApp();
Promise.delay(1).then(() => {
sleep(1).then(() => {
// at this point, we're trying to do a guest registration;
// we expect a spinner
assertAtLoadingSpinner(matrixChat);
@ -503,14 +503,14 @@ describe('loading:', function() {
expect(windowLocation.hash).toEqual("#/welcome");
expect(MatrixClientPeg.get().baseUrl).toEqual(DEFAULT_HS_URL);
expect(MatrixClientPeg.get().idBaseUrl).toEqual(DEFAULT_IS_URL);
}).done(done, done);
}).then(done, done);
});
it('shows a room view if we followed a room link', function(done) {
loadApp({
uriFragment: "#/room/!room:id",
});
Promise.delay(1).then(() => {
sleep(1).then(() => {
// at this point, we're trying to do a guest registration;
// we expect a spinner
assertAtLoadingSpinner(matrixChat);
@ -533,7 +533,7 @@ describe('loading:', function() {
}).then(() => {
httpBackend.verifyNoOutstandingExpectation();
expect(windowLocation.hash).toEqual("#/room/!room:id");
}).done(done, done);
}).then(done, done);
});
describe('Login as user', function() {
@ -600,7 +600,7 @@ describe('loading:', function() {
ReactTestUtils.Simulate.click(returnToApp);
return Promise.delay(1).then(() => {
return sleep(1).then(() => {
// we should be straight back into the home page
ReactTestUtils.findRenderedComponentWithType(
matrixChat, sdk.getComponent('structures.EmbeddedPage'));
@ -616,7 +616,7 @@ describe('loading:', function() {
queryString: "?loginToken=secretToken&homeserver=https%3A%2F%2Fhomeserver&identityServer=https%3A%2F%2Fidserver",
});
Promise.delay(1).then(() => {
sleep(1).then(() => {
// we expect a spinner while we're logging in
assertAtLoadingSpinner(matrixChat);
@ -645,7 +645,7 @@ describe('loading:', function() {
expect(localStorage.getItem('mx_access_token')).toEqual('access_token');
expect(localStorage.getItem('mx_hs_url')).toEqual('https://homeserver');
expect(localStorage.getItem('mx_is_url')).toEqual('https://idserver');
}).done(done, done);
}).then(done, done);
});
});
@ -664,7 +664,7 @@ describe('loading:', function() {
// Give the component some time to finish processing the login flows before
// continuing.
await Promise.delay(100);
await sleep(100);
httpBackend.when('POST', '/login').check(function(req) {
expect(req.data.type).toEqual('m.login.password');
@ -680,7 +680,7 @@ describe('loading:', function() {
return httpBackend.flush().then(() => {
// Wait for another trip around the event loop for the UI to update
return Promise.delay(1);
return sleep(1);
}).then(() => {
// we expect a spinner
ReactTestUtils.findRenderedComponentWithType(
@ -738,7 +738,7 @@ function awaitRoomView(matrixChat, retryLimit, retryCount) {
throw new Error("MatrixChat still not ready after " +
retryCount + " tries");
}
return Promise.delay(0).then(() => {
return sleep(0).then(() => {
return awaitRoomView(matrixChat, retryLimit, retryCount + 1);
});
}

View file

@ -1,7 +1,5 @@
"use strict";
import Promise from 'bluebird';
/**
* Perform common actions before each test case, e.g. printing the test case
* name to stdout.
@ -58,3 +56,5 @@ export function deleteIndexedDB(dbName) {
throw e;
});
}
export const sleep = (ms) => new Promise((resolve) => { setTimeout(resolve, ms); });