tschaub / mock-fs

Configurable mock for the fs module
https://npmjs.org/package/mock-fs
Other
908 stars 86 forks source link

Issue with CodeBuild. Tests stops. #269

Open IgorSkobelev opened 5 years ago

IgorSkobelev commented 5 years ago

First of all, thank you for this module. It is awesome!

I've faced with issue when trying to run tests that uses mock-fs on AWS CodeBuild.

Node version: 10.14.1 mock-fs version: 4.7.0 ( 4.9.0 issue reproduced as well )

I have simple test:

const chai = require('chai');
const fs = require('fs');
const mockFS = require('mock-fs');
const Parser = require('../parser');

describe('mock-section', () => {
    context('test runner', () => {
        afterEach(() => {
            mockFS.restore();
        })
        it('parse mocked file system', () => {
            console.log('before');
            mockFS({
                'dir': {
                    'file1': '{"key1": "value1"}'
                }
            });
            console.log('after');
            const data = Parser.parseFile(`dir/file1`);
            chai.expect(data.key1).to.be.equal('value1');
        })
    });
});

when I run it on my local machine it works well ( MacOS, Linux ), but when I run it on CodeBuild tests stops on calling of mockFS(). Bird-eye debugging showed, that tests become freeze in overrideBinding function in mock-fs/lib/index.js when it try override writeBuffer function.

function overrideBinding(binding) {
  for (var key in binding) {
    if (typeof binding[key] === 'function') {

      // **TEST STOPS HERE WHEN KEY IS EQUAL writeBuffer**
      realBinding[key] = binding[key].bind(binding);

    } else {
      realBinding[key] = binding[key];
    }
  }
}

So as result output of test on CodeBuild looks like

...
[Container] 2019/05/08 11:42:17 Running command npm run test 

> mock-fs-test@1.0.0 test /codebuild/output/src540903502/src/git-codecommit.us-west-2.amazonaws.com/v1/repos/mock-fs-test 
> NODE_ENV=test ./node_modules/mocha/bin/mocha --recursive test/** 

  mock-section 
    test runner 
before 

[Container] 2019/05/08 11:42:18 Phase complete: BUILD State: SUCCEEDED
...

UPD. : There is really suitable tool to debug without AWS account https://aws.amazon.com/blogs/devops/announcing-local-build-support-for-aws-codebuild/ https://docs.aws.amazon.com/codebuild/latest/userguide/use-codebuild-agent.html

Thank you in advance!

oscar-ardila-admios commented 3 years ago

I'm seeing this issue too with 4.10.2 version.

3cp commented 3 years ago

Please try the last v4.14.0. It changed the way the binding is patched.