Skip to content
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

Allow opt-out of fetch polyfill #67

Merged
merged 1 commit into from Jan 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Expand Up @@ -35,6 +35,16 @@ var app = new EmberApp({
});
```

You can also opt out of including the fetch polyfill, if you do not need to run your tests in older browsers:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be "if you do not need to test fetch with pretender"? Since the polyfill is not for older browsers but to make fetch interceptable by pretender.


```javascript
var app = new EmberApp({
pretender: {
includeFetchPolyfill: false
}
});
```

Nested Addon Usage Caveat
=====

Expand Down
33 changes: 27 additions & 6 deletions index.js
Expand Up @@ -63,10 +63,8 @@ module.exports = {
});
},

included: function included(app) {
if (app.app) {
app = app.app;
}
included: function included() {
var app = this._findApp();
this.app = app;

var opts = app.options.pretender || { enabled: app.tests };
Expand All @@ -75,9 +73,32 @@ module.exports = {

app.import('vendor/fake-xml-http-request/' + path.basename(this._fakeRequestPath));
app.import('vendor/route-recognizer/' + path.basename(this._routeRecognizerPath));
app.import('vendor/abortcontroller-polyfill/' + path.basename(this._abortControllerPath));
app.import('vendor/whatwg-fetch/' + path.basename(this._whatwgFetchPath));

var includeFetchPolyfill = opts.includeFetchPolyfill || typeof opts.includeFetchPolyfill === 'undefined';
if (includeFetchPolyfill) {
app.import('vendor/abortcontroller-polyfill/' + path.basename(this._abortControllerPath));
app.import('vendor/whatwg-fetch/' + path.basename(this._whatwgFetchPath));
}

app.import('vendor/pretender/' + path.basename(this._pretenderPath));
}
},

_findApp() {
if (typeof this._findHost === 'function') {
return this._findHost();
} else {
// Otherwise, we'll use this implementation borrowed from the _findHost()
// method in ember-cli.
// Keep iterating upward until we don't have a grandparent.
// Has to do this grandparent check because at some point we hit the project.
let app;
let current = this;
do {
app = current.app || this;
} while (current.parent && current.parent.parent && (current = current.parent));

return app;
}
},
};