Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
node-sass
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
楚学文
node-sass
Commits
272518e0
Commit
272518e0
authored
Mar 28, 2015
by
Adeel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Importer: Allows importer to return error.
* Adds corresponding tests. Issue URL: #651. PR URL: #817.
parent
4ed6de22
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
82 additions
and
13 deletions
+82
-13
custom_importer_bridge.cpp
src/custom_importer_bridge.cpp
+25
-5
api.js
test/api.js
+41
-7
cli.js
test/cli.js
+13
-1
my_custom_importer_error.js
test/fixtures/extras/my_custom_importer_error.js
+3
-0
No files found.
src/custom_importer_bridge.cpp
View file @
272518e0
...
...
@@ -16,16 +16,36 @@ SassImportList CustomImporterBridge::post_process_return_value(Handle<Value> val
for
(
size_t
i
=
0
;
i
<
array
->
Length
();
++
i
)
{
Local
<
Value
>
value
=
array
->
Get
(
static_cast
<
uint32_t
>
(
i
));
if
(
!
value
->
IsObject
())
if
(
!
value
->
IsObject
())
{
continue
;
}
Local
<
Object
>
object
=
Local
<
Object
>::
Cast
(
value
);
char
*
path
=
create_string
(
object
->
Get
(
NanNew
<
String
>
(
"file"
)));
char
*
contents
=
create_string
(
object
->
Get
(
NanNew
<
String
>
(
"contents"
)));
imports
[
i
]
=
sass_make_import_entry
(
path
,
(
!
contents
||
contents
[
0
]
==
'\0'
)
?
0
:
strdup
(
contents
),
0
);
if
(
value
->
IsNativeError
())
{
char
*
message
=
create_string
(
object
->
Get
(
NanNew
<
String
>
(
"message"
)));
imports
[
i
]
=
sass_make_import_entry
(
0
,
0
,
0
);
sass_import_set_error
(
imports
[
i
],
message
,
-
1
,
-
1
);
}
else
{
char
*
path
=
create_string
(
object
->
Get
(
NanNew
<
String
>
(
"file"
)));
char
*
contents
=
create_string
(
object
->
Get
(
NanNew
<
String
>
(
"contents"
)));
imports
[
i
]
=
sass_make_import_entry
(
path
,
(
!
contents
||
contents
[
0
]
==
'\0'
)
?
0
:
strdup
(
contents
),
0
);
}
}
}
else
if
(
returned_value
->
IsNativeError
())
{
imports
=
sass_make_import_list
(
1
);
Local
<
Object
>
object
=
Local
<
Object
>::
Cast
(
returned_value
);
char
*
message
=
create_string
(
object
->
Get
(
NanNew
<
String
>
(
"message"
)));
imports
[
0
]
=
sass_make_import_entry
(
0
,
0
,
0
);
sass_import_set_error
(
imports
[
0
],
message
,
-
1
,
-
1
);
}
else
if
(
returned_value
->
IsObject
())
{
imports
=
sass_make_import_list
(
1
);
Local
<
Object
>
object
=
Local
<
Object
>::
Cast
(
returned_value
);
...
...
@@ -46,7 +66,7 @@ std::vector<Handle<Value>> CustomImporterBridge::pre_process_args(std::vector<vo
std
::
vector
<
Handle
<
Value
>>
out
;
for
(
void
*
ptr
:
in
)
{
out
.
push_back
(
NanNew
<
String
>
((
char
const
*
)
ptr
));
out
.
push_back
(
NanNew
<
String
>
((
char
const
*
)
ptr
));
}
return
out
;
...
...
test/api.js
View file @
272518e0
...
...
@@ -387,6 +387,30 @@ describe('api', function() {
done
();
});
});
it
(
'should reflect user-defined error when returned as callback'
,
function
(
done
)
{
sass
.
render
({
data
:
src
,
importer
:
function
(
url
,
prev
,
done
)
{
done
(
new
Error
(
'doesn
\'
t exist!'
));
}
},
function
(
error
)
{
assert
.
equal
(
error
.
message
,
'doesn
\'
t exist!'
);
done
();
});
});
it
(
'should reflect user-defined error with return'
,
function
(
done
)
{
sass
.
render
({
data
:
src
,
importer
:
function
()
{
return
new
Error
(
'doesn
\'
t exist!'
);
}
},
function
(
error
)
{
assert
.
equal
(
error
.
message
,
'doesn
\'
t exist!'
);
done
();
});
});
});
describe
(
'.render(functions)'
,
function
()
{
...
...
@@ -1136,6 +1160,20 @@ describe('api', function() {
assert
.
equal
(
sync
,
true
);
done
();
});
it
(
'should throw user-defined error'
,
function
(
done
)
{
assert
.
throws
(
function
()
{
sass
.
renderSync
({
data
:
src
,
importer
:
function
()
{
return
new
Error
(
'doesn
\'
t exist!'
);
}
});
},
/doesn
\'
t exist!/
);
done
();
});
});
describe
(
'.render({stats: {}})'
,
function
()
{
...
...
@@ -1390,14 +1428,10 @@ describe('api', function() {
assert
.
throws
(
function
()
{
fs
.
renameSync
(
originalBin
,
renamedBin
);
process
.
sass
.
getBinaryPath
(
true
);
},
function
(
err
)
{
fs
.
renameSync
(
renamedBin
,
originalBin
);
},
/`libsass` bindings not found. Try reinstalling `node-sass`
?
/
);
if
((
err
instanceof
Error
)
&&
/`libsass` bindings not found. Try reinstalling `node-sass`
?
/
.
test
(
err
))
{
done
();
return
true
;
}
});
fs
.
renameSync
(
renamedBin
,
originalBin
);
done
();
});
});
});
test/cli.js
View file @
272518e0
...
...
@@ -410,7 +410,7 @@ describe('cli', function() {
});
});
it
(
'should return error
on
for invalid importer file path'
,
function
(
done
)
{
it
(
'should return error for invalid importer file path'
,
function
(
done
)
{
var
bin
=
spawn
(
cli
,
[
src
,
'--output'
,
path
.
dirname
(
dest
),
'--importer'
,
fixture
(
'non/existing/path'
)
...
...
@@ -421,6 +421,18 @@ describe('cli', function() {
done
();
});
});
it
(
'should reflect user-defined Error'
,
function
(
done
)
{
var
bin
=
spawn
(
cli
,
[
src
,
'--output'
,
path
.
dirname
(
dest
),
'--importer'
,
fixture
(
'extras/my_custom_importer_error.js'
)
]);
bin
.
stderr
.
once
(
'data'
,
function
(
code
)
{
assert
.
equal
(
JSON
.
parse
(
code
).
message
,
'doesn
\'
t exist!'
);
done
();
});
});
});
describe
(
'functions'
,
function
()
{
...
...
test/fixtures/extras/my_custom_importer_error.js
0 → 100644
View file @
272518e0
module
.
exports
=
function
()
{
return
new
Error
(
'doesn
\'
t exist!'
);
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment