Skip to content

Commit

Permalink
Update printWidth to 120 chars
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasonny83 committed Jul 21, 2019
1 parent ae99e80 commit 580eaf5
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 143 deletions.
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"trailingComma": "all",
"semi": true,
"singleQuote": true,
"printWidth": 80,
"printWidth": 120,
"useTabs": false,
"tabWidth": 2,
"bracketSpacing": true
Expand Down
70 changes: 29 additions & 41 deletions __tests__/budgets-analyzer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,45 +11,33 @@ describe('budgets-analyzer', () => {
process.exit = processExit;
});

it(
'should return `false` if any over-budget reported' +
'and `--fail-on-budgets` set to `true`',
() => {
const mockBudgetsReport = {
'total-count': '323 requests',
'total-size': '12677kb',
};

const result = analyzeBudgets(mockBudgetsReport, true);

expect(result).toEqual(false);
},
);

it(
'should return `true` if no over-budget reported' +
'and `--fail-on-budgets` set to `true`',
() => {
const mockBudgetsReport = {};

const result = analyzeBudgets(mockBudgetsReport, true);

expect(result).toEqual(true);
},
);

it(
'should return `true` if any over-budget reported' +
'and `--fail-on-budgets` set to `false`',
() => {
const mockBudgetsReport = {
'total-count': '323 requests',
'total-size': '12677kb',
};

const result = analyzeBudgets(mockBudgetsReport, true);

expect(result).toEqual(false);
},
);
it('should return `false` if any over-budget reported and `--fail-on-budgets` set to `true`', () => {
const mockBudgetsReport = {
'total-count': '323 requests',
'total-size': '12677kb',
};

const result = analyzeBudgets(mockBudgetsReport, true);

expect(result).toEqual(false);
});

it('should return `true` if no over-budget reported and `--fail-on-budgets` set to `true`', () => {
const mockBudgetsReport = {};

const result = analyzeBudgets(mockBudgetsReport, true);

expect(result).toEqual(true);
});

it('should return `true` if any over-budget reported and `--fail-on-budgets` set to `false`', () => {
const mockBudgetsReport = {
'total-count': '323 requests',
'total-size': '12677kb',
};

const result = analyzeBudgets(mockBudgetsReport, true);

expect(result).toEqual(false);
});
});
10 changes: 2 additions & 8 deletions __tests__/helpers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ describe('helpers', () => {

// Assert
expect(res).resolves.toEqual();
expect(rimraf).toHaveBeenCalledWith(
expectedFolderName,
expect.any(Function),
);
expect(rimraf).toHaveBeenCalledWith(expectedFolderName, expect.any(Function));
});
});

Expand Down Expand Up @@ -93,10 +90,7 @@ describe('helpers', () => {

// Assert
expect(res).resolves.toEqual();
expect(mkdirp).toHaveBeenCalledWith(
expectedFolderName,
expect.any(Function),
);
expect(mkdirp).toHaveBeenCalledWith(expectedFolderName, expect.any(Function));
});
});

Expand Down
86 changes: 36 additions & 50 deletions __tests__/score-analyzer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,23 @@ describe('score-analyzer', () => {
seo: 0.73,
};

expect(() => analyzeScore(mockCategoryReport)).toThrowError(
'Invalid threshold score.',
);
expect(() => analyzeScore(mockCategoryReport)).toThrowError('Invalid threshold score.');
});

it(
'should return `false` if one or more category index is below the ' +
'threshold',
() => {
const threshold = 75;
const mockCategoryReport = {
performance: 7,
pwa: 36,
accessibility: 57,
'best-practices': 69,
seo: 73,
};
it('should return `false` if one or more category index is below the threshold', () => {
const threshold = 75;
const mockCategoryReport = {
performance: 7,
pwa: 36,
accessibility: 57,
'best-practices': 69,
seo: 73,
};

const result = analyzeScore(mockCategoryReport, threshold);
const result = analyzeScore(mockCategoryReport, threshold);

expect(result).toEqual(false);
},
);
expect(result).toEqual(false);
});

