-
Notifications
You must be signed in to change notification settings - Fork 1
Replaced axios with fetch (FF-1976) #57
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
Conversation
19bbc01
to
4b6f32c
Compare
4b6f32c
to
29135d4
Compare
|
||
describe('Eppo Client constructed with configuration request parameters', () => { | ||
let client: EppoClient; | ||
let storage: IConfigurationStore; |
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.
I was finding that this variable seemed to be impacted by other tests - there is a bit of spaghetti here that I would love to unpack so things can run in a more isolated fashion.
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.
Interesting. Yeah test interdependency is not good.
import { Evaluator, FlagEvaluation, noneResult } from '../evaluator'; | ||
import ExperimentConfigurationRequestor from '../flag-configuration-requestor'; | ||
import HttpClient from '../http-client'; | ||
import FlagConfigurationRequestor from '../flag-configuration-requestor'; |
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 default exports in nodejs are kind of funny to me; noticed this wasn't renamed.
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.
Nice work! 👏 This is a great modernization.
I agree the mocking got a bit all over. I think basically we separate that test into separate describe blocks for when we want the unobfuscated UFC, obfuscated UFC, or per-test. The first two just need to make one mock for all tests returning the appropriate UFC. The latter can not mock anything in a beforeAll()
, leaving it up to the tests, but resetting in an afterEach() or afterAll()
. I think that would clean things up.
Also, this would be a good time to sneak in changing the default for throwing error on initialization.
|
||
describe('EppoClient E2E test', () => { | ||
const storage = new TestConfigurationStore(); | ||
global.fetch = jest.fn(() => { |
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.
Jest runs each file in it's own process so I don't think it's necessary to clean this up. But you may want to, just in case. Also not necessary, but consider putting it in beforeAll()
just to cluster that one-time stuff together.
beforeAll(async () => {
const original fetch = fetch;
global.fetch = jest.fn(() => {
...
});
await init(storage);
});
afterAll(()=> {
global.fetch = originalFetch;
})
Update: I see you do it later on. I think you could just ax this one entirely and just save off and restore fetch()
at the top level. Then have two nested describes for unobfuscated and obfuscated responses, where you mock fetch()
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.
🚀
Motivation and Context
1️⃣ the
axios
package cannot be supported in chrome extensions v3 because it is based on APIs that do not exist within a service worker. dogfooding eppo's js sdk within an v3 extension throws this error:2️⃣
axios
is a heavy weight package and is something like 50% of our asset size. removing it will improve our customers' applicationsDescription
axios
withfetch
- supporting a base url and timeoutsIHttpClient
interface and implementingFetchHttpClient
Decisions
Since the
HttpClient
is instantiated inside theEppoClient
, instead of being injected in, I have no choice but to continue mocking the http API. Changing fromxhr-mock
to mockingfetch
itself. In the future if we decide passing the http client is useful then we can mock that object directly.👉 Could use a set of eyes on the
beforeAlls
in the unit tests - everything passes but something feels a little off to me.How has this been tested?