Example #1
0
 it("Log error information", () => {
     mock({
         "error.log": ""
     });
     const log = logError("error.log");
     log(new Error("error"));
     const results = fs.readFileSync("error.log", "utf8");
     expect(
         /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\nError: error[\s\S]+/.test(results)
     ).toBeTruthy();
     mock.restore();
 });
Example #2
0
        renamer.renameImage('image.jpg', function testRenamed(err) {
            should.not.exist(err);

            // see if file renamed correctly
            var newFileName = fs.readdirSync('.')[0];
                newFileName.should.equal('2011-12-31T18-07-29C23a0f622');

            // restore original fs
            mockfs.restore();

            done();
        });
Example #3
0
      it('Outputs the correct key', () => {
        let customOutput = {
          foo: [
            'src/apps/page1.js',
            'src/apps/page2.js',
            'src/apps/page3.js'
          ]
        };

        mockFS(customTree);
        expect(getEntries(customRoot, '.js', 'foo')).to.deep.equal(customOutput);
        mockFS.restore();
      });
        splitter.writeToFiles(parts, paths, true, function(err) {
            t.error(err, 'error argument should be empty');

            for (var key in contents) {
                t.notEqual(
                    contents[key],
                    fs.readFileSync('/some/path/' + key, { encoding: 'utf8' }),
                    'contents of ' + key + ' should have changed'
                );
            }
            mockfs.restore();
            t.end();
        });
Example #5
0
test('info with browserslist file', function (t) {
  mock({
    'browserslist': '# Comment\nSafari 8\nIE >= 11'
  })

  var actual = doiuse({}).info().browsers
  var expected = [['ie', '11'], ['safari', '8']]

  t.deepEqual(actual, expected)

  mock.restore()

  t.end()
})
Example #6
0
 const checkRemoved = function checkRemoved(tt) {
     const files = fs.readdirSync(joysetupDir);
     tt.equal(files.length, 7);
     const remainingTools = files.filter(isCNTools);
     const remainingOther = files.filter(function (p) {
         return (!isCNTools(p));
     });
     tt.deepEqual(remainingTools.slice().sort(),
                  cnTools.slice().sort());
     tt.deepEqual(remainingOther.slice().sort(),
                  Object.keys(stdFiles).sort());
     mockfs.restore();
     tt.end();
 };
Example #7
0
    it('it should raise and exception on invalid config', function ƒ() {

      mock({
        file: 'invalid'
      });

      var config = new ConfigManager();
      expect(function ƒ() {
        config.load('file');
      }).to.throw(Error, /InvalidConfig/);

      mock.restore();

    });
    it('should send a payload when process.env.npm_package_name does not exists and git.properties exists', function () {
        var infoRouteRewire = rewire("../../../lib/infoRoute");
        infoRouteRewire.__set__("envPackageName", null);

        mock({
          'git.properties': "git.branch=master\ngit.commit.id.abbrev=1324324\ngit.commit.time=2016-11-18T13:16:39.000Z",
          'package.json': "\{\"name\":\"eor\"\}"
        });

        infoRouteRewire(null, response);

        expect(response.json).to.have.been.calledOnce;
        expect(response.json).to.have.property('name');

        mock.restore();
    });
Example #9
0
 it("Get directories", () => {
     mock({
         dir1: {
             d1: {},
             f1: "file"
         },
         dir2: {}
     });
     expect(
         arrayAreEqual(getDirectories("dir1"), ["d1"])
     ).toBeTruthy();
     expect(
         arrayAreEqual(getDirectories("dir2"), [])
     ).toBeTruthy();
     mock.restore();
 });
    splitter.writeToFiles(parts, paths, true, function (err) {
      t.error(err, 'error argument should be empty')

      for (var contentKey in contents) {
        if (contents.hasOwnProperty(contentKey)) {
          t.notEqual(
            contents[contentKey],
            fs.readFileSync('/some/path/' + contentKey, {encoding: 'utf8'}),
            'contents of ' + contentKey + ' should have changed'
          )
        }
      }

      mockfs.restore()
      t.end()
    })
Example #11
0
test('malformed repository', function() {
  mock(mockRepo.malformed);

  expect(
    evaluate(function() {
      /**
       * get one
       * @returns {number} one
       */
      function getOne() {
        return 1;
      }
    })[0].context.github
  ).toBe(undefined);

  mock.restore();
});
Example #12
0
 it("Get files", () => {
     mock({
         dir1: {
             d1: {},
             "f1.md": "file",
             f2: "file"
         },
         dir2: {}
     });
     expect(
         arrayAreEqual(getFiles("dir1"), ["f1"])
     ).toBeTruthy();
     expect(
         arrayAreEqual(getFiles("dir2"), [])
     ).toBeTruthy();
     mock.restore();
 });
