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
ef5c28fd
Commit
ef5c28fd
authored
Aug 20, 2015
by
Marcin Cieslak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Raise an error when no string/file provided
Intended to fix
https://github.com/sass/node-sass/issues/924
parent
1479af67
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
175 additions
and
5 deletions
+175
-5
index.js
lib/index.js
+19
-4
api.js
test/api.js
+30
-0
lowlevel.js
test/lowlevel.js
+126
-1
No files found.
lib/index.js
View file @
ef5c28fd
...
...
@@ -179,8 +179,9 @@ function getLinefeed(options) {
function
getOptions
(
options
,
cb
)
{
options
=
options
||
{};
options
.
sourceComments
=
options
.
sourceComments
||
false
;
options
.
data
=
options
.
data
||
null
;
options
.
file
=
getInputFile
(
options
);
if
(
options
.
hasOwnProperty
(
'file'
))
{
options
.
file
=
getInputFile
(
options
);
}
options
.
outFile
=
getOutputFile
(
options
);
options
.
includePaths
=
(
options
.
includePaths
||
[]).
join
(
path
.
delimiter
);
options
.
precision
=
parseInt
(
options
.
precision
)
||
5
;
...
...
@@ -351,7 +352,13 @@ module.exports.render = function(options, cb) {
});
}
return
options
.
data
?
binding
.
render
(
options
)
:
binding
.
renderFile
(
options
);
if
(
options
.
data
)
{
binding
.
render
(
options
);
}
else
if
(
options
.
file
)
{
binding
.
renderFile
(
options
);
}
else
{
cb
({
status
:
3
,
message
:
'No input specified: provide a file name or a source string to process'
});
}
};
/**
...
...
@@ -398,7 +405,15 @@ module.exports.renderSync = function(options) {
});
}
var
status
=
options
.
data
?
binding
.
renderSync
(
options
)
:
binding
.
renderFileSync
(
options
);
var
status
;
if
(
options
.
data
)
{
status
=
binding
.
renderSync
(
options
);
}
else
if
(
options
.
file
)
{
status
=
binding
.
renderFileSync
(
options
);
}
else
{
throw
new
Error
(
'No input specified: provide a file name or a source string to process'
);
}
var
result
=
options
.
result
;
if
(
status
)
{
...
...
test/api.js
View file @
ef5c28fd
...
...
@@ -76,6 +76,22 @@ describe('api', function() {
});
});
it
(
'should NOT compile empty data string'
,
function
(
done
)
{
sass
.
render
({
data
:
''
},
function
(
error
)
{
assert
.
equal
(
error
.
message
,
'No input specified: provide a file name or a source string to process'
);
done
();
});
});
it
(
'should NOT compile without parameters'
,
function
(
done
)
{
sass
.
render
({
},
function
(
error
)
{
assert
.
equal
(
error
.
message
,
'No input specified: provide a file name or a source string to process'
);
done
();
});
});
it
(
'should compile sass to css using indented syntax'
,
function
(
done
)
{
var
src
=
read
(
fixture
(
'indent/index.sass'
),
'utf8'
);
var
expected
=
read
(
fixture
(
'indent/expected.css'
),
'utf8'
).
trim
();
...
...
@@ -1074,6 +1090,20 @@ describe('api', function() {
done
();
});
it
(
'should NOT compile empty data string'
,
function
(
done
)
{
assert
.
throws
(
function
()
{
sass
.
renderSync
({
data
:
''
});
},
/No input specified: provide a file name or a source string to process/
);
done
();
});
it
(
'should NOT compile without any input'
,
function
(
done
)
{
assert
.
throws
(
function
()
{
sass
.
renderSync
({});
},
/No input specified: provide a file name or a source string to process/
);
done
();
});
it
(
'should throw error for bad input'
,
function
(
done
)
{
assert
.
throws
(
function
()
{
sass
.
renderSync
(
'somestring'
);
...
...
test/lowlevel.js
View file @
ef5c28fd
...
...
@@ -12,6 +12,90 @@ describe('lowlevel', function() {
done
();
});
it
(
'data context with options.data not provided'
,
function
(
done
)
{
var
options
=
{
/* data: */
sourceComments
:
false
,
file
:
null
,
outFile
:
null
,
includePaths
:
''
,
precision
:
5
,
sourceMap
:
null
,
style
:
0
,
indentWidth
:
2
,
indentType
:
0
,
linefeed
:
'
\
n'
,
result
:
{
stats
:
{}
}
};
binding
.
renderSync
(
options
);
assert
(
/Data context created without a source string/
.
test
(
options
.
result
.
error
),
'Should fail with error message "Data context created without a source string"'
);
done
();
});
it
(
'data context with both options.data and options.file not provided'
,
function
(
done
)
{
var
options
=
{
/* data: */
sourceComments
:
false
,
/* file: null, */
outFile
:
null
,
includePaths
:
''
,
precision
:
5
,
sourceMap
:
null
,
style
:
0
,
indentWidth
:
2
,
indentType
:
0
,
linefeed
:
'
\
n'
,
result
:
{
stats
:
{}
}
};
binding
.
renderSync
(
options
);
assert
(
/Data context created without a source string/
.
test
(
options
.
result
.
error
),
'Should fail with error message "Data context created without a source string"'
);
done
();
});
it
(
'file context with both options.data and options.file not provided'
,
function
(
done
)
{
var
options
=
{
/* data: */
sourceComments
:
false
,
/* file: null, */
outFile
:
null
,
includePaths
:
''
,
precision
:
5
,
sourceMap
:
null
,
style
:
0
,
indentWidth
:
2
,
indentType
:
0
,
linefeed
:
'
\
n'
,
result
:
{
stats
:
{}
}
};
binding
.
renderFileSync
(
options
);
assert
(
/File context created without an input path/
.
test
(
options
.
result
.
error
),
'Should fail with error message "File context created without an input path"'
);
done
();
});
it
(
'file context with options.file not provided, options.data given'
,
function
(
done
)
{
var
options
=
{
data
:
'div { width: 10px; } '
,
sourceComments
:
false
,
/* file: null, */
outFile
:
null
,
includePaths
:
''
,
precision
:
5
,
sourceMap
:
null
,
style
:
0
,
indentWidth
:
2
,
indentType
:
0
,
linefeed
:
'
\
n'
,
result
:
{
stats
:
{}
}
};
binding
.
renderFileSync
(
options
);
assert
(
/File context created without an input path/
.
test
(
options
.
result
.
error
),
'Should fail with error message "File context created without an input path"'
);
done
();
});
it
(
'fail with options.result not provided'
,
function
(
done
)
{
var
options
=
{
data
:
'div { width: 10px; } '
,
sourceComments
:
false
,
...
...
@@ -96,7 +180,26 @@ describe('lowlevel', function() {
});
it
(
'options.indentWidth not provided'
,
function
(
done
)
{
var
options
=
{
data
:
'div { width: 10px; } '
,
var
options
=
{
data
:
'div { width: 10px; }'
,
sourceComments
:
false
,
file
:
null
,
outFile
:
null
,
includePaths
:
''
,
precision
:
5
,
sourceMap
:
null
,
style
:
0
,
/* indentWidth */
indentType
:
0
,
linefeed
:
'
\
n'
,
result
:
{
stats
:
{}
}
};
binding
.
renderSync
(
options
);
assert
(
options
.
result
.
css
);
done
();
});
it
(
'empty data string'
,
function
(
done
)
{
var
options
=
{
data
:
''
,
sourceComments
:
false
,
file
:
null
,
outFile
:
null
,
...
...
@@ -110,8 +213,30 @@ describe('lowlevel', function() {
result
:
{
stats
:
{}
}
};
binding
.
renderSync
(
options
);
assert
(
/empty source string/
.
test
(
options
.
result
.
error
),
'Should fail with error message "Data context created with empty source string"'
);
done
();
});
it
(
'empty file string'
,
function
(
done
)
{
var
options
=
{
sourceComments
:
false
,
file
:
''
,
outFile
:
null
,
includePaths
:
''
,
precision
:
5
,
sourceMap
:
null
,
style
:
0
,
/* indentWidth */
indentType
:
0
,
linefeed
:
'
\
n'
,
result
:
{
stats
:
{}
}
};
binding
.
renderFileSync
(
options
);
assert
(
/empty input path/
.
test
(
options
.
result
.
error
),
'Should fail with error message "File context created with empty input path"'
);
done
();
});
});
// lowlevel
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