test("recurse root (files should not contain multiple /)", async () => { mock({ "/": { etc: { hosts: "dooone", }, }, }); const api = new fdir().normalize().crawl("/"); const files = await api[type](); expect(files.every((file) => !file.includes("/"))).toBe(true); mock.restore(); });
describe('using snapshot', () => { const mock = require('mock-fs') const snapshot = require('snap-shot') beforeEach(() => { mock(fakeFileSystem) }) it('restores FS before trying to load snapshot', () => { return readFiles('foo/b.txt', 'baz.txt').then(text => { // restore file system _before_ snapshot tries to // load previous snapshot file mock.restore() snapshot(text) }) }) })
// ------------------------------------------------------------- // Setup. // ------------------------------------------------------------- beforeEach(() => { mock(fakeFileSystem) })
it('should not return build when package.json does not exist', function (done) { // The behaviour of a package.json empty is the same as if file doesn't exists mock({ 'package.json': '' }) request(app) .get('/info') .end(function (err, res) { if (err) return err expect(res.statusCode).to.equal(200) expect(res.headers['content-type']).to.equal('application/json; charset=utf-8') expect(res.body.build).to.be.undefined() expect(res.body.git).to.be.undefined() done() }) })
describe('#save()', function ƒ() { 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(); }); });
describe('mocks several files by create a file system', () => { const mock = require('mock-fs') beforeEach(() => { mock(fakeFileSystem) }) afterEach(() => { mock.restore() }) it('several files', () => { return readFiles('foo/bar/a.txt', 'foo/b.txt', 'baz.txt').then(text => { console.assert(text.includes('foo/b.txt')) }) }) })
mock({ file: '{ \ "fileVersion": 1,\
mock({ 'package.json': '{"name":"testName","description":"testDescription","version":"1.0.0"}', 'git.properties': 'git.branch=master\ngit.commit.id.abbrev=1a24c24\ngit.commit.time=2016-11-18T13:16:39.000Z'
it('should return build and git when package.json and git.properties exists', function (done) { mock({ 'package.json': '{"name":"testName","description":"testDescription","version":"1.0.0"}', 'git.properties': 'git.branch=master\ngit.commit.id.abbrev=1a24c24\ngit.commit.time=2016-11-18T13:16:39.000Z' }) request(app) .get('/info') .end(function (err, res) { if (err) return err expect(res.statusCode).to.equal(200) expect(res.headers['content-type']).to.equal('application/json; charset=utf-8') expect(res.body.build.name).to.equal('testName') expect(res.body.build.description).to.equal('testDescription') expect(res.body.build.version).to.equal('1.0.0') expect(res.body.git.branch).to.equal('master') expect(res.body.git.commit.id).to.equal('1a24c24') expect(res.body.git.commit.time).to.equal('2016-11-18T13:16:39.000Z') done() }) })
mock(); });
mock({ 'package.json': '{"name":"testName","description":"testDescription","version":"1.0.0"}', 'git.properties': 'git.commit.id.abbrev=42954d1\n' +
it('should return build when package.json exists and git.properties doesn\'t', function (done) { mock({ './package.json': '{"name":"testName","description":"testDescription","version":"1.0.0"}' }) request(app) .get('/info') .end(function (err, res) { if (err) return err expect(res.statusCode).to.equal(200) expect(res.headers['content-type']).to.equal('application/json; charset=utf-8') expect(res.body.build.name).to.equal('testName') expect(res.body.build.description).to.equal('testDescription') expect(res.body.build.version).to.equal('1.0.0') expect(res.body.git).to.be.undefined() done() }) })
mock({ 'package.json': '{"name":"testName","description":"testDescription","version":"1.0.0"}' })