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

NockBack fails to read recorded fixture in [email protected] and above #2806

Open
2 tasks done
techxplorer opened this issue Nov 16, 2024 · 1 comment
Open
2 tasks done
Labels

Comments

@techxplorer
Copy link

Please avoid duplicates

Reproducible test case

Apologies for not creating a RunKit working example, I wasn't sure how to do that with recording of fixtures.

Nock Version

[email protected]

Node Version

v23.2.0

TypeScript Version

No response

What happened?

I'm using NockBack in lockdown mode as part of my test suite. I'm using the beta version because I want to use native fetch.

My test suite started to fail with the release of [email protected]

The parsing of the recorded artefact fails.

The reported error is a Z_DATA_ERROR with the below stack trace:

TypeError
    at handleKnownInternalErrors (node:internal/webstreams/adapters:115:21)
    at Gunzip.<anonymous> (node:internal/webstreams/adapters:476:13)
    at Gunzip.<anonymous> (node:internal/util:542:20)
    at Gunzip.onerror (node:internal/streams/end-of-stream:136:14)
    at Gunzip.emit (node:events:519:35)
    at emitErrorNT (node:internal/streams/destroy:170:8)
    at emitErrorCloseNT (node:internal/streams/destroy:129:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:90:21)

I've tried deleting and re-creating the fixtures without success.

My code to use the native fetch looks like this:

 async fetchData() {

    try {
      const response = await fetch( this.urlToFetch );
      if ( !response.ok ) {
        throw new Error( `Response status: ${ response.status }` );
      }

      this.fetchedStatusData = await response.json();

    } catch ( error ) {
      throw new Error( error );
    }
  }

My test looks like this:

import nock from "nock";
import path from "node:path";

const nockArtefacts = path.resolve( "tests/artefacts/nock" );
const nockBack = nock.back;

describe( "fetchData", async() => {
  before( () => {
    nockBack.fixtures = nockArtefacts;
    nockBack.setMode( "lockdown" );
  } );

  it( "should successfully fetch the user data JSON object", async() => {
    const fetcher = new FetchStatuses(
      testPassFQDN,
      testPassUserId
    );

    assert.equal(
      fetcher.fetchedStatusData,
      null
    );

    const { nockDone } = await nockBack( "user-statuses.json" );

    await fetcher.fetchData();

    nockDone();

    assert.notEqual(
      fetcher.fetchedStatusData,
      null
    );

  } );

} );

The exact same code works as expected with [email protected]

I'm keen to help in any way that I can.

Would you be interested in contributing a fix?

  • yes
@mikicho
Copy link
Contributor

mikicho commented Nov 16, 2024

I ran Nock's tests using Node v23, and they were successful. Could you please share a more straightforward example? something I can easily run online or on my computer without unnecessary external dependencies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants