Skip to content

Commit 215324d

Browse files
committed
fix for relative path import
1 parent 654f317 commit 215324d

8 files changed

Lines changed: 43 additions & 21 deletions

File tree

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ with an express/sinatra style syntax for defining routes and their handlers.
1212
Pretender will temporarily replace native XMLHttpRequest and Fetch , intercept
1313
all requests, and direct them to little pretend service you've defined.
1414

15-
**:warning: Pretender only works in the browser!**
16-
1715
```javascript
1816
const PHOTOS = {
1917
"10": {
@@ -40,6 +38,10 @@ const server = new Pretender(function() {
4038
$.get('/photos/12', {success() => { ... }})
4139
```
4240
41+
## Usage examples
42+
43+
44+
4345
## The Server DSL
4446
The server DSL is inspired by express/sinatra. Pass a function to the Pretender constructor
4547
that will be invoked with the Pretender instance as its context. Available methods are

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "pretender",
33
"version": "3.1.0",
44
"main": "./pretender.js",
5-
"module": "./pretender.es.js",
5+
"module": "./src/pretender.es.js",
66
"description": "Pretender is a mock server library for XMLHttpRequest and Fetch, that comes with an express/sinatra style syntax for defining routes and their handlers.",
77
"license": "MIT",
88
"engines": {
@@ -29,7 +29,7 @@
2929
"coveralls": "^2.11.3",
3030
"es6-promise": "^4.0.5",
3131
"eslint": "^5.11.1",
32-
"jshint": "^2.8.0",
32+
"jshint": "^2.9.7",
3333
"karma": "^1.7.0",
3434
"karma-chrome-launcher": "^2.2.0",
3535
"karma-coverage": "^1.1.1",
@@ -48,6 +48,7 @@
4848
"typescript-eslint-parser": "^21.0.2"
4949
},
5050
"dependencies": {
51+
"@babel/plugin-external-helpers": "^7.2.0",
5152
"@xg-wang/whatwg-fetch": "^3.0.0",
5253
"fake-xml-http-request": "^2.0.0",
5354
"route-recognizer": "^0.3.3"

pretender.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ var Pretender = (function (self, RouteRecognizer, FakeXMLHttpRequest, FakeFetch)
3333
var anchor = document.createElement('a');
3434
anchor.href = url;
3535
if (!anchor.host) {
36+
// eslint-disable-next-line no-self-assign
3637
anchor.href = anchor.href; // IE: load the host and protocol
3738
}
3839
var pathname = anchor.pathname;
@@ -243,6 +244,7 @@ var Pretender = (function (self, RouteRecognizer, FakeXMLHttpRequest, FakeFetch)
243244
return this._passthroughCheck('getAllResponseHeaders', arguments);
244245
};
245246
if (ctx.pretender._nativeXMLHttpRequest.prototype._passthroughCheck) {
247+
// eslint-disable-next-line no-console
246248
console.warn('You created a second Pretender instance while there was already one running. ' +
247249
'Running two Pretender servers at once will lead to unexpected results and will ' +
248250
'be removed entirely in a future major version.' +
@@ -322,7 +324,9 @@ var Pretender = (function (self, RouteRecognizer, FakeXMLHttpRequest, FakeFetch)
322324
var note = 'Remember to `return [status, headers, body];` in your route handler.';
323325
throw new Error('Nothing returned by handler for ' + path + '. ' + note);
324326
}
325-
var status = statusHeadersAndBody[0], headers = pretender.prepareHeaders(statusHeadersAndBody[1]), body = pretender.prepareBody(statusHeadersAndBody[2], headers);
327+
var status = statusHeadersAndBody[0];
328+
var headers = pretender.prepareHeaders(statusHeadersAndBody[1]);
329+
var body = pretender.prepareBody(statusHeadersAndBody[2], headers);
326330
pretender.handleResponse(request, async, function () {
327331
request.respond(status, headers, body);
328332
pretender.handledRequest(verb, path, request);

rollup.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ module.exports = {
3030
'var RouteRecognizer = self.RouteRecognizer;\n',
3131
},
3232
{
33-
file: 'pretender.es.js',
33+
file: 'src/pretender.es.js',
3434
format: 'es'
3535
},
3636
{
37-
file: 'pretender.cjs.js',
37+
file: 'src/pretender.cjs.js',
3838
format: 'cjs'
3939
},
4040
],

src/iife-self-placeholder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// This is just a placeholder for the build step
22
// See the IIFE output in the Rollup config
3-
export default null;
3+
export default window;
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ function parseURL(url) {
2929
var anchor = document.createElement('a');
3030
anchor.href = url;
3131
if (!anchor.host) {
32+
// eslint-disable-next-line no-self-assign
3233
anchor.href = anchor.href; // IE: load the host and protocol
3334
}
3435
var pathname = anchor.pathname;
@@ -239,6 +240,7 @@ function interceptor(ctx) {
239240
return this._passthroughCheck('getAllResponseHeaders', arguments);
240241
};
241242
if (ctx.pretender._nativeXMLHttpRequest.prototype._passthroughCheck) {
243+
// eslint-disable-next-line no-console
242244
console.warn('You created a second Pretender instance while there was already one running. ' +
243245
'Running two Pretender servers at once will lead to unexpected results and will ' +
244246
'be removed entirely in a future major version.' +
@@ -318,7 +320,9 @@ Pretender.prototype = {
318320
var note = 'Remember to `return [status, headers, body];` in your route handler.';
319321
throw new Error('Nothing returned by handler for ' + path + '. ' + note);
320322
}
321-
var status = statusHeadersAndBody[0], headers = pretender.prepareHeaders(statusHeadersAndBody[1]), body = pretender.prepareBody(statusHeadersAndBody[2], headers);
323+
var status = statusHeadersAndBody[0];
324+
var headers = pretender.prepareHeaders(statusHeadersAndBody[1]);
325+
var body = pretender.prepareBody(statusHeadersAndBody[2], headers);
322326
pretender.handleResponse(request, async, function () {
323327
request.respond(status, headers, body);
324328
pretender.handledRequest(verb, path, request);

pretender.es.js renamed to src/pretender.es.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ function parseURL(url) {
2525
var anchor = document.createElement('a');
2626
anchor.href = url;
2727
if (!anchor.host) {
28+
// eslint-disable-next-line no-self-assign
2829
anchor.href = anchor.href; // IE: load the host and protocol
2930
}
3031
var pathname = anchor.pathname;
@@ -235,6 +236,7 @@ function interceptor(ctx) {
235236
return this._passthroughCheck('getAllResponseHeaders', arguments);
236237
};
237238
if (ctx.pretender._nativeXMLHttpRequest.prototype._passthroughCheck) {
239+
// eslint-disable-next-line no-console
238240
console.warn('You created a second Pretender instance while there was already one running. ' +
239241
'Running two Pretender servers at once will lead to unexpected results and will ' +
240242
'be removed entirely in a future major version.' +
@@ -314,7 +316,9 @@ Pretender.prototype = {
314316
var note = 'Remember to `return [status, headers, body];` in your route handler.';
315317
throw new Error('Nothing returned by handler for ' + path + '. ' + note);
316318
}
317-
var status = statusHeadersAndBody[0], headers = pretender.prepareHeaders(statusHeadersAndBody[1]), body = pretender.prepareBody(statusHeadersAndBody[2], headers);
319+
var status = statusHeadersAndBody[0];
320+
var headers = pretender.prepareHeaders(statusHeadersAndBody[1]);
321+
var body = pretender.prepareBody(statusHeadersAndBody[2], headers);
318322
pretender.handleResponse(request, async, function () {
319323
request.respond(status, headers, body);
320324
pretender.handledRequest(verb, path, request);

yarn.lock

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
dependencies:
1010
"@babel/highlight" "^7.0.0"
1111

12+
"@babel/helper-plugin-utils@^7.0.0":
13+
version "7.0.0"
14+
resolved "https://registry.yarnpkg.com/@babel/helper-plugin-utils/-/helper-plugin-utils-7.0.0.tgz#bbb3fbee98661c569034237cc03967ba99b4f250"
15+
integrity sha512-CYAOUCARwExnEixLdB6sDm2dIJ/YgEAKDM1MOeMeZu9Ld/bDgVo8aiWrXwcY7OBh+1Ea2uUcVRcxKk0GJvW7QA==
16+
1217
"@babel/highlight@^7.0.0":
1318
version "7.0.0"
1419
resolved "https://registry.yarnpkg.com/@babel/highlight/-/highlight-7.0.0.tgz#f710c38c8d458e6dd9a201afb637fcb781ce99e4"
@@ -18,6 +23,13 @@
1823
esutils "^2.0.2"
1924
js-tokens "^4.0.0"
2025

26+
"@babel/plugin-external-helpers@^7.2.0":
27+
version "7.2.0"
28+
resolved "https://registry.yarnpkg.com/@babel/plugin-external-helpers/-/plugin-external-helpers-7.2.0.tgz#7f4cb7dee651cd380d2034847d914288467a6be4"
29+
integrity sha512-QFmtcCShFkyAsNtdCM3lJPmRe1iB+vPZymlB4LnDIKEBj2yKQLQKtoxXxJ8ePT5fwMl4QGg303p4mB0UsSI2/g==
30+
dependencies:
31+
"@babel/helper-plugin-utils" "^7.0.0"
32+
2133
"@sinonjs/formatio@^2.0.0":
2234
version "2.0.0"
2335
resolved "https://registry.yarnpkg.com/@sinonjs/formatio/-/formatio-2.0.0.tgz#84db7e9eb5531df18a8c5e0bfb6e449e55e654b2"
@@ -2339,16 +2351,16 @@ jsbn@~0.1.0:
23392351
resolved "https://registry.yarnpkg.com/jsbn/-/jsbn-0.1.1.tgz#a5e654c2e5a2deb5f201d96cefbca80c0ef2f513"
23402352
integrity sha1-peZUwuWi3rXyAdls77yoDA7y9RM=
23412353

2342-
jshint@^2.8.0:
2343-
version "2.9.5"
2344-
resolved "https://registry.yarnpkg.com/jshint/-/jshint-2.9.5.tgz#1e7252915ce681b40827ee14248c46d34e9aa62c"
2345-
integrity sha1-HnJSkVzmgbQIJ+4UJIxG006apiw=
2354+
jshint@^2.9.7:
2355+
version "2.9.7"
2356+
resolved "https://registry.yarnpkg.com/jshint/-/jshint-2.9.7.tgz#038a3fa5c328fa3ab03ddfd85df88d3d87bedcbd"
2357+
integrity sha512-Q8XN38hGsVQhdlM+4gd1Xl7OB1VieSuCJf+fEJjpo59JH99bVJhXRXAh26qQ15wfdd1VPMuDWNeSWoNl53T4YA==
23462358
dependencies:
23472359
cli "~1.0.0"
23482360
console-browserify "1.1.x"
23492361
exit "0.1.x"
23502362
htmlparser2 "3.8.x"
2351-
lodash "3.7.x"
2363+
lodash "~4.17.10"
23522364
minimatch "~3.0.2"
23532365
shelljs "0.3.x"
23542366
strip-json-comments "1.0.x"
@@ -2570,11 +2582,6 @@ lodash.unescape@4.0.1:
25702582
resolved "https://registry.yarnpkg.com/lodash.unescape/-/lodash.unescape-4.0.1.tgz#bf2249886ce514cda112fae9218cdc065211fc9c"
25712583
integrity sha1-vyJJiGzlFM2hEvrpIYzcBlIR/Jw=
25722584

2573-
lodash@3.7.x:
2574-
version "3.7.0"
2575-
resolved "https://registry.yarnpkg.com/lodash/-/lodash-3.7.0.tgz#3678bd8ab995057c07ade836ed2ef087da811d45"
2576-
integrity sha1-Nni9irmVBXwHreg27S7wh9qBHUU=
2577-
25782585
lodash@^3.8.0:
25792586
version "3.10.1"
25802587
resolved "https://registry.yarnpkg.com/lodash/-/lodash-3.10.1.tgz#5bf45e8e49ba4189e17d482789dfd15bd140b7b6"
@@ -2585,7 +2592,7 @@ lodash@^4.0.1, lodash@^4.17.0, lodash@^4.17.10, lodash@^4.5.0:
25852592
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.10.tgz#1b7793cf7259ea38fb3661d4d38b3260af8ae4e7"
25862593
integrity sha512-UejweD1pDoXu+AD825lWwp4ZGtSwgnpZxb3JDViD7StjQz+Nb/6l093lx4OQ0foGWNRoc19mWy7BzL+UAK2iVg==
25872594

2588-
lodash@^4.17.11, lodash@^4.17.5:
2595+
lodash@^4.17.11, lodash@^4.17.5, lodash@~4.17.10:
25892596
version "4.17.11"
25902597
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.11.tgz#b39ea6229ef607ecd89e2c8df12536891cac9b8d"
25912598
integrity sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==

0 commit comments

Comments
 (0)