-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #317 from macbre/improve-code-coverage
Improve code coverage
- Loading branch information
Showing
11 changed files
with
98 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,4 @@ rules: | |
- error | ||
- allowEmptyCatch: true | ||
no-prototype-builtins: 'off' | ||
"node/no-extraneous-require": 'off' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,72 @@ | ||
/*global describe, it */ | ||
'use strict'; | ||
const { describe, it } = require("@jest/globals"); | ||
|
||
var analyzer = require('../'), | ||
fs = require('fs'), | ||
isSassInstalled = true, | ||
assert = require('assert'), | ||
scss = 'nav {\nul{ color: white }\n}', | ||
sass = 'nav\n\tul\n\t\tcolor: white\n'; | ||
sass = 'nav\n\tul\n\t\tcolor: white\n', | ||
nodeSassInfo; | ||
|
||
try { | ||
require('node-sass'); | ||
nodeSassInfo = require('node-sass').info; | ||
console.log(`Using ${nodeSassInfo.replace("\n", " ")}`); | ||
} catch (e) { | ||
isSassInstalled = false; | ||
} | ||
|
||
/** | ||
* TODO: install and test node-sass | ||
*/ | ||
function testSassInstalled(done) { | ||
new analyzer(sass, { | ||
preprocessor: 'sass' | ||
}, function(err, res) { | ||
assert.strictEqual(err, null); | ||
assert.equal(res.metrics.selectors, 1); | ||
done(); | ||
}); | ||
} | ||
|
||
/** | ||
* node-sass is not installed by default (see #118) | ||
*/ | ||
function testSassNotInstalled(done) { | ||
try { | ||
new analyzer(scss, { | ||
preprocessor: 'sass' | ||
}, function() {}); | ||
} catch (e) { | ||
assert.ok(e instanceof Error); | ||
assert.equal(e.message, 'Preprocessing failed: Error: Can\'t process SASS/SCSS, please run \'npm install node-sass\''); | ||
done(); | ||
} | ||
} | ||
|
||
describe('SASS preprocessor [' + (isSassInstalled ? 'node-sass installed' : 'node-sass missing') + ']', () => { | ||
it('should be chosen for SCSS files', () => { | ||
var preprocessors = new(require('../lib/preprocessors.js'))(); | ||
|
||
assert.equal(preprocessors.findMatchingByFileName('test/foo.scss'), 'sass'); | ||
assert.equal(preprocessors.findMatchingByFileName('test/foo.sass'), 'sass'); | ||
assert.equal(preprocessors.findMatchingByFileName('test/foo.css'), false); | ||
assert.strictEqual(preprocessors.findMatchingByFileName('test/foo.scss'), 'sass'); | ||
assert.strictEqual(preprocessors.findMatchingByFileName('test/foo.sass'), 'sass'); | ||
assert.strictEqual(preprocessors.findMatchingByFileName('test/foo.css'), false); | ||
}); | ||
|
||
it('should report parsing error (if not selected)', done => { | ||
new analyzer(scss, function(err, res) { | ||
assert.strictEqual(err, null); | ||
assert.equal(res.metrics.parsingErrors, 3); | ||
assert.strictEqual(res.metrics.parsingErrors, 3); | ||
done(); | ||
}); | ||
}); | ||
|
||
it( | ||
'should generate CSS from SCSS correctly', | ||
!isSassInstalled ? testSassNotInstalled : testSassInstalled | ||
); | ||
if (isSassInstalled === false) { | ||
return; | ||
} | ||
|
||
it( | ||
'should generate CSS from SASS correctly', | ||
!isSassInstalled ? testSassNotInstalled : testSassInstalled | ||
); | ||
it('should generate CSS from SCSS correctly', done => { | ||
try { | ||
new analyzer(scss, { | ||
preprocessor: 'sass' | ||
}, done); | ||
} catch (e) { | ||
assert.ok(e instanceof Error); | ||
assert.strictEqual(e.message, 'Preprocessing failed: Error: Can\'t process SASS/SCSS, please run \'npm install node-sass\''); | ||
done(); | ||
} | ||
}); | ||
|
||
it('should generate CSS from SASS correctly', done => { | ||
try { | ||
new analyzer(sass, { | ||
preprocessor: 'sass' | ||
}, done); | ||
} catch (e) { | ||
assert.ok(e instanceof Error); | ||
assert.strictEqual(e.message, 'Preprocessing failed: Error: Can\'t process SASS/SCSS, please run \'npm install node-sass\''); | ||
done(); | ||
} | ||
}); | ||
|
||
it('should parse SCSS file correctly', done => { | ||
const file = __dirname + '/../examples/base.scss', | ||
source = fs.readFileSync(file).toString(); | ||
|
||
new analyzer(source, { | ||
file: file, | ||
preprocessor: 'sass' | ||
}, done); | ||
}); | ||
}); |