filer/tests/spec
..
node-js/simple
providers
shell
shims
webpack-plugin
errors.spec.js
filer.buffer.spec.js
filer.filesystem.spec.js
filer.spec.js
fs.access.spec.js
fs.appendFile.spec.js
fs.chmod.spec.js
fs.chown.spec.js
fs.close.spec.js
fs.copyFile.spec.js
fs.exists.spec.js
fs.fsync.spec.js
fs.ftruncate.spec.js
fs.link.spec.js
fs.lseek.spec.js
fs.lstat.spec.js
fs.mkdir.spec.js
fs.mkdtemp.spec.js
fs.mknod.spec.js
fs.open.spec.js
fs.read.spec.js
fs.readdir.spec.js
fs.readlink.spec.js
fs.rename.spec.js
fs.rmdir.spec.js
fs.shell.spec.js
fs.spec.js
fs.stat.spec.js
fs.symlink.spec.js
fs.truncate.spec.js
fs.unlink.spec.js
fs.unwatchFile.spec.js
fs.utimes.spec.js
fs.watch.spec.js
fs.write.spec.js
fs.writeFile-readFile.spec.js
fs.xattr.spec.js
path-resolution.spec.js
readme.example.spec.js
time-flags.spec.js
times.spec.js
trailing-slashes.spec.js

readme.example.spec.js

const { path } = require('../../src');
var util = require('../lib/test-utils.js');
var expect = require('chai').expect;

describe('README example code', function() {
  beforeEach(util.setup);
  afterEach(util.cleanup);

  it('should run the code in the README overview example', function(done) {
    // Slightly modified version of the first example code in the README
    // See <a name="overviewExample"></a>
    const fs = util.fs();

    fs.mkdir('/docs', (err) => {
      if (err) throw err;
      
      const filename = path.join('/docs', 'first.txt');
      const data = 'Hello World!\n';
    
      fs.writeFile(filename, data, (err) => {
        if (err) throw err;
    
        fs.stat(filename, (err, stats) => {
          if (err) throw err;
          expect(stats.size).to.equal(data.length);
          done();
        });
      });
    });
  });

  it('should run the fsPromises example code', function() {
    const fs = util.fs().promises;
    const filename = '/myfile';
    const data = 'some data';

    return fs.writeFile(filename, data)
      .then(() => fs.stat(filename))
      .then(stats => { 
        expect(stats.size).to.equal(data.length);
      });
  });
});