Skip to content

Commit 7ed037f

Browse files
Support max num routes, fix vcs comment of extra nested data (#142)
* Support max num routes, fix vcs comment of extra nested data * No need for this since we filter now * Fix tests * Try onlyFailures on comment * Fix up circleci config for example testing * Use browsers docker image * Update deps for gimbal * fix unit tests * fix error
1 parent c629f56 commit 7ed037f

File tree

15 files changed

+885
-715
lines changed

15 files changed

+885
-715
lines changed

.circleci/config.yml

+5-3
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,22 @@ aliases:
1414
- packages/plugin-mysql/node_modules
1515
- packages/plugin-sqlite/node_modules
1616
- &restore-example-cache
17-
key: v1-dependencies-{{ checksum "yarn.lock" }}
17+
key: v1-dependencies-{{ checksum "examples/angular/yarn.lock" }}-{{ checksum "examples/react/yarn.lock" }}
1818
name: Restoring examples node_modules/ cache
1919
- &save-example-cache
20-
key: v1-dependencies-{{ checksum "yarn.lock" }}
20+
key: v1-dependencies-{{ checksum "examples/angular/yarn.lock" }}-{{ checksum "examples/react/yarn.lock" }}
2121
name: Saving examples node_modules/ cache
2222
paths:
23+
- examples/angular/dist
2324
- examples/angular/node_modules
2425
- examples/angular/gimbal.db
26+
- examples/react/build
2527
- examples/react/node_modules
2628
- examples/react/gimbal.db
2729

2830
docker-defaults: &docker-defaults
2931
docker:
30-
- image: circleci/node:10-browsers
32+
- image: circleci/node:12-browsers
3133

3234
defaults: &defaults
3335
<<: *docker-defaults

bin/build_examples.sh

+17-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,22 @@ EXAMPLES_DIR="$BASE_DIR/examples"
1818
for file in $EXAMPLES_DIR/*; do
1919
cd $file
2020

21-
yarn
21+
if [[ ! -d node_modules ]]; then
22+
echo
23+
echo "# Installing $file example"
24+
echo
25+
26+
yarn
27+
fi
28+
29+
# if either of these exists, continue
30+
if [[ -d build ]] || [[ -d dist ]]; then
31+
continue
32+
fi
33+
34+
echo
35+
echo "# Building $file example"
36+
echo
37+
2238
yarn build
2339
done

examples/react/.gimbalrc.yml

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ audits:
66
- heap-snapshot
77
- source-map-explorer
88

9+
configs:
10+
comment:
11+
onlyFailures: true
12+
913
outputs:
1014
html: artifacts/gimbal.html
1115
json: artifacts/gimbal.json

package.json

+8-8
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,22 @@
3636
"@types/jest": "24.0.15",
3737
"@types/node": "12.6.8",
3838
"@typescript-eslint/eslint-plugin": "1.12.0",
39-
"@typescript-eslint/parser": "1.12.0",
39+
"@typescript-eslint/parser": "1.13.0",
4040
"@zerollup/ts-transform-paths": "1.7.3",
41-
"eslint": "6.0.1",
41+
"eslint": "6.1.0",
4242
"eslint-config-airbnb": "17.1.1",
4343
"eslint-config-prettier": "6.0.0",
4444
"eslint-import-resolver-lerna": "1.1.0",
4545
"eslint-import-resolver-typescript": "1.1.1",
46-
"eslint-plugin-import": "2.18.0",
47-
"eslint-plugin-jest": "22.10.0",
46+
"eslint-plugin-import": "2.18.2",
47+
"eslint-plugin-jest": "22.15.0",
4848
"eslint-plugin-jsx-a11y": "6.2.3",
4949
"eslint-plugin-prettier": "3.1.0",
50-
"eslint-plugin-react": "7.14.2",
51-
"husky": "3.0.0",
50+
"eslint-plugin-react": "7.14.3",
51+
"husky": "3.0.3",
5252
"jest": "24.8.0",
53-
"lerna": "3.15.0",
54-
"lint-staged": "9.2.0",
53+
"lerna": "3.16.4",
54+
"lint-staged": "9.2.1",
5555
"prettier": "1.18.2",
5656
"rimraf": "2.6.3",
5757
"ts-jest": "24.0.2",

packages/gimbal/package.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@
7373
"homepage": "https://github.com/ModusCreateOrg/gimbal/tree/master/packages/gimbal#readme",
7474
"dependencies": {
7575
"@modus/gimbal-core": "1.1.11",
76-
"@octokit/rest": "16.28.4",
77-
"brotli-size": "3.0.1",
76+
"@octokit/rest": "16.28.7",
77+
"brotli-size": "4.0.0",
7878
"bytes": "3.1.0",
7979
"cli-table3": "0.5.1",
8080
"colors": "1.3.3",
@@ -85,14 +85,14 @@
8585
"globby": "10.0.1",
8686
"gzip-size": "5.1.1",
8787
"js-yaml": "3.13.1",
88-
"lighthouse": "5.1.0",
88+
"lighthouse": "5.2.0",
8989
"marked": "0.7.0",
9090
"minimatch": "3.0.4",
9191
"mkdirp": "0.5.1",
9292
"pidusage": "2.0.17",
93-
"puppeteer": "1.18.1",
93+
"puppeteer": "1.19.0",
9494
"read-pkg": "5.2.0",
95-
"serve-handler": "6.1.0",
95+
"serve-handler": "6.1.1",
9696
"strip-ansi": "5.2.0",
9797
"update-notifier": "3.0.1"
9898
},
@@ -106,7 +106,7 @@
106106
"@types/minimatch": "3.0.3",
107107
"@types/mkdirp": "0.5.2",
108108
"@types/pidusage": "2.0.1",
109-
"@types/puppeteer": "1.12.4",
109+
"@types/puppeteer": "1.19.0",
110110
"@types/read-pkg": "5.1.0",
111111
"@types/update-notifier": "2.5.0",
112112
"copyfiles": "2.1.1"

packages/gimbal/src/command/audit/index.ts

+32-23
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import findPort from '@modus/gimbal-core/lib/utils/port';
44
import Queue from '@modus/gimbal-core/lib/utils/Queue';
55
import Config from '@/config';
66
import Chrome from '@/module/chrome';
7-
import { get } from '@/module/registry';
7+
import { get, getMeta } from '@/module/registry';
88
import Serve from '@/module/serve';
99
import { Report, ReportItem } from '@/typings/command';
1010
import { Modules } from '@/typings/module';
@@ -115,32 +115,41 @@ const audit = async (options: CommandOptions): Promise<Report | Report[]> => {
115115
const queue = new Queue();
116116

117117
options.route.forEach((route: string, index: number): void => {
118-
audits.forEach((auditToRun: string): void =>
119-
addSpinner(auditToRun, { status: 'stopped', text: `[ ${auditToRun} ] - ${route}` }),
120-
);
121-
122-
queue.add(
123-
(): Promise<Report> =>
124-
doAudit(
125-
{
126-
chrome,
127-
url: `http://localhost:${servePort}${route}`,
128-
},
129-
audits,
130-
{
131-
...options,
132-
route,
133-
// if we will run size module, we should only do it once since
134-
// it won't change across multiple runs
135-
size: options.size && index === 0,
136-
},
137-
),
138-
);
118+
const filteredAudits = audits.filter((name: string): boolean => {
119+
const meta = getMeta(name);
120+
121+
if (meta && meta.maxNumRoutes && index >= meta.maxNumRoutes) {
122+
return false;
123+
}
124+
125+
return true;
126+
});
127+
128+
if (filteredAudits.length) {
129+
filteredAudits.forEach((name: string): void =>
130+
addSpinner(name, { status: 'stopped', text: `[ ${name} ] - ${route}` }),
131+
);
132+
133+
queue.add(
134+
(): Promise<Report> =>
135+
doAudit(
136+
{
137+
chrome,
138+
url: `http://localhost:${servePort}${route}`,
139+
},
140+
filteredAudits,
141+
{
142+
...options,
143+
route,
144+
},
145+
),
146+
);
147+
}
139148
});
140149

141150
report = (await queue.run()) as Report[];
142151
} else {
143-
audits.forEach((auditToRun: string): void => addSpinner(auditToRun, `[ ${auditToRun} ]`));
152+
audits.forEach((name: string): void => addSpinner(name, `[ ${name} ]`));
144153

145154
report = await doAudit(
146155
{

packages/gimbal/src/module/size/index.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { readFile, resolvePath, stats, getDirectorySize } from '@modus/gimbal-core/lib/utils/fs';
2-
// @ts-ignore
3-
import brotliSize from 'brotli-size';
2+
import { sync as brotliSize } from 'brotli-size';
43
import bytes from 'bytes';
54
import deepmerge from 'deepmerge';
65
import globby from 'globby';
@@ -27,7 +26,7 @@ type CompressionMechanisms = 'brotli' | 'gzip' | undefined;
2726
const getBundleSize = (source: Buffer, compression: CompressionMechanisms = 'gzip'): number => {
2827
switch (compression) {
2928
case 'brotli':
30-
return brotliSize.sync(source);
29+
return brotliSize(source);
3130
case 'gzip':
3231
return gzipSize.sync(source);
3332
default:

packages/gimbal/src/module/size/meta.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Meta } from '@/typings/module';
22

33
const meta: Meta = {
4+
maxNumRoutes: 1,
45
thresholdLimit: 'upper',
56
thresholdType: 'size',
67
};

packages/gimbal/src/vcs/comment/index.ts

+27-23
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import {
1616
Comment,
1717
} from '@/typings/vcs/comment';
1818

19+
const noFailuresText = 'No Failures';
20+
1921
const renderItem = async (
2022
reportItem: ReportItem,
2123
commandOptions: CommandOptions,
@@ -38,32 +40,34 @@ const renderItem = async (
3840
await EventEmitter.fire(`vcs/comment/render/table/start`, commentRenderTableStartEvent);
3941

4042
const output = [];
43+
const { onlyFailures } = comment as CommentObject;
4144

4245
if (reportItem.data && reportItem.data[0] && reportItem.data[0].data && reportItem.data[0].data.length) {
43-
const buffered = [`## ${reportItem.label}`];
44-
45-
await Promise.all(
46-
reportItem.data.map(
47-
async (childItem: ReportItem): Promise<void> => {
48-
const rendered = await outputTable(childItem, commandOptions);
49-
50-
buffered.push(`### ${childItem.label}`, rendered);
51-
},
52-
),
53-
);
54-
55-
output.push(...buffered);
46+
if (onlyFailures && !numFailed) {
47+
output.push(noFailuresText);
48+
} else {
49+
const buffered = [`## ${reportItem.label}`];
50+
51+
await Promise.all(
52+
reportItem.data.map(
53+
async (childItem: ReportItem): Promise<void> => {
54+
const rendered =
55+
onlyFailures && childItem.success ? noFailuresText : await outputTable(childItem, commandOptions);
56+
57+
buffered.push(`### ${childItem.label}`, rendered);
58+
},
59+
),
60+
);
61+
62+
output.push(...buffered);
63+
}
64+
} else if (onlyFailures && reportItem.success) {
65+
output.push(noFailuresText);
5666
} else {
57-
const { onlyFailures } = comment as CommentObject;
58-
const rendered =
59-
onlyFailures && reportItem.success
60-
? 'No Failures'
61-
: await outputTable(
62-
onlyFailures && reportItem
63-
? (filterReportItemsFailures(reportItem as ReportItem) as ReportItem)
64-
: reportItem,
65-
commandOptions,
66-
);
67+
const rendered = await outputTable(
68+
onlyFailures && reportItem ? (filterReportItemsFailures(reportItem as ReportItem) as ReportItem) : reportItem,
69+
commandOptions,
70+
);
6771

6872
output.push(`## ${reportItem.label}`, rendered);
6973
}

packages/plugin-axe/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const getThreshold = (entry: Result, { thresholds }: Config): ThresholdValueStri
5656
};
5757

5858
const isSuccessful = (entry: Result, threshold: ThresholdValueString): boolean =>
59-
threshold == null ? true : impactMap[threshold] >= impactMap[entry.impact];
59+
threshold == null || !entry.impact ? true : impactMap[threshold] >= impactMap[entry.impact];
6060

6161
const parseEntry = (entry: Result, success: boolean, config: Config): ReportItem => {
6262
const threshold = getThreshold(entry, config);

packages/plugin-source-map-explorer/src/config.spec.ts

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ describe('@modus/gimbal-plugin-source-map-explorer/config', (): void => {
77
});
88

99
expect(meta).toEqual({
10+
maxNumRoutes: 1,
1011
thresholdLimit: 'upper',
1112
thresholdType: 'size',
1213
});

packages/plugin-source-map-explorer/src/config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export const defaultConfig: Config = {
2121
};
2222

2323
export const meta: Meta = {
24+
maxNumRoutes: 1,
2425
thresholdLimit: 'upper',
2526
thresholdType: 'size',
2627
};

packages/plugin-source-map-explorer/src/mod.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ describe('@modus/gimbal-plugin-source-map-explorer/mod', (): void => {
217217

218218
expect(register).toHaveBeenCalledWith(
219219
'source-map-explorer',
220-
{ thresholdLimit: 'upper', thresholdType: 'size' },
220+
{ maxNumRoutes: 1, thresholdLimit: 'upper', thresholdType: 'size' },
221221
expect.any(Function),
222222
);
223223
});

packages/typings/module/index.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ interface TypesMap {
1010

1111
/* eslint-disable-next-line import/prefer-default-export */
1212
export interface Meta {
13+
maxNumRoutes?: number;
1314
thresholdLimit: ReportThresholdLimit;
1415
thresholdType?: Types;
1516
thresholdTypes?: TypesMap;

0 commit comments

Comments
 (0)