Skip to content

Commit

Permalink
tests: lint and typecheck improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickhulce committed Oct 20, 2020
1 parent 612e74c commit 56fb2d5
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 14 deletions.
6 changes: 3 additions & 3 deletions packages/server/src/cron/delete-old-builds.js
Expand Up @@ -12,10 +12,9 @@ const {normalizeCronSchedule} = require('./utils');
/**
* @param {LHCI.ServerCommand.StorageMethod} storageMethod
* @param {number} maxAgeInDays
* @param {Date} now
* @return {Promise<void>}
*/
async function deleteOldBuilds(storageMethod, maxAgeInDays, now = new Date()) {
async function deleteOldBuilds(storageMethod, maxAgeInDays) {
if (!maxAgeInDays || !Number.isInteger(maxAgeInDays) || maxAgeInDays <= 0) {
throw new Error('Invalid range');
}
Expand All @@ -42,6 +41,7 @@ function startDeleteOldBuildsCron(storageMethod, options) {
throw new Error('Cannot configure schedule');
}

/** @type {(s: string) => void} */
const log =
options.logLevel === 'silent'
? () => {}
Expand All @@ -58,7 +58,7 @@ function startDeleteOldBuildsCron(storageMethod, options) {
}
inProgress = true;
log(`Starting delete old builds`);
deleteOldBuilds(storageMethod, maxAgeInDays, new Date())
deleteOldBuilds(storageMethod, maxAgeInDays)
.then(() => {
log(`Successfully delete old builds`);
})
Expand Down
6 changes: 3 additions & 3 deletions packages/server/src/ui/routes/build-view/build-view.jsx
Expand Up @@ -56,15 +56,15 @@ const BuildView_ = props => {

const compareRuns = props.runs.filter(run => run.buildId === props.build.id);
const compareUrl = props.compareUrl || computeSelectedUrl(props, compareRuns);
const baseUrl = props.baseUrl || compareUrl
const baseUrl = props.baseUrl || compareUrl;
const availableUrls = [...new Set(compareRuns.map(run => run.url))];
const run = compareRuns.find(run => run.url === compareUrl);

const ancestorBuildId = props.ancestorBuild && props.ancestorBuild.id;
const baseRuns = props.runs.filter(run => run.buildId === ancestorBuildId);
const baseRun = baseRuns.find(run => run.url === baseUrl);

const availableUrlOptions = availableUrls.map(url => ({value: url, label: url}))
const availableUrlOptions = availableUrls.map(url => ({value: url, label: url}));

/** @type {LH.Result|undefined} */
let lhr;
Expand Down Expand Up @@ -165,7 +165,7 @@ const BuildView_ = props => {
baseLhr={baseLhr}
className={clsx({
'build-view--with-lhr-base-link-hover': isOpenLhrBaseLinkHovered,
'build-view--with-lhr-compare-link-hover': isOpenLhrCompareLinkHovered
'build-view--with-lhr-compare-link-hover': isOpenLhrCompareLinkHovered,
})}
hookElements={{
warnings: computeWarnings(warningProps).hasWarning ? (
Expand Down
9 changes: 2 additions & 7 deletions packages/server/test/cron/delete-old-builds.test.js
Expand Up @@ -16,10 +16,7 @@ jest.mock('cron', () => ({
},
}));

const {
startDeleteOldBuildsCron,
deleteOldBuilds,
} = require('../../src/cron/delete-old-builds.js');
const {startDeleteOldBuildsCron, deleteOldBuilds} = require('../../src/cron/delete-old-builds.js');

describe('cron/delete-old-builds', () => {
/** @type {{ findBuildsBeforeTimestamp: jest.MockInstance, deleteBuild: jest.MockInstance}} */
Expand Down Expand Up @@ -118,9 +115,7 @@ describe('cron/delete-old-builds', () => {
maxAgeInDays: 30,
},
};
expect(() => startDeleteOldBuildsCron(storageMethod, options)).toThrow(
/Invalid cron format/
);
expect(() => startDeleteOldBuildsCron(storageMethod, options)).toThrow(/Invalid cron format/);
});
it('should schedule a cron job', () => {
startDeleteOldBuildsCron(storageMethod, {
Expand Down
9 changes: 9 additions & 0 deletions packages/utils/src/api-client.js
Expand Up @@ -370,6 +370,15 @@ class ApiClient {
throw new Error('Unimplemented');
}

/**
* @param {Date} runAt
* @return {Promise<LHCI.ServerCommand.Build[]>}
*/
// eslint-disable-next-line no-unused-vars
async findBuildsBeforeTimestamp(runAt) {
throw new Error('Unimplemented');
}

/**
* @param {string} projectId
* @return {Promise<string>}
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/src/assertions.js
Expand Up @@ -26,7 +26,7 @@ const {computeRepresentativeRuns} = require('./representative-runs.js');
* @property {string|undefined} [auditProperty]
* @property {string|undefined} [auditTitle]
* @property {string|undefined} [auditDocumentationLink]
* @property {string} [message]
* @property {string|undefined} [message]
*/

/** @typedef {StrictOmit<AssertionResult, 'url'>} AssertionResultNoURL */
Expand Down

0 comments on commit 56fb2d5

Please sign in to comment.