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

Working with axios-cookiejar-support ? #439

Open
skilbjo opened this issue Jan 21, 2024 · 1 comment
Open

Working with axios-cookiejar-support ? #439

skilbjo opened this issue Jan 21, 2024 · 1 comment

Comments

@skilbjo
Copy link

skilbjo commented Jan 21, 2024

I'm not able to get this working to 1) record requests and 2) play them back.

the test works perfectly fine if i comment out the await jestPlayback.setup({ ... }) line.

src.ts

import axios from 'axios'
import { wrapper } from 'axios-cookiejar-support';

wrapper(axios);

const data = (await axios.request({
  ...
})).data

test.ts

import * as jestPlayback from 'jest-playback';
await jestPlayback.setup({ mode: jestPlayback.Mode.Auto });

import * as src from './src'

// do tests

when i run the test in jest,

node --experimental-vm-modules node_modules/.bin/jest test.ts

 FAIL  test.test.ts
  test
    ✕  happy path (1364 ms)

  ● test ›  happy path

    AxiosError: Request failed with status code 401

      at settle (node_modules/axios/lib/core/settle.js:19:12)
      at PassThrough.handleStreamEnd (node_modules/axios/lib/adapters/http.js:589:11)

test.ts.snap

// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`test happy path: (jest-playback) 86230859c6 1`] = `
NONE/11 401 Unauthorized
cf-cache-status: DYNAMIC
cf-ray: 8492d7c0ac274211-EWR
connection: keep-alive
content-type: text/html; charset=UTF-8
date: Sun, 21 Jan 2024 22:02:40 GMT
server: cloudflare
set-cookie: _cfuvid=2q37XoAAhzrdz.kcRy9F4Jjf6lAhpOxuqI92YqyvaMU-1705874560244-0-604800000; path=/; domain=.bamboohr.com; HttpOnly; Secure; SameSite=None
strict-transport-security: max-age=31536000; includeSubDomains; preload
transfer-encoding: chunked
x-frame-options: SAMEORIGIN
x-session-invalid: true
`;
@skilbjo
Copy link
Author

skilbjo commented Jan 21, 2024

actually - it's probably this line that is messing with the test ...

import { wrapper } from 'axios-cookiejar-support';

wrapper(axios);

i imagine that axios is not registering that when await jestPlayback.setup({ ... }) is enabled ?

reason i say that is i use a jar which authenticates the requests -- if a jar is not passed in, the server rejects with a 401. so it must be something about jest-playback (more likely @mswjs/interceptors) internals that is not working with axios-cookiejar-support ?

@skilbjo skilbjo changed the title Working with axios ? Working with axios-cookiejar-support ? Jan 21, 2024
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

No branches or pull requests

1 participant