gypwatcher
Version:
Automatically run node-gyp when your module's C++ files change
73 lines (49 loc) • 2.02 kB
JavaScript
;
const _ = require('lodash');
const ChildProcess = require('child_process');
const Path = require('path');
const GypWatcher = require('..');
const Module = require('./');
describe('GypWatcher', function() {
let defaultConfig = newConfig();
let watcher = new GypWatcher(defaultConfig);
describe('#constructor', () => {
it('should select the current working directory', () => process.cwd().should.be.eql(watcher.cwd));
it('should set the config', () => watcher.config.should.be.eql(defaultConfig));
it('should format watch files properly', () => {
let config = newConfig({ watchFiles: [ './abc', '/etc' ] });
let watcher = new GypWatcher(config);
watcher.watchFiles.forEach(file => /^\//.test(file).should.be.ok);
});
it('should find a node-gyp executable', () => /node-gyp/.test(defaultConfig.nodeGypScript).should.be.ok);
it('should have a node-gyp post function', () => {
watcher.postExec.should.be.a.function;
let config = newConfig({nodeGypPost: './postExec'});
let watcher2 = new GypWatcher(config);
watcher2.postExec.should.be.a.function;
config = newConfig({nodeGypPost: null});
let watcher3 = new GypWatcher(config);
(null === watcher3.postExec).should.be.true;
});
it('should have initialized a watcher', () => watcher.watcher.should.be.an.object);
});
describe('#watch', () => {
it('should begin watching the current directory', () => {
watcher.watch();
});
it('should run node-gyp when the C++ files change', (done) => {
this.timeout(5000);
// cause C++ file to change
ChildProcess.execSync('touch Module.cc', {cwd: watcher.cwd});
// wait for node-gyp to finish running
watcher.on('finished', () => {
// check that post exec ran
watcher.didRun.should.be.true;
done();
});
});
});
});
function newConfig(config) {
return _.merge({}, require('../config'), require('./gypwatcher'), config);
}