Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show error info for --require param problem #176

Merged
merged 3 commits into from
Feb 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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