Skip to content

Commit

Permalink
test: resolving failing tests
Browse files Browse the repository at this point in the history
Fixes #2122

Removed test related to old nodemon config format, and updated default
watch extensions if undefined
  • Loading branch information
remy committed Jul 9, 2023
1 parent e4c163f commit af74bdb
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 49 deletions.
54 changes: 39 additions & 15 deletions test/cli/exec.test.js
Expand Up @@ -10,12 +10,12 @@ const utils = require('../../lib/utils');
function toCmd(options) {
var cmd = command({
script: options.script || 'app.js',
execOptions: options
execOptions: options,
});

return {
cmd: cmd,
string: utils.stringify(cmd.executable, cmd.args)
string: utils.stringify(cmd.executable, cmd.args),
};
}

Expand All @@ -34,17 +34,17 @@ describe('expandScript', () => {
it('should expand app.js', () => {
const script = expandScript('app');
assert.equal(script, 'app.js', script);
})
});

it('should expand hello.py', () => {
const script = expandScript('hello', '.py');
assert.equal(script, 'hello.py', script);
})
});

it('should ignore foo.js', () => {
const script = expandScript('foo', '.js');
assert.equal(script, 'foo', script);
})
});
});

describe('nodemon exec', function () {
Expand All @@ -63,7 +63,7 @@ describe('nodemon exec', function () {
var options = exec({ script: 'index.js' });
var cmd = toCmd(options);
assert.equal(options.exec, 'node', 'exec is node');
assert.equal(options.ext, 'js,mjs,json');
assert.equal(options.ext, 'js,mjs,cjs,json');
assert.equal(cmd.string, 'node index.js', cmd.string);
});

Expand Down Expand Up @@ -95,7 +95,11 @@ describe('nodemon exec', function () {

it('should support watching all extensions', function () {
var options = exec({ script: 'app.js', ext: '' });
assert.equal(options.ext, '', 'does not set default extensions when empty extension requested');
assert.equal(
options.ext,
'',
'does not set default extensions when empty extension requested'
);

options = exec({ script: 'app.js', ext: '.' });
assert.equal(options.ext, '', 'treats `.` as wildcard extension');
Expand All @@ -104,45 +108,66 @@ describe('nodemon exec', function () {
assert.equal(options.ext, '', 'treats `*` as wildcard extension');

options = exec({ script: 'app.coffee', exec: 'coffee', ext: '' });
assert.equal(options.ext, '', 'does not set default extensions when empty extension requested');
assert.equal(
options.ext,
'',
'does not set default extensions when empty extension requested'
);
});

it('should replace {{filename}}', function () {
var options = exec({ script: 'app.js', exec: 'node {{filename}}.tmp --somethingElse' });
var options = exec({
script: 'app.js',
exec: 'node {{filename}}.tmp --somethingElse',
});

var cmd = toCmd(options);
assert(cmd.string === 'node app.js.tmp --somethingElse', cmd.string);
});

it('should not split on spaces in {{filename}}', function () {
var options = exec({ script: 'my app.js', exec: 'node {{filename}}.tmp --somethingElse' });
var options = exec({
script: 'my app.js',
exec: 'node {{filename}}.tmp --somethingElse',
});
var cmd = toCmd(options);
// var cmd = command({ execOptions: options });

assert(cmd.string === 'node my app.js.tmp --somethingElse', cmd.string);
});

it('should support extension maps', function () {
var options = exec({ script: 'template.pug' }, { 'pug': 'pug {{filename}} --out /tmp' });
var options = exec(
{ script: 'template.pug' },
{ pug: 'pug {{filename}} --out /tmp' }
);
var cmd = toCmd(options);
assert(cmd.string === 'pug template.pug --out /tmp', cmd.string);
});

it('should support input from argv#parse', function () {
var parse = require('../../lib/cli/parse');
parse('node /usr/local/bin/nodemon.js --debug -e js,pug,hbs app.js'.split(' '));
parse(
'node /usr/local/bin/nodemon.js --debug -e js,pug,hbs app.js'.split(' ')
);
});

it('should use coffeescript on .coffee', function () {
var options = exec({ script: 'index.coffee' });
assert(options.exec.indexOf('coffee') === 0, 'using coffeescript to execute');
assert(
options.exec.indexOf('coffee') === 0,
'using coffeescript to execute'
);
assert(options.ext.indexOf('coffee') !== -1);
});

it('should support coffeescript in debug mode', function () {
var options = exec({ script: 'app.coffee', nodeArgs: ['--debug'] });

assert(options.exec.indexOf('coffee') === 0, 'using coffeescript to execute');
assert(
options.exec.indexOf('coffee') === 0,
'using coffeescript to execute'
);
assert(options.execArgs[1].indexOf('--debug') !== -1);
assert(options.ext.indexOf('coffee') !== -1);
});
Expand Down Expand Up @@ -219,5 +244,4 @@ describe('nodemon exec', function () {
var cmd = toCmd(options);
assert(cmd.string === 'node index', cmd.string);
});

});
34 changes: 0 additions & 34 deletions test/monitor/match.test.js
Expand Up @@ -220,40 +220,6 @@ describe('match', function () {
);
});

it('should support old .nodemonignore', function (done) {
// prevents our test from finding the nodemon.json files
var pwd = process.cwd(),
old = nodemonUtils.home;

process.chdir(path.resolve(pwd, 'test/fixtures/legacy'));
nodemonUtils.home = path.resolve(pwd, 'test/fixtures/legacy');

// will load the legacy file format
config.load({ script: utils.appjs, ext: 'js json' }, function (config) {
var files = [utils.appjs];
var result = match(
files,
config.options.monitor,
config.options.execOptions.ext
);

assert.deepEqual(result.result, files, 'allows app.js: ' + result.result);

files = [path.resolve(pwd, 'test/fixtures/app.json')];
result = match(
files,
config.options.monitor,
config.options.execOptions.ext
);

assert.deepEqual(result.result, [], 'nothing matched' + result.result);

process.chdir(pwd);
nodemonUtils.home = old;
done();
});
});

it('should be specific about directories', function (done) {
config.load(
{
Expand Down

0 comments on commit af74bdb

Please sign in to comment.