Skip to content

Commit

Permalink
feat(plugins): add plugin for lost-pixel config (#630)
Browse files Browse the repository at this point in the history
* feat(plugins): add plugin for lost-pixel config

* Fix: add lost-pixel config file to fixtures

* Fix: adjust test exectuion assertion

* Fix: adjust config file casing

* Fix: adjust lost-pixel test

* Fix: remove - from the lostpixel config file
  • Loading branch information
PeterMK85 committed May 14, 2024
1 parent d7b2545 commit 24772ca
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 0 deletions.
33 changes: 33 additions & 0 deletions packages/knip/fixtures/plugins/lost-pixel/lostpixel.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import type { CustomProjectConfig } from 'lost-pixel';

export const config: CustomProjectConfig = {
apiKey: process.env.LOST_PIXEL_API_KEY,

ladleShots: {
ladleUrl: 'dist/ladle',
},

lostPixelProjectId: process.env.LOST_PIXEL_PROJECT_ID,

shotConcurrency: 5,
setPendingStatusCheck: true,

imagePathBaseline: '.lostpixel/baseline',
imagePathCurrent: '.lostpixel/current',
imagePathDifference: '.lostpixel/difference',

ciBuildId: process.env.BUILD_ID,
ciBuildNumber: process.env.BUILD_NUMBER,
repository: process.env.REPOSITORY_NAME,
commitRefName: process.env.CHANGE_BRANCH ?? process.env.BRANCH_NAME,
commitHash: process.env.GIT_COMMIT,

configureBrowser: () => ({
userAgent:
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36',
viewport: {
width: 800,
height: 600,
},
}),
};
7 changes: 7 additions & 0 deletions packages/knip/fixtures/plugins/lost-pixel/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "@fixtures/lost-pixel",
"version": "*",
"devDependencies": {
"lost-pixel": "*"
}
}
4 changes: 4 additions & 0 deletions packages/knip/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,10 @@
"title": "linthtml plugin configuration (https://github.com/webpro/knip/blob/main/src/plugins/linthtml/README.md)",
"$ref": "#/definitions/plugin"
},
"lost-pixel": {
"title": "lost-pixel plugin configuration (https://github.com/webpro/knip/blob/main/src/plugins/lost-pixel/README.md)",
"$ref": "#/definitions/plugin"
},
"markdownlint": {
"title": "markdownlint plugin configuration (https://github.com/webpro/knip/blob/main/src/plugins/markdownlint/README.md)",
"$ref": "#/definitions/plugin"
Expand Down
1 change: 1 addition & 0 deletions packages/knip/src/ConfigurationValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ const pluginsSchema = z.object({
lefthook: pluginSchema,
'lint-staged': pluginSchema,
linthtml: pluginSchema,
'lost-pixel': pluginSchema,
markdownlint: pluginSchema,
mocha: pluginSchema,
moonrepo: pluginSchema,
Expand Down
1 change: 1 addition & 0 deletions packages/knip/src/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export { default as jest } from './jest/index.js';
export { default as lefthook } from './lefthook/index.js';
export { default as lintStaged } from './lint-staged/index.js';
export { default as linthtml } from './linthtml/index.js';
export { default as lostPixel } from './lost-pixel/index.js';
export { default as markdownlint } from './markdownlint/index.js';
export { default as mocha } from './mocha/index.js';
export { default as moonrepo } from './moonrepo/index.js';
Expand Down
20 changes: 20 additions & 0 deletions packages/knip/src/plugins/lost-pixel/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { EnablerPatterns } from '#p/types/config.js';
import type { IsPluginEnabled, Plugin } from '#p/types/plugins.js';
import { hasDependency } from '#p/util/plugin.js';

// link to lost-pixel docs https://docs.lost-pixel.com/user-docs/api-reference/lost-pixel.config.js-or-ts

const title = 'Lost Pixel';

const enablers: EnablerPatterns = ['lost-pixel'];

const isEnabled: IsPluginEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);

const config = ['lostpixel.config.{js,ts}'];

export default {
title,
enablers,
isEnabled,
config,
} satisfies Plugin;
21 changes: 21 additions & 0 deletions packages/knip/test/plugins/lost-pixel.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { test } from 'bun:test';
import assert from 'node:assert/strict';
import { main } from '../../src/index.js';
import { resolve } from '../../src/util/path.js';
import baseArguments from '../helpers/baseArguments.js';
import baseCounters from '../helpers/baseCounters.js';

const cwd = resolve('fixtures/plugins/lost-pixel');

test('Find dependencies with the lost-pixel plugin', async () => {
const { counters } = await main({
...baseArguments,
cwd,
});

assert.deepEqual(counters, {
...baseCounters,
processed: 1,
total: 1,
});
});

0 comments on commit 24772ca

Please sign in to comment.