Various adaptations for Phantomas v2

This commit is contained in:
Gaël Métais
2020-08-11 03:01:43 +02:00
parent bafea756ee
commit e19a521c4e
4 changed files with 60 additions and 47 deletions
+10 -8
View File
@@ -312,7 +312,7 @@ var policies = {
list: offenders.map(function(offender) {
if (offender === '[inline CSS]') {
return {
error: 'Empty style tag',
error: 'Empty <style> tag',
file: null,
line: null,
column: null
@@ -321,17 +321,19 @@ var policies = {
if (offender.value) {
return {
error: offender.value.message || 'Unknown parsing error' + (parts[1] ? '. The entire file was ignored. As a result, the other CSS metrics and scores are miscalculated.' : ''),
file: offender.file || null,
error: offender.value.message || 'Unknown parsing error. The entire file was ignored. As a result, the other CSS metrics and scores are miscalculated.',
file: offender.url || null,
line: offender.value.position ? offender.value.position.start.line : null,
column: offender.value.position ? offender.value.position.start.column : null
};
} else {
return {
error: 'Unknown parsing error. The entire file was ignored. As a result, the other CSS metrics and scores are miscalculated.',
file: offender,
line: null,
column: null
};
}
debug('cssParsingErrors offenders transform function error with "%s"', offender);
return {
parseError: offender
};
})
};
}
+2 -23
View File
@@ -65,32 +65,11 @@ var PhantomasWrapper = function() {
options.proxy = task.options.proxy;
}
// Output the command line for debugging purpose
debug('If you want to reproduce the phantomas task only, copy the following command line:');
var optionsString = '';
for (var opt in options) {
var value = options[opt];
if ((typeof value === 'string' || value instanceof String) && value.indexOf(' ') >= 0) {
value = '"' + value + '"';
}
if (value === true) {
optionsString += ' ' + '--' + opt;
} else if (value === false || value === null || value === undefined) {
// Nothing
} else {
optionsString += ' ' + '--' + opt + '=' + value;
}
}
debug('node node_modules/phantomas/bin/phantomas.js --url=' + task.url + optionsString + ' --verbose');
// It's time to launch the test!!!
const promise = phantomas(task.url, {
'analyze-css': true
'analyze-css': true,
'screenshot': true
});
// handle the promise
+11 -11
View File
@@ -4,10 +4,10 @@ var colorDiff = require('../../lib/tools/colorDiff');
describe('colorDiff', function() {
it('should parse offenders correctly', function() {
colorDiff.parseOffender('#000 (1 times)').should.equal('#000');
colorDiff.parseOffender('#5bc0de (2 times)').should.equal('#5bc0de');
colorDiff.parseOffender('rgba(0,0,0,0.075) (100 times)').should.equal('rgba(0,0,0,0.075)');
colorDiff.parseOffender('rgb(91,192,222) (1000 times)').should.equal('rgb(91,192,222)');
colorDiff.parseOffender({url:'file.css', value: {message: '#000 (1 times)'}}).should.equal('#000');
colorDiff.parseOffender({url:'file.css', value: {message: '#5bc0de (2 times)'}}).should.equal('#5bc0de');
colorDiff.parseOffender({url:'file.css', value: {message: 'rgba(0,0,0,0.075) (100 times)'}}).should.equal('rgba(0,0,0,0.075)');
colorDiff.parseOffender({url:'file.css', value: {message: 'rgb(91,192,222) (1000 times)'}}).should.equal('rgb(91,192,222)');
});
it('should parse colors correctly', function() {
@@ -45,13 +45,13 @@ describe('colorDiff', function() {
it('should compare all colors to each other', function() {
var colors = [
'#000 (1 times)',
'#5bc0de (2 times)',
'rgba(0,0,0,0.075) (100 times)',
'rgb(91,192,222) (1000 times)',
'rgba(0,0,2,1) (1 times)',
'rgba(99,99,99,1) (1 times)',
'rgba(100,100,100,1) (1 times)'
{url:'file.css', value: {message: '#000 (1 times)'}},
{url:'file.css', value: {message: '#5bc0de (2 times)'}},
{url:'file.css', value: {message: 'rgba(0,0,0,0.075) (100 times)'}},
{url:'file.css', value: {message: 'rgb(91,192,222) (1000 times)'}},
{url:'file.css', value: {message: 'rgba(0,0,2,1) (1 times)'}},
{url:'file.css', value: {message: 'rgba(99,99,99,1) (1 times)'}},
{url:'file.css', value: {message: 'rgba(100,100,100,1) (1 times)'}}
];
var data = {
+37 -5
View File
@@ -46,8 +46,13 @@ describe('customPolicies', function() {
},
"offenders": {
"DOMidDuplicated": [
"colorswitch-30883-30865: 4 occurrences",
"foo: 1 occurrences"
{
"id": "colorswitch-30883-30865",
"occurrences": 4
}, {
"id": "foo",
"occurrences": 1
}
]
}
}
@@ -267,8 +272,29 @@ describe('customPolicies', function() {
},
"offenders": {
"cssParsingErrors": [
"<http://www.sudexpress.com/skin/frontend/sudexpress/default/css/styles.css> (Error: CSS parsing failed: missing '}' @ 4:1)",
"<http://www.sudexpress.com/skin/frontend/sudexpress/default/css/reset.css> (Empty CSS was provided)"
{
"url": "http://www.sudexpress.com/skin/frontend/sudexpress/default/css/styles.css",
"value": {
"message": "Error: CSS parsing failed: missing '}'",
"position": {
"start": {
"line": 4,
"column": 1
},
"end": {
"line": 4,
"column": 72
}
}
}
},
{
"url": "http://www.sudexpress.com/skin/frontend/sudexpress/default/css/reset.css",
"value": {
"message": "Empty CSS was provided"
}
},
"http://www.sudexpress.com/skin/frontend/sudexpress/default/css/another.css"
]
}
}
@@ -277,7 +303,7 @@ describe('customPolicies', function() {
results.should.have.a.property('cssParsingErrors');
results.cssParsingErrors.should.have.a.property('offendersObj').that.deep.equals({
"count": 2,
"count": 3,
"list": [
{
"error": "Error: CSS parsing failed: missing '}'",
@@ -290,6 +316,12 @@ describe('customPolicies', function() {
"file": "http://www.sudexpress.com/skin/frontend/sudexpress/default/css/reset.css",
"line": null,
"column": null
},
{
"error": "Unknown parsing error. The entire file was ignored. As a result, the other CSS metrics and scores are miscalculated.",
"file": "http://www.sudexpress.com/skin/frontend/sudexpress/default/css/another.css",
"line": null,
"column": null
}
]
});