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

async function hangs indefinitely? #348

Open
isaaclem90 opened this issue Jan 17, 2022 · 1 comment
Open

async function hangs indefinitely? #348

isaaclem90 opened this issue Jan 17, 2022 · 1 comment

Comments

@isaaclem90
Copy link

First of all thanks for this awesome library! I have met some problem as below and would appreciate if you can help shed some light

import fsPromises from 'fs/promises';

const createFolder = async (target: string) => {
  await fsPromises.mkdir(target, { recursive: true });
};

The above code is pretty straight forward, which takes in target, and create the folder recursively.

Now I'm trying unit test as below

import {createFolder} from './xx';
import mock from 'mock-fs';
import fs from 'fs';

describe('createFolder()', () => {
  beforeAll(() => {
    mock(
      {
        sourceFolder: {
          'index.md': 'abc',
        },
      },
      { createCwd: true, createTmp: true }
    );
  });

  afterAll(() => {
    mock.restore();
  });

  it('creates folder successfully', async () => {
    await createFolder(
      `${process.cwd()}/destinationFolder`
    );

    expect(fs.existsSync(`${process.cwd()}/destinationFolder`)).toBeTruthy();
  });
});

When the above code ran, it will hang all the way till timeout, can anyone share what's wrong with it?

@saiichihashimoto
Copy link

I'm having the same issue with fsPromises.readFile.

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

2 participants