Socket
Socket
Sign inDemoInstall

slow-promise

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

slow-promise - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

examples/puppeteer/bad_test.js

8

dist/slow-promise.install.js
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.SlowPromise = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
const NativePromise = Promise; // this will allow us to install SlowPromise in place of the native Promise implementation
let nativeFetch = window.fetch;
module.exports.mockFetch = (mockFetch) => nativeFetch = mockFetch;

@@ -23,8 +25,12 @@ let delayInMs = 1000;

const slowFetch = (...args) => wrapPromise(nativeFetch.apply(window, args));
module.exports.SlowPromise = SlowPromise;
module.exports.slowFetch = slowFetch;
},{}],2:[function(require,module,exports){
const { SlowPromise, setDelay } = require("./index");
const { SlowPromise, slowFetch, setDelay } = require("./index");
window.Promise = SlowPromise;
window.fetch = slowFetch;

@@ -31,0 +37,0 @@ if (document.currentScript) {

const NativePromise = Promise; // this will allow us to install SlowPromise in place of the native Promise implementation
let nativeFetch = window.fetch;
module.exports.mockFetch = (mockFetch) => nativeFetch = mockFetch;

@@ -22,2 +24,5 @@ let delayInMs = 1000;

const slowFetch = (...args) => wrapPromise(nativeFetch.apply(window, args));
module.exports.SlowPromise = SlowPromise;
module.exports.slowFetch = slowFetch;

@@ -1,3 +0,6 @@

const { SlowPromise } = require("./index");
global.window = {};
const fetchMock = require('fetch-mock');
const { SlowPromise, slowFetch, mockFetch } = require("./index");
describe("slow-promise", () => {

@@ -459,2 +462,47 @@ let spy;

});
describe("fetch", () => {
let sandboxFetch;
beforeEach(() => {
sandboxFetch = fetchMock.sandbox();
mockFetch(sandboxFetch);
sandboxFetch.mock('*', 200);
});
afterEach(() => {
sandboxFetch.reset();
});
it("does not call the callback if timeout hasn't occurred yet", async () => {
const p = slowFetch('http://localhost:65432/blargh');
p.then(spy);
await processNextPromiseChain();
jasmine.clock().tick(999);
await processNextPromiseChain();
expect(spy).not.toHaveBeenCalled();
});
it("calls the callback after timeout has occurred", async () => {
const p = slowFetch('http://localhost:65432/blargh');
p.then(spy);
await processNextPromiseChain();
jasmine.clock().tick(1000);
await processNextPromiseChain();
expect(spy).toHaveBeenCalled();
});
it("returns the response", async () => {
const p = slowFetch('http://localhost:65432/blargh');
p.then(spy);
await processNextPromiseChain();
jasmine.clock().tick(1000);
await processNextPromiseChain();
const args = spy.calls.mostRecent().args;
expect(args.length).toBe(1);
expect(args[0].status).toBe(200);
});
});
});

3

install_global.js

@@ -1,4 +0,5 @@

const { SlowPromise, setDelay } = require("./index");
const { SlowPromise, slowFetch, setDelay } = require("./index");
window.Promise = SlowPromise;
window.fetch = slowFetch;

@@ -5,0 +6,0 @@ if (document.currentScript) {

{
"name": "slow-promise",
"version": "0.2.0",
"version": "0.3.0",
"description": "Slow down your promises",

@@ -21,6 +21,8 @@ "main": "index.js",

"browserify": "^16.2.3",
"fetch-mock": "^7.3.3",
"jasmine": "^3.4.0",
"jshint": "^2.10.2",
"node-fetch": "^2.3.0",
"prettier": "^1.16.4"
}
}

@@ -9,2 +9,6 @@ # slow-promise

## Example
Slow-Promise surfacing a flaky test in Puppeteer: [./examples/puppeteer/](./examples/puppeteer/)
## Why?

@@ -11,0 +15,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc