Ejemplo n.º 1
0
        it("should create directory if necessary", function () {
            fs.existsSync.returns(false);
            pidfiles.writePidFileSync(PIDS_DIR, "master", 0);

            mkdirp.sync.calledOnce.should.be.ok;
            mkdirp.sync.calledWith(PIDS_DIR).should.be.ok;

            fs.writeFileSync.calledOnce.should.be.ok;
            fs.writeFileSync.calledWith(path.join(PIDS_DIR, "master.pid"), "0").should.be.ok;
        });
Ejemplo n.º 2
0
test('saves the state to the file system', t => {
  const win = {
    getBounds: sinon.stub().returns({
      x: 100,
      y: 100,
      width: 500,
      height: 500
    }),
    isMaximized: sinon.stub().returns(false),
    isMinimized: sinon.stub().returns(false),
    isFullScreen: sinon.stub().returns(false)
  };

  const screenBounds = {x: 0, y: 0, width: 100, height: 100};

  const mkdirp = require('mkdirp');
  sinon.spy(mkdirp, 'sync');

  const jsonfile = require('jsonfile');
  sinon.spy(jsonfile, 'writeFileSync');

  const screen = require('electron').screen;
  sinon.stub(screen, 'getDisplayMatching').returns({bounds: screenBounds});

  const state = require('./')({defaultWidth: 1000, defaultHeight: 2000});
  state.saveState(win);

  t.ok(mkdirp.sync.calledOnce);
  t.ok(jsonfile.writeFileSync.calledWith('/temp/window-state.json', {
    x: 100,
    y: 100,
    width: 500,
    height: 500,
    isMaximized: false,
    isFullScreen: false,
    displayBounds: screenBounds
  }));

  jsonfile.writeFileSync.restore();
  screen.getDisplayMatching.restore();
  mkdirp.sync.restore();
});
Ejemplo n.º 3
0
// Returns an Array of filenames matching the pattern
file.expand = function expand(pattern, options) {
  return glob.sync(pattern, options);
};

// Performs a glob search with the provided `pattern` and optional Hash of
// `options`, filtering results to only return files (not directories). Options
// can be any option supported by
// [glob](https://github.com/isaacs/node-glob#options)
//
// - pattern  - Glob String pattern to look for
// - options  - Hash of options matching glob's option.
//
// Returns an Array of filenames matching the pattern
file.expandFiles = function expandFiles(pattern, options) {
  var cwd = options.cwd || process.cwd();
  return this.expand(pattern, options).filter(function(filepath) {
    return fs.statSync(path.join(cwd, filepath)).isFile();
  });
};

// Checks a given file path being absolute or not. Borrowed to grunt's file API.
file.isPathAbsolute = function() {
  var filepath = path.join.apply(path, arguments);
  return path.resolve(filepath) === filepath;
};


// simple facade to mkdirp.sync
file.mkdir = mkdirp.sync.bind(mkdirp);
Ejemplo n.º 4
0
 afterEach(function () {
     fs.existsSync.restore();
     fs.writeFileSync.restore();
     mkdirp.sync.restore();
 });
Ejemplo n.º 5
0
 mkdir: function () {
   mkdirp.sync.apply(mkdirp, arguments);
 },