Skip to content

Commit

Permalink
Update: Surface errors from modules loaded by --require flag (#176)
Browse files Browse the repository at this point in the history
  • Loading branch information
smialy authored and phated committed Feb 23, 2019
1 parent 4782b9a commit 7d9d1a0
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 7 deletions.
10 changes: 8 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,14 @@ cli.on('require', function(name) {
log.info('Requiring external module', ansi.magenta(name));
});

cli.on('requireFail', function(name) {
log.warn(ansi.yellow('Failed to load external module'), ansi.magenta(name));
cli.on('requireFail', function(name, error) {
log.warn(
ansi.yellow('Failed to load external module'),
ansi.magenta(name)
);
if (error) {
log.warn(ansi.yellow(error.toString()));
}
});

cli.on('respawn', function(flags, child) {
Expand Down
2 changes: 1 addition & 1 deletion test/exports-as-tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('exports as tasks', function() {
var filepath = path.join(expectedDir, 'tasks-as-exports.txt');
var expected = fs.readFileSync(filepath, 'utf-8');
// Remove babel/register lines
stdout = eraseTime(skipLines(stdout, 3));
stdout = eraseTime(skipLines(stdout, 4));
expect(stdout).toEqual(expected);
done(err);
}
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/test-error-module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
throw new Error('from error module');
console.log('inside error module');
47 changes: 43 additions & 4 deletions test/flags-require.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,55 @@ describe('flag: --require', function() {
expect(stderr).toEqual('');
stdout = eraseLapse(eraseTime(stdout));
expect(stdout).toMatch('Failed to load external module ./null-module.js');
expect(stdout).toMatch('Error: Cannot find module \'./null-module.js\'');
expect(stdout).toNotMatch('inside test module');
expect(stdout).toNotMatch(
'Requiring external module ../test-module.js');
expect(stdout).toNotMatch('Requiring external module ../test-module.js');

var chgWorkdirLog = headLines(stdout, 2);
var chgWorkdirLog = headLines(stdout, 3);
var workdir = 'test/fixtures/gulpfiles'.replace(/\//g, path.sep);
expect(chgWorkdirLog).toMatch('Working directory changed to ');
expect(chgWorkdirLog).toMatch(workdir);

stdout = eraseLapse(eraseTime(skipLines(stdout, 3)));
stdout = eraseLapse(eraseTime(skipLines(stdout, 4)));
expect(stdout).toEqual(
'Starting \'default\'...\n' +
'Starting \'test1\'...\n' +
'Starting \'noop\'...\n' +
'Finished \'noop\' after ?\n' +
'Finished \'test1\' after ?\n' +
'Starting \'test3\'...\n' +
'Starting \'described\'...\n' +
'Finished \'described\' after ?\n' +
'Finished \'test3\' after ?\n' +
'Starting \'noop\'...\n' +
'Finished \'noop\' after ?\n' +
'Finished \'default\' after ?\n' +
''
);

done(err);
}
});

it('warns if module throw some error', function(done) {
runner({ verbose: false })
.gulp('--require ../test-error-module.js', '--cwd ./test/fixtures/gulpfiles')
.run(cb);

function cb(err, stdout, stderr) {
stdout = eraseLapse(eraseTime(stdout));
expect(err).toEqual(null);
expect(stderr).toEqual('');
expect(stdout).toMatch('Failed to load external module ../test-error-module.js');
expect(stdout).toMatch('Error: from error module');
expect(stdout).toNotMatch('inside error module');

var chgWorkdirLog = headLines(stdout, 3);
var workdir = 'test/fixtures/gulpfiles'.replace(/\//g, path.sep);
expect(chgWorkdirLog).toMatch('Working directory changed to ');
expect(chgWorkdirLog).toMatch(workdir);

stdout = eraseLapse(eraseTime(skipLines(stdout, 4)));
expect(stdout).toEqual(
'Starting \'default\'...\n' +
'Starting \'test1\'...\n' +
Expand Down

0 comments on commit 7d9d1a0

Please sign in to comment.