Example #13
0
    it('it should convert an old config file', function ƒ() {

      var oldApiKey = '12345678901234567890123456789012';

      mock({
        file: oldApiKey
      });

      var config = new ConfigManager();
      config.load('file');

      config.options.should.be.an('object');
      config.options.apiKey.should.be.equal(oldApiKey);
      expect(config.options.secret).to.be.null;
      expect(config.options.authUrl).to.be.null;

      mock.restore();
    });
Example #14
0
    it('it should be initialized with a path', function ƒ() {

      mock({
        file: '{ \
          "fileVersion": 1,\
          "apiKey": "someKey",\
          "secret": "someSecret",\
          "authUrl": "someUrl"\
        }'
      });

      var config = new ConfigManager('file');
      config.options.should.be.an('object');
      config.options.apiKey.should.be.equal('someKey');
      config.options.secret.should.be.equal('someSecret');
      config.options.authUrl.should.be.equal('someUrl');

      mock.restore();
    });
Example #15
0
test('github', function() {
  mock(mockRepo.master);

  expect(
    evaluate(function() {
      /**
       * get one
       * @returns {number} one
       */
      function getOne() {
        return 1;
      }
    })[0].context.github
  ).toEqual({
    path: 'index.js',
    url: 'https://github.com/foo/bar/blob/this_is_the_sha/index.js#L6-L8'
  });

  mock.restore();
});
Example #16
0
    it('should create a directory if tmpDir is same as appDir', function(done) {
        mockFs();

        listOfNumbers(10).map(String).forEach(function(num){
            var path = tmpDir(num);


            var parent = pathLib.join(path, '..', '..');
            var appDir = pathLib.join(__dirname, '..', '..');

            expect(parent).to.equal(appDir);

            fs.mkdirSync(path);
            var content = fs.readdirSync(pathLib.join(path, '..'));
            expect(content.length).to.equal(num*1);
        });
        mockFs.restore();

        done();
    });
    it('should return build and git when git.properties exists', function (done) {
        mock({
          'git.properties': "\{git.branch=master\ngit.commit.id=1324324\ngit.commit.time=1478086940000\}"
        });

        request.get('/info')
            .expect(200)
            .expect('Content-Type', /json/)
            .expect(function(res) {
                expect(res.body.build.name).to.not.be.null,
                expect(res.body.build.description).to.not.be.null,
                expect(res.body.build.version).to.not.be.null,
                expect(res.body.git.branch).to.equal('master'),
                expect(res.body.git.commit.id).to.equal('1324324'),
                expect(res.body.git.commit.time).to.equal('1478086940000')
            })

        mock.restore();

        done();
    });
Example #18
0
    it('it should persist config on file', function ƒ() {

      // TODO

      mock({
        file: ''
      });

      // save a new config
      var config1 = new ConfigManager();
      config1.options.apiKey = 'newApiKey';
      config1.save('file');

      // load a new instance with the previously saved config
      var config2 = new ConfigManager('file');

      // check if the 2 configs have the same data
      config2.options.should.deep.equal(config1.options);

      mock.restore();

    });
Example #19
0
 afterEach(function () {
     mock.restore();
 });
function read(f) {
    return JSON.parse(fs.readFileSync(f).toString())
}

if (require.main != module) {
    // Patch _resoveFilename to try to resolve components first,
    // falling back to node modules.
    Module._resolveFilename = function(request, parent) {
        try {
            return _resolveFilename(request, parent)
        } catch (e) {
            return componentResolve(request, parent)
        }
    }
}

// Test
if (require.main === module) {
    var assert = require("better-assert")
    var mock = require('mock-fs');
    mock({
      '/test/some/path/component.json': '{"dependencies": {"karlbohlmark/my-module": "*"}}',
      '/test/some/path/components/karlbohlmark/my-module/0.0.1/component.json': '{"main": "start.js"}'
    });
    var parentModule = {
        filename: "/test/some/path/module.js"
    }
    var moduleEntryPath = componentResolve('my-module', parentModule);
    assert(moduleEntryPath, "/test/some/path/components/karlbohlmark/my-module/start.js");
    mock.restore()
}
Example #21
0
 after(function() {
     mockFs.restore();
 });
Example #22
0
 afterEach(() => {
   mockFs.restore();
 });
Example #23
0
 after(function () {
   _.values(inputStreams).forEach(endStream);
   inputStreams = null;
   outputStream = null;
   mockFs.restore();
 });
 afterEach(function() {
   config.log = originalLogConfig;
   mock.restore();
 });
 .end(function() {
   mockfs.restore();
   done();
 });
Example #26
0
 afterEach(() => {
   mockfs.restore(); //restore file system
   process.env = {}; //reset process.env
 });
Example #27
0
test.afterEach(t => {
    mockFs.restore();

    t.context.flatStub.restore();
    t.context.nestedStub.restore();
});
Example #28
0
 afterEach(() => {
   mockFs.restore();
   sandbox.restore();
 });
 afterEach(function () {
     delete global.text;
     mock.restore();
 });
 after(function() {
   mockfs.restore();
   infoStub.restore();
   errorStub.restore();
 });