-
Notifications
You must be signed in to change notification settings - Fork 158
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
Add build step and TS support #243
Conversation
"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.", | ||
"license": "MIT", | ||
"engines": { | ||
"node": ">=4" | ||
}, | ||
"scripts": { | ||
"prepublishOnly": "npm run build && npm run tests-only", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Making sure that the build step is ran before publishing a new version, in case a PR bypassed a red CI somehow.
"test": "npm run lint && npm run jscs && npm run tests-only", | ||
"test-ci": "npm run pretest && npm run lint && npm run jscs && npm run tests-only-ci", | ||
"test-ci": "npm run pretest && npm run build && npm run lint && npm run jscs && npm run tests-only-ci", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Making sure that the build step is ran before running the tests, in case there is a PR that didn't include the build outputs.
This comment has been minimized.
This comment has been minimized.
74fb3dd
to
10cf35a
Compare
src/index.ts
Outdated
@@ -144,7 +131,7 @@ function Pretender(/* routeMap1, routeMap2, ..., options*/) { | |||
self.XMLHttpRequest = interceptor(ctx); | |||
|
|||
// polyfill fetch when xhr is ready | |||
this._fetchProps = FakeFetch ? ['fetch', 'Headers', 'Request', 'Response'] : []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was just added in a recently merged PR #235, so I'm surprised to see you changing it back. Have you studied the other PR, and verified that your change is correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My initial impression was that it was just a fallback put in place to avoid an error state. (had seem to be a reaction to the issue linked to in the original PR)
Now I see that I was wrong, it is about restoring the global space to its original state if needed. I would have used different syntax, but that is out of scope for this PR :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The thing is, I still don't see how would FakeFetch
ever be undefined? Originally, the conversation around it started because of issue #221, but that one is easily explained. The html wasn't loading fetch.umd.js
.
I don't think we need the fallback, but I'm going to leave that in place since it isn't immediately pertinent to the objective of this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xg-wang can you comment here as to the correct behavior? I don't want anyone to roll back a legitimate bugfix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When appearsBrowserified
is false
, if the whatwg-fetch
lib is not installed self.WHATWGFetch
will be undefined
. This always happens for non ember-cli-pretender
users since they have to manual bundle the fetch lib.
In this pr the build output will be:
var FakeFetch = self.WHATWGFetch;
var Pretender = (function (self, RouteRecognizer, FakeXMLHttpRequest, FakeFetch) {
}(self, RouteRecognizer, FakeXMLHttpRequest, FakeFetch));
The self.WHATWGFetch
is pulled in by https://github.com/pretenderjs/pretender/blob/v2.1.1/karma.conf.js#L24
@mike-north thanks for the feedback! I'll be addressing each comment. |
We have to think about how to deal with the type information consumers see, and how this PR may affect/break things. Typically, after TS conversion is complete, hand-written declaration files ( Ultimately (i.e., before we publish a new release) we want type information to come from the
|
return module.default || module; | ||
} | ||
|
||
var appearsBrowserified = typeof self !== 'undefined' && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a breaking change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It shouldn't break anyones app. The build step produces two files with unique consumption mechanisms that immediately inform whether you are browserifying or not depending on which one you choose to use. So, Pretender doesn't need to figure that out at runtime anymore.
I linked it to ember-cli-mirage and ran all the tests ( Adding the types blew out the diffs. If you prefer, I'm okay to go back to plan B (not generate the declaration file) and postpone the addition of the types for a subsequent PR. |
@givanse Yes, let's ensure rollup does not generate declaration files, and stick with the handwritten types until we can get the |
2e815f7
to
7da303c
Compare
7da303c
to
eb06984
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this looks good to me now. @givanse we ready to merge?
Yeah, it is ready. Thanks for your help. |
This is excellent! Can we get a release based on this version? We're using Pretender in an Angular app and installing off of master fixes the manual module resolution problems that we were encountering 👌 |
Depends on:
module
attribute FakeXMLHttpRequest#46