-
-
Notifications
You must be signed in to change notification settings - Fork 80
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
Do not include polyfill if browser targets don't need it #173
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2c4e636
Do not include fetch polyfill if target browsers don't need it
27a87fc
Ensure abortcontroller polyfill is included if it is not supported
0df78a3
Require `preferNative=true` to check for fetch support
2e7bfa6
Streamline fetch browser target checks & tests
d326603
Update README.md
xg-wang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
'use strict'; | ||
|
||
const AddonFactory = require('../'); | ||
const expect = require('chai').expect; | ||
const helpers = require('broccoli-test-helper'); | ||
const co = require('co'); | ||
|
||
describe(`Do not include the polyfill if the browser targets match`, function() { | ||
xg-wang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let output, subject, addon; | ||
|
||
beforeEach(function() { | ||
addon = Object.create(AddonFactory); | ||
Object.assign(addon, { | ||
addons: [], | ||
_fetchBuildConfig: { | ||
xg-wang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
preferNative: true, | ||
browsers: ['last 1 chrome versions'] | ||
}, | ||
ui: { | ||
writeWarnLine() { | ||
} | ||
} | ||
}); | ||
subject = addon.treeForVendor(); | ||
output = helpers.createBuilder(subject); | ||
}); | ||
|
||
afterEach(co.wrap(function* () { | ||
yield output.dispose(); | ||
})); | ||
|
||
it('preferNative is built into vendor file', co.wrap(function* () { | ||
xg-wang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
yield output.build(); | ||
let files = output.read(); | ||
expect(files).to.have.all.keys('ember-fetch.js'); | ||
expect(files['ember-fetch.js']).to.include(`var preferNative = true`); | ||
xg-wang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
expect(files['ember-fetch.js']).to.not.include(`fetch.polyfill = true`); | ||
expect(files['ember-fetch.js']).to.not.include(`class AbortController`); | ||
})); | ||
|
||
}); | ||
|
||
describe(`Ignore target browsers if preferNative is false`, function() { | ||
let output, subject, addon; | ||
|
||
beforeEach(function() { | ||
addon = Object.create(AddonFactory); | ||
Object.assign(addon, { | ||
addons: [], | ||
_fetchBuildConfig: { | ||
preferNative: false, | ||
browsers: ['last 1 chrome versions'] | ||
}, | ||
ui: { | ||
writeWarnLine() { | ||
} | ||
} | ||
}); | ||
subject = addon.treeForVendor(); | ||
output = helpers.createBuilder(subject); | ||
}); | ||
|
||
afterEach(co.wrap(function* () { | ||
yield output.dispose(); | ||
})); | ||
|
||
it('preferNative is built into vendor file', co.wrap(function* () { | ||
yield output.build(); | ||
let files = output.read(); | ||
expect(files).to.have.all.keys('ember-fetch.js'); | ||
expect(files['ember-fetch.js']).to.include(`var preferNative = false`); | ||
expect(files['ember-fetch.js']).to.include(`fetch.polyfill = true`); | ||
expect(files['ember-fetch.js']).to.include(`class AbortController`); | ||
})); | ||
|
||
}); | ||
|
||
describe(`Include the polyfill if the browser targets do not match`, function() { | ||
let output, subject, addon; | ||
|
||
beforeEach(function() { | ||
addon = Object.create(AddonFactory); | ||
Object.assign(addon, { | ||
addons: [], | ||
_fetchBuildConfig: { | ||
preferNative: true, | ||
browsers: ['ie 11'] | ||
}, | ||
ui: { | ||
writeWarnLine() { | ||
} | ||
} | ||
}); | ||
subject = addon.treeForVendor(); | ||
output = helpers.createBuilder(subject); | ||
}); | ||
|
||
afterEach(co.wrap(function* () { | ||
yield output.dispose(); | ||
})); | ||
|
||
it('preferNative is built into vendor file', co.wrap(function* () { | ||
yield output.build(); | ||
let files = output.read(); | ||
expect(files).to.have.all.keys('ember-fetch.js'); | ||
expect(files['ember-fetch.js']).to.include(`var preferNative = true`); | ||
expect(files['ember-fetch.js']).to.include(`fetch.polyfill = true`); | ||
expect(files['ember-fetch.js']).to.include(`class AbortController`); | ||
})); | ||
|
||
}); | ||
|
||
describe(`Include the abortcontroller polyfill only if the browser targets support fetch only`, function() { | ||
let output, subject, addon; | ||
|
||
beforeEach(function() { | ||
addon = Object.create(AddonFactory); | ||
Object.assign(addon, { | ||
addons: [], | ||
_fetchBuildConfig: { | ||
preferNative: true, | ||
browsers: ['safari 11'] | ||
}, | ||
ui: { | ||
writeWarnLine() { | ||
} | ||
} | ||
}); | ||
subject = addon.treeForVendor(); | ||
output = helpers.createBuilder(subject); | ||
}); | ||
|
||
afterEach(co.wrap(function* () { | ||
yield output.dispose(); | ||
})); | ||
|
||
it('preferNative is built into vendor file', co.wrap(function* () { | ||
yield output.build(); | ||
let files = output.read(); | ||
expect(files).to.have.all.keys('ember-fetch.js'); | ||
expect(files['ember-fetch.js']).to.include(`var preferNative = true`); | ||
expect(files['ember-fetch.js']).to.not.include(`fetch.polyfill = true`); | ||
expect(files['ember-fetch.js']).to.include(`class AbortController`); | ||
})); | ||
|
||
}); | ||
|
||
describe(`Include the polyfill if alwaysIncludePolyfill=true`, function() { | ||
let output, subject, addon; | ||
|
||
beforeEach(function() { | ||
addon = Object.create(AddonFactory); | ||
Object.assign(addon, { | ||
addons: [], | ||
_fetchBuildConfig: { | ||
preferNative: true, | ||
alwaysIncludePolyfill: true, | ||
browsers: ['last 1 chrome versions'] | ||
}, | ||
ui: { | ||
writeWarnLine() { | ||
} | ||
} | ||
}); | ||
subject = addon.treeForVendor(); | ||
output = helpers.createBuilder(subject); | ||
}); | ||
|
||
afterEach(co.wrap(function* () { | ||
yield output.dispose(); | ||
})); | ||
|
||
it('preferNative is built into vendor file', co.wrap(function* () { | ||
yield output.build(); | ||
let files = output.read(); | ||
expect(files).to.have.all.keys('ember-fetch.js'); | ||
expect(files['ember-fetch.js']).to.include(`var preferNative = true`); | ||
expect(files['ember-fetch.js']).to.include(`fetch.polyfill = true`); | ||
expect(files['ember-fetch.js']).to.include(`class AbortController`); | ||
})); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 error should be changed to provide more actionable info if we agree on changes below.