Skip to content

Commit daec34d

Browse files
committed
Adding a test
1 parent 97afca1 commit daec34d

File tree

3 files changed

+61
-13
lines changed

3 files changed

+61
-13
lines changed

lib/friendly-errors/formatters/missing-loader.js

+1-8
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,8 @@ function formatErrors(errors) {
5151

5252
messages.push('');
5353
}
54-
return messages;
55-
56-
var msg = chalk.bgGreen.black('', 'WOH', '');
5754

58-
return [
59-
msg,
60-
'Hi',
61-
'Hello'
62-
];
55+
return messages;
6356
}
6457

6558
function format(errors) {

lib/friendly-errors/transformers/missing-loader.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ function transform(error) {
2424
return error;
2525
}
2626

27+
error = Object.assign({}, error);
28+
2729
const extension = getFileExtension(error.file);
2830
switch (extension) {
2931
case 'sass':
@@ -39,11 +41,12 @@ function transform(error) {
3941
default:
4042
return error;
4143
}
42-
return Object.assign({}, error, {
43-
type: TYPE,
44-
severity: 900,
45-
name: 'Loader not enabled'
46-
});
44+
45+
error.type = TYPE;
46+
error.severity = 900;
47+
error.name = 'Loader not enabled';
48+
49+
return error;
4750
}
4851

4952
module.exports = transform;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
const expect = require('chai').expect;
2+
const transform = require('../../../lib/friendly-errors/transformers/missing-loader');
3+
4+
describe('transform/missing-loader', () => {
5+
6+
describe('test transform', () => {
7+
it('Error not with "ModuleParseError" name is ignored', () => {
8+
const startError = {
9+
name: 'OtherParseError',
10+
message: 'You may need an appropriate loader',
11+
file: '/path/to/file.sass'
12+
};
13+
const actualError = transform(Object.assign({}, startError));
14+
15+
expect(actualError).to.deep.equal(startError);
16+
});
17+
18+
it('Error not containing "appropriate loader" is ignored', () => {
19+
const startError = {
20+
name: 'ModuleParseError',
21+
message: 'Some other message',
22+
file: '/path/to/file.sass'
23+
};
24+
const actualError = transform(Object.assign({}, startError));
25+
26+
expect(actualError).to.deep.equal(startError);
27+
});
28+
29+
it('Error with unsupported file extension is ignored', () => {
30+
const startError = {
31+
name: 'ModuleParseError',
32+
message: 'You may need an appropriate loader',
33+
file: '/path/to/file.jpg'
34+
};
35+
const actualError = transform(Object.assign({}, startError));
36+
37+
expect(actualError).to.deep.equal(startError);
38+
});
39+
40+
it('Matching error is properly transformed', () => {
41+
const startError = {
42+
name: 'ModuleParseError',
43+
message: 'You may need an appropriate loader',
44+
file: '/path/to/file.sass'
45+
};
46+
const actualError = transform(Object.assign({}, startError));
47+
48+
expect(actualError.name).to.deep.equal('Loader not enabled');
49+
expect(actualError.loaderName).to.deep.equal('sass');
50+
});
51+
});
52+
});

0 commit comments

Comments
 (0)