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

fix: CozyClient can be used in a node env #1180

Merged
merged 1 commit into from May 27, 2022

Conversation

Ldoppea
Copy link
Member

@Ldoppea Ldoppea commented May 25, 2022

Previous fix tried to handle undefined window in node env

But in a node env window is not undefined as it is not even an
existing variable

So instead of checking its value, a better way is to check its type as
typeof will return 'undefined' when called with a variable that
does not exist

Related commit: 509a0ca

Warning
This fix cannot be unit tested until #1179 - Current tests are not covering Node environment is resolved

Following test is success with the new fix if run from a node env

    it('should not secure the URL if window is not existing (node env)', () => {
      const client = new CozyClient({
        uri: 'http://cozy.tools',
        schema: '',
        token: 'SOME_TOKEN'
      })

      expect(client.options.uri).toBe('http://cozy.tools')
    })

Following test is success with the new fix if run from a jsdom env

    it('should not secure the URL if window is undefined (node env)', () => {
      let windowSpy = jest.spyOn(window, 'window', 'get')
      windowSpy.mockImplementation(() => undefined)
      const client = new CozyClient({
        uri: 'http://cozy.tools',
        schema: '',
        token: 'SOME_TOKEN'
      })

      expect(client.options.uri).toBe('http://cozy.tools')
      windowSpy.mockRestore()
    })

Previous fix tried to handle undefined `window` in node env

But in a node env window is not `undefined` as it is not even an
existing variable

So instead of checking its value, a better way is to check its type as
`typeof` will return `'undefined'` when called with a variable that
does not exist

Related commit: 509a0ca
@Ldoppea Ldoppea force-pushed the fix/handle_window_not_defined branch from eb0460f to 2b963c6 Compare May 25, 2022 16:44
Copy link
Contributor

@paultranvan paultranvan left a comment

Choose a reason for hiding this comment

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

Thanks 🎉

@Ldoppea Ldoppea merged commit ab4556f into master May 27, 2022
@Ldoppea Ldoppea deleted the fix/handle_window_not_defined branch May 27, 2022 07:48
Ldoppea added a commit to cozy/cozy-drive that referenced this pull request May 27, 2022
`cozy-client` as been upgraded to to `29.1.1` to retrieve fix about
broken services from cozy/cozy-client#1180
Ldoppea added a commit to cozy/cozy-banks that referenced this pull request May 27, 2022
`cozy-client` as been upgraded to to `29.1.1` to retrieve fix about
broken services from cozy/cozy-client#1180
Ldoppea added a commit to cozy/cozy-drive that referenced this pull request May 27, 2022
`cozy-client` as been upgraded to to `29.1.1` to retrieve fix about
broken services from cozy/cozy-client#1180
Ldoppea added a commit to cozy/cozy-drive that referenced this pull request May 27, 2022
`cozy-client` as been upgraded to to `29.1.1` to retrieve fix about
broken services from cozy/cozy-client#1180
Ldoppea added a commit to cozy/cozy-banks that referenced this pull request May 27, 2022
`cozy-client` as been upgraded to to `29.1.1` to retrieve fix about
broken services from cozy/cozy-client#1180
Ldoppea added a commit to cozy/cozy-drive that referenced this pull request May 27, 2022
`cozy-client` as been upgraded to to `29.1.1` to retrieve fix about
broken services from cozy/cozy-client#1180
Ldoppea added a commit to cozy/cozy-banks that referenced this pull request May 27, 2022
`cozy-client` as been upgraded to to `29.1.1` to retrieve fix about
broken services from cozy/cozy-client#1180
Ldoppea added a commit to cozy/cozy-drive that referenced this pull request May 27, 2022
`cozy-client` as been upgraded to to `29.1.1` to retrieve fix about
broken services from cozy/cozy-client#1180
Ldoppea added a commit to cozy/cozy-banks that referenced this pull request May 27, 2022
`cozy-client` as been upgraded to to `29.1.1` to retrieve fix about
broken services from cozy/cozy-client#1180
Ldoppea added a commit to cozy/cozy-banks that referenced this pull request May 27, 2022
`cozy-client` as been upgraded to to `29.1.1` to retrieve fix about
broken services from cozy/cozy-client#1180
Ldoppea added a commit to cozy/cozy-drive that referenced this pull request May 27, 2022
`cozy-client` as been upgraded to to `29.1.1` to retrieve fix about
broken services from cozy/cozy-client#1180
paultranvan added a commit to cozy/coachCO2 that referenced this pull request May 30, 2022
paultranvan added a commit to cozy/coachCO2 that referenced this pull request May 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants