Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
SrBrahma committed Mar 31, 2024
1 parent ae20551 commit ec65041
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 57 deletions.
55 changes: 45 additions & 10 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
{
"plugins": ["@typescript-eslint", "unicorn"],
"extends": ["plugin:@typescript-eslint/recommended", "prettier"],
"plugins": [
"@typescript-eslint",
"unicorn"
],
"extends": [
"plugin:@typescript-eslint/recommended",
"prettier"
],
"rules": {
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/no-explicit-any": "error",
Expand All @@ -9,15 +15,44 @@
"no-console": "error",
"@typescript-eslint/padding-line-between-statements": [
"error",
{ "blankLine": "always", "prev": ["const", "let"], "next": "*" },
{
"blankLine": "always",
"prev": [
"const",
"let"
],
"next": "*"
},
{
"blankLine": "any",
"prev": ["const", "let"],
"next": ["const", "let"]
"prev": [
"const",
"let"
],
"next": [
"const",
"let"
]
},
{ "blankLine": "always", "prev": ["*"], "next": ["if", "return"] },
{ "blankLine": "always", "prev": ["*"], "next": ["try"] }
],
"no-await-in-loop": "off"
{
"blankLine": "always",
"prev": [
"*"
],
"next": [
"if",
"return"
]
},
{
"blankLine": "always",
"prev": [
"*"
],
"next": [
"try"
]
}
]
}
}
}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@
"n/file-extension-in-import": "off",
"no-lone-blocks": "off",
"capitalized-comments": "off",
"unicorn/prefer-ternary": "off"
"unicorn/prefer-ternary": "off",
"no-await-in-loop": "off"
}
}
}
}
17 changes: 8 additions & 9 deletions src/checkDifferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ export const checkDifferences = async (
addDifferenceToDifferences({
difference,
differences,
shotItem: item[1]
})
shotItem: item[1],
});
},
);