it('should return `true` if all the category indexes are above the threshold', () => {
const threshold = 70;
Expand All @@ -75,20 +69,16 @@ describe('score-analyzer', () => {
seo: 10,
};

it(
'should return `true` if the target categories indexes are above ' +
'the thresholds',
() => {
const threshold = {
performance: 70,
pwa: 80,
};
it('should return `true` if the target categories indexes are above the thresholds', () => {
const threshold = {
performance: 70,
pwa: 80,
};

const result = analyzeScore(mockCategoryReport, threshold);
const result = analyzeScore(mockCategoryReport, threshold);

expect(result).toEqual(true);
},
);
expect(result).toEqual(true);
});

it('should pass if the target categories indexes are above the "best-practices" thresholds', () => {
const threshold = {
Expand Down Expand Up @@ -191,25 +181,21 @@ describe('score-analyzer', () => {
});
});

it(
'should return `false` if one or more target category index is below ' +
'the thresholds',
() => {
const threshold = {
performance: 70,
pwa: 80,
};
const mockCategoryReport = {
performance: 70,
pwa: 79,
accessibility: 10,
'best-practices': 10,
seo: 10,
};
it('should return `false` if one or more target category index is below the thresholds', () => {
const threshold = {
performance: 70,
pwa: 80,
};
const mockCategoryReport = {
performance: 70,
pwa: 79,
accessibility: 10,
'best-practices': 10,
seo: 10,
};

const result = analyzeScore(mockCategoryReport, threshold);
const result = analyzeScore(mockCategoryReport, threshold);

expect(result).toEqual(false);
},
);
expect(result).toEqual(false);
});
});
7 changes: 1 addition & 6 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@
*/

const scores = ['performance', 'pwa', 'accessibility', 'best-practices', 'seo'];
const chromeFlags = [
'--disable-gpu',
'--headless',
'--no-zygote',
'--no-sandbox',
];
const chromeFlags = ['--disable-gpu', '--headless', '--no-zygote', '--no-sandbox'];

const getScores = () => scores;
const getChromeFlags = () => chromeFlags;
Expand Down
11 changes: 3 additions & 8 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ const clean = () =>
});

const createDir = () =>
new Promise((resolve, reject) =>
mkdirp('./lighthouse', err => (err ? reject(err) : resolve())),
);
new Promise((resolve, reject) => mkdirp('./lighthouse', err => (err ? reject(err) : resolve())));

const scoreReducer = (flags, scoreList) => {
if (flags.score) {
Expand Down Expand Up @@ -57,9 +55,7 @@ const createDefaultConfig = config => {
};

const getOwnProps = obj => {
return Object.keys(obj).filter(key =>
Object.prototype.hasOwnProperty.call(obj, key),
);
return Object.keys(obj).filter(key => Object.prototype.hasOwnProperty.call(obj, key));
};

const convertToBudgetList = obj => {
Expand All @@ -74,8 +70,7 @@ const convertToBudgetList = obj => {
}, []);
};

const convertToResourceKey = key =>
'resource' + key.charAt(0).toUpperCase() + key.slice(1);
const convertToResourceKey = key => 'resource' + key.charAt(0).toUpperCase() + key.slice(1);

module.exports = {
clean,
Expand Down
34 changes: 5 additions & 29 deletions lib/lighthouse-reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,11 @@ const util = require('util');
const lighthouse = require('lighthouse');
const chromeLauncher = require('chrome-launcher');
const ReportGenerator = require('lighthouse/lighthouse-core/report/report-generator');
const {
createDefaultConfig,
getOwnProps,
convertToBudgetList,
convertToResourceKey,
} = require('./helpers');
const { createDefaultConfig, getOwnProps, convertToBudgetList, convertToResourceKey } = require('./helpers');

const readFile = util.promisify(fs.readFile);

const launchChromeAndRunLighthouse = async (
url,
chromeFlags,
lighthouseFlags,
configPath,
budgetPath,
) => {
const launchChromeAndRunLighthouse = async (url, chromeFlags, lighthouseFlags, configPath, budgetPath) => {
const chrome = await chromeLauncher.launch({
chromeFlags,
});
Expand Down Expand Up @@ -132,10 +121,7 @@ const createBudgetsReport = results => {
}

if (obj.sizeOverBudget) {
acc[obj.resourceType + '-size'] = `${Math.round(
obj.sizeOverBudget / 1024,
0,
)}kb`;
acc[obj.resourceType + '-size'] = `${Math.round(obj.sizeOverBudget / 1024, 0)}kb`;
}

return acc;
Expand All @@ -144,18 +130,8 @@ const createBudgetsReport = results => {
return report;
};

async function writeReport(
url,
flags = {},
defaultChromeFlags,
lighthouseFlags,
) {
const {
chromeFlags,
configPath,
budgetPath,
...extraLHFlags
} = lighthouseFlags;
async function writeReport(url, flags = {}, defaultChromeFlags, lighthouseFlags) {
const { chromeFlags, configPath, budgetPath, ...extraLHFlags } = lighthouseFlags;
const customChromeFlags = chromeFlags ? chromeFlags.split(',') : [];

const lighthouseResult = await launchChromeAndRunLighthouse(
Expand Down

0 comments on commit 580eaf5

Please sign in to comment.