Skip to content

Commit

Permalink
Fix playwright-ct plugin, add coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Oct 7, 2023
1 parent ee57600 commit d6fb53d
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 8 deletions.

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

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

9 changes: 9 additions & 0 deletions fixtures/plugins/playwright-ct2/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "@fixtures/playwright-ct2",
"knip": {
"playwright-ct": true
},
"devDependencies": {
"@playwright/experimental-ct-vue": "*"
}
}
11 changes: 11 additions & 0 deletions fixtures/plugins/playwright-ct2/playwright-ct.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const defineConfig = c => c;

export default defineConfig({
testDir: './tests/component',
testMatch: ['**/*.spec.ts'],
projects: [
{
name: 'chromium',
},
],
});
7 changes: 7 additions & 0 deletions fixtures/plugins/playwright-ct2/src/unused.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig, devices } from '@playwright/experimental-ct-vue';

test.describe('stuff', () => {
test('thing', async () => {
expect(null).toMatch(null);
});
});
7 changes: 7 additions & 0 deletions fixtures/plugins/playwright-ct2/tests/component/some.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig, devices } from '@playwright/experimental-ct-vue';

test.describe('stuff', () => {
test('thing', async () => {
expect(null).toMatch(null);
});
});
13 changes: 6 additions & 7 deletions src/plugins/playwright-ct/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { dirname, join } from '../../util/path.js';
import { timerify } from '../../util/Performance.js';
import { hasDependency, load } from '../../util/plugin.js';
import { toEntryPattern } from '../../util/protocols.js';
import { toEntryPatterns } from '../playwright/index.js';
import type { GenericPluginCallback, IsPluginEnabledCallback } from '../../types/plugins.js';

// https://playwright.dev/docs/test-components
Expand All @@ -18,11 +17,11 @@ export const CONFIG_FILE_PATTERNS = ['playwright-ct.config.{js,ts}', 'playwright
/** @public */
export const ENTRY_FILE_PATTERNS = ['**/*.@(spec|test).?(c|m)[jt]s?(x)'];

const findPlaywrightCTDependencies: GenericPluginCallback = async configFilePath => {
const cfg = await load(configFilePath);
const dir = cfg.testDir ? join(dirname(configFilePath), cfg.testDir) : dirname(configFilePath);
const entryPatterns = (cfg.testMatch ? [cfg.testMatch] : ENTRY_FILE_PATTERNS).map(p => toEntryPattern(join(dir, p)));
return entryPatterns;
const findPlaywrightCTDependencies: GenericPluginCallback = async (configFilePath, { cwd }) => {
const config = await load(configFilePath);
const entryPatterns = toEntryPatterns(config.testMatch, cwd, configFilePath, config);
if (entryPatterns.length > 0) return entryPatterns;
return toEntryPatterns(ENTRY_FILE_PATTERNS, cwd, configFilePath, config);
};

export const findDependencies = timerify(findPlaywrightCTDependencies);
2 changes: 1 addition & 1 deletion src/plugins/playwright/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const ENTRY_FILE_PATTERNS = ['**/*.@(spec|test).?(c|m)[jt]s?(x)'];

export const CONFIG_FILE_PATTERNS = ['playwright.config.{js,ts}'];

const toEntryPatterns = (
export const toEntryPatterns = (
testMatch: string | RegExp | Array<string | RegExp> | undefined,
cwd: string,
configFilePath: string,
Expand Down
24 changes: 24 additions & 0 deletions tests/plugins/playwright-ct2.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { main } from '../../src/index.js';
import { join, resolve } from '../../src/util/path.js';
import baseArguments from '../helpers/baseArguments.js';
import baseCounters from '../helpers/baseCounters.js';

const cwd = resolve('fixtures/plugins/playwright-ct2');

test('Find dependencies in Playwright for components configuration', async () => {
const { issues, counters } = await main({
...baseArguments,
cwd,
});

assert(issues.files.has(join(cwd, 'src/unused.spec.ts')));

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

0 comments on commit d6fb53d

Please sign in to comment.