Expand All @@ -135,18 +135,17 @@ export const checkDifferences = async (
export const addDifferenceToDifferences = ({
difference,
differences,
shotItem
shotItem,
}: {
shotItem: ShotItem,
differences: Differences,
difference: Difference
shotItem: ShotItem;
differences: Differences;
difference: Difference;
}) => {
if (difference.status === 'added')
differences.noBaselinesItems.push(shotItem);
else if (difference.status === 'changed')
differences.aboveThresholdDifferenceItems.push(shotItem);

if (difference.comparisonResult)
differences.comparisonResults[shotItem.id] =
difference.comparisonResult;
}
differences.comparisonResults[shotItem.id] = difference.comparisonResult;
};
38 changes: 25 additions & 13 deletions src/createShots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ import {
import type { Differences } from './checkDifferences';
import { takeScreenShots } from './shots/shots';

export const createShots = async ({ compareAfterShot }: {
compareAfterShot?: boolean
export const createShots = async ({
compareAfterShot,
}: {
compareAfterShot?: boolean;
} = {}): Promise<{
shotItems: ShotItem[];
/** Defined if using compareAfterShot option */
Expand All @@ -59,9 +61,7 @@ export const createShots = async ({ compareAfterShot }: {
noBaselinesItems: [],
};

const mergeDifferences = (props: {
differences?: Differences;
}) => {
const mergeDifferences = (props: { differences?: Differences }) => {
differences.aboveThresholdDifferenceItems.push(
...(props.differences?.aboveThresholdDifferenceItems ?? []),
);
Expand Down Expand Up @@ -125,11 +125,14 @@ export const createShots = async ({ compareAfterShot }: {
log.process(
'info',
'general',
`Prepared ${shotItems.length
`Prepared ${
shotItems.length
} ladle stories for screenshots on ${browser.name()}`,
);

mergeDifferences(await takeScreenShots(shotItems, { browser, compareAfterShot }));
mergeDifferences(
await takeScreenShots(shotItems, { browser, compareAfterShot }),
);
});

localServer?.close();
Expand Down Expand Up @@ -192,11 +195,14 @@ export const createShots = async ({ compareAfterShot }: {
log.process(
'info',
'general',
`Prepared ${shotItems.length
`Prepared ${
shotItems.length
} Histoire stories for screenshots on ${browser.name()}`,
);

mergeDifferences(await takeScreenShots(shotItems, { browser, compareAfterShot }));
mergeDifferences(
await takeScreenShots(shotItems, { browser, compareAfterShot }),
);
});

localServer?.close();
Expand Down Expand Up @@ -258,11 +264,14 @@ export const createShots = async ({ compareAfterShot }: {
log.process(
'info',
'general',
`Prepared ${shotItems.length
`Prepared ${
shotItems.length
} stories for screenshots on ${browser.name()}`,
);

mergeDifferences(await takeScreenShots(shotItems, { browser, compareAfterShot }));
mergeDifferences(
await takeScreenShots(shotItems, { browser, compareAfterShot }),
);
});

localServer?.close();
Expand Down Expand Up @@ -317,11 +326,14 @@ export const createShots = async ({ compareAfterShot }: {
log.process(
'info',
'general',
`Prepared ${shotItems.length
`Prepared ${
shotItems.length
} pages for screenshots on ${browser.name()}`,
);

mergeDifferences(await takeScreenShots(shotItems, { browser, compareAfterShot }));
mergeDifferences(
await takeScreenShots(shotItems, { browser, compareAfterShot }),
);
});

log.process('info', 'general', 'Screenshots done!');
Expand Down
4 changes: 3 additions & 1 deletion src/docker-runner/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ export const executeDockerRun = async ({ version }: { version: string }) => {
isGenerateMetaEnabled ? '-e LOST_PIXEL_GENERATE_META=true' : '',
isLocalDebugModeEnabled ? '-e LOST_PIXEL_LOCAL=true' : '',
// Usage: npx lost-pixel docker --dockerArgs="x y -z"
...(argv.dockerArgs ? argv.dockerArgs.split(' ').filter(arg => arg.trim()) : []),
...(argv.dockerArgs
? argv.dockerArgs.split(' ').filter((arg) => arg.trim())
: []),
`lostpixel/lost-pixel:v${version}`,
];

Expand Down
8 changes: 3 additions & 5 deletions src/runner.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import path from 'node:path';
import fse, { writeFileSync } from 'fs-extra';
import {
checkDifferences,
type Differences,
} from './checkDifferences';
import { checkDifferences, type Differences } from './checkDifferences';
import {
createShotsFolders,
exitProcess,
Expand Down Expand Up @@ -91,7 +88,8 @@ export const runner = async (config: GenerateOnlyModeConfig) => {
log.process(
'info',
'general',
`Writing meta file with ${Object.entries(differences.comparisonResults).length
`Writing meta file with ${
Object.entries(differences.comparisonResults).length
} items.`,
);
writeFileSync(
Expand Down
34 changes: 17 additions & 17 deletions src/shots/shots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ const takeScreenShot = async ({
browser,
item: [index, shotItem],
logger,
compareAfterShot
compareAfterShot,
}: {
browser: Browser;
item: [number, ShotItem];
logger: ReturnType<typeof log.item>;
compareAfterShot?: boolean
compareAfterShot?: boolean;
}): Promise<{
success: boolean;
/** Defined if using compareAfterShot */
Expand Down Expand Up @@ -158,8 +158,7 @@ const takeScreenShot = async ({
retryCount <= config.flakynessRetries;
retryCount++
) {
if (retryCount > 0)
await sleep(config.waitBetweenFlakynessRetries);
if (retryCount > 0) await sleep(config.waitBetweenFlakynessRetries);

const screenshotOptions: PageScreenshotOptions = {
path: shotItem.filePathCurrent,
Expand Down Expand Up @@ -202,8 +201,7 @@ const takeScreenShot = async ({
`Screenshot of '${shotItem.shotName}' taken (Retry ${retryCount}). Hash: ${currentShotHash} - Previous hash: ${lastShotHash}`,
);

if (lastShotHash === currentShotHash)
break;
if (lastShotHash === currentShotHash) break;
}

lastShotHash = currentShotHash;
Expand Down Expand Up @@ -240,21 +238,20 @@ const takeScreenShot = async ({
export const takeScreenShots = async (
shotItems: ShotItem[],
props: {
browser?: BrowserType,
compareAfterShot?: boolean
}
browser?: BrowserType;
compareAfterShot?: boolean;
},
): Promise<{ differences?: Differences }> => {
const browser = await (props.browser ?? getBrowser()).launch();
const total = shotItems.length;

const differences: Differences | undefined =
props.compareAfterShot
? {
const differences: Differences | undefined = props.compareAfterShot
? {
aboveThresholdDifferenceItems: [],
comparisonResults: {},
noBaselinesItems: [],
}
: undefined;
: undefined;

await mapLimit<[number, ShotItem], void>(
shotItems.entries(),
Expand All @@ -271,7 +268,8 @@ export const takeScreenShots = async (
logger.process(
'info',
'general',
`Taking screenshot of '${shotItem.shotName} ${shotItem.breakpoint ? `[${shotItem.breakpoint}]` : ''
`Taking screenshot of '${shotItem.shotName} ${
shotItem.breakpoint ? `[${shotItem.breakpoint}]` : ''
}'`,
);

Expand All @@ -288,8 +286,11 @@ export const takeScreenShots = async (
);

if (config.compareAfterShot && differences && result.difference)
addDifferenceToDifferences({ difference: result.difference, differences, shotItem });

addDifferenceToDifferences({
difference: result.difference,
differences,
shotItem,
});
} else {
logger.process(
'info',
Expand All @@ -304,4 +305,3 @@ export const takeScreenShots = async (

return { differences };
};

0 comments on commit ec65041

Please sign in to comment.