Skip to content

Commit

Permalink
Add webdriver-io plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Jun 17, 2024
1 parent df35b9f commit 7414dc1
Show file tree
Hide file tree
Showing 12 changed files with 102 additions and 0 deletions.
Binary file modified bun.lockb
Binary file not shown.
Empty file.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions packages/knip/fixtures/plugins/webdriver-io/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "@fixtures/webdriver-io",
"version": "*",
"scripts": {
"test": "wdio"
},
"dependencies": {
"@wdio/cli": "*",
"@wdio/mocha-framework": "*",
"@wdio/concise-reporter": "*",
"@wdio/browser-runner": "*"
}
}
5 changes: 5 additions & 0 deletions packages/knip/fixtures/plugins/webdriver-io/wdio.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
exports.config = {
runner: ['browser', {}],
framework: 'mocha',
reporters: ['concise'],
};
1 change: 1 addition & 0 deletions packages/knip/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
"@types/picomatch": "2.3.3",
"@types/resolve": "^1.20.6",
"@types/webpack": "^5.28.5",
"@wdio/types": "^8.38.2",
"glob": "^10.3.12",
"playwright": "^1.44.1",
"release-it": "^17.3.0",
Expand Down
4 changes: 4 additions & 0 deletions packages/knip/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,10 @@
"title": "vue plugin configuration (https://knip.dev/reference/plugins/vue)",
"$ref": "#/definitions/plugin"
},
"webdriver-io": {
"title": "webdriver-io plugin configuration (https://knip.dev/reference/plugins/webdriver-io)",
"$ref": "#/definitions/plugin"
},
"webpack": {
"title": "Webpack plugin configuration (https://knip.dev/reference/plugins/webpack)",
"$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 @@ -138,6 +138,7 @@ const pluginsSchema = z.object({
vue: pluginSchema,
vite: pluginSchema,
vitest: pluginSchema,
'webdriver-io': pluginSchema,
webpack: pluginSchema,
wireit: pluginSchema,
wrangler: 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 @@ -60,6 +60,7 @@ export { default as vercelOg } from './vercel-og/index.js';
export { default as vite } from './vite/index.js';
export { default as vitest } from './vitest/index.js';
export { default as vue } from './vue/index.js';
export { default as webdriverIo } from './webdriver-io/index.js';
export { default as webpack } from './webpack/index.js';
export { default as wireit } from './wireit/index.js';
export { default as wrangler } from './wrangler/index.js';
Expand Down
45 changes: 45 additions & 0 deletions packages/knip/src/plugins/webdriver-io/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import type { IsPluginEnabled, Plugin, ResolveConfig } from '#p/types/plugins.js';
import { hasDependency } from '#p/util/plugin.js';
import type { WebdriverIOConfig } from './types.js';

// https://webdriver.io/docs/configuration

const title = 'WebdriverIO';

const enablers = ['@wdio/cli'];

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

const config = ['wdio.conf.js'];

const resolveConfig: ResolveConfig<WebdriverIOConfig> = async config => {
const cfg = config?.config;
if (!cfg) return [];

const frameworks = cfg?.framework ? [`@wdio/${cfg.framework}-framework`] : [];

const runners =
cfg?.runner && cfg.runner !== 'local'
? [`@wdio/${Array.isArray(cfg.runner) ? cfg.runner[0] : cfg.runner}-runner`]
: [];

const reporters = cfg?.reporters
? cfg.reporters
.flatMap(reporter => {
if (typeof reporter === 'string') return [reporter];
if (Array.isArray(reporter) && typeof reporter[0] === 'string') return [reporter[0]];
return [];
})
.map(reporter => `@wdio/${reporter}-reporter`)
: [];

return [...frameworks, ...runners, ...reporters];
};

export default {
title,
enablers,
isEnabled,
config,
resolveConfig,
} satisfies Plugin;
5 changes: 5 additions & 0 deletions packages/knip/src/plugins/webdriver-io/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// <reference types="@wdio/types" />

export type WebdriverIOConfig = {
config: WebdriverIO.Config;
};
21 changes: 21 additions & 0 deletions packages/knip/test/plugins/webdriver-io.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/webdriver-io');

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

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

0 comments on commit 7414dc1

Please sign in to comment.