Skip to content

Commit 1e112d8

Browse files
committed
Add globalSetup and globalTeardown to playwright plugin (closes #1202)
1 parent 78cab1c commit 1e112d8

File tree

2 files changed

+36
-16
lines changed

2 files changed

+36
-16
lines changed

packages/knip/src/plugins/playwright/index.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { IsPluginEnabled, Plugin, ResolveConfig } from '../../types/config.js';
2-
import { toDeferResolve, toEntry } from '../../util/input.js';
2+
import { arrayify } from '../../util/array.js';
3+
import { type Input, toDeferResolve, toEntry } from '../../util/input.js';
34
import { join, relative } from '../../util/path.js';
45
import { hasDependency } from '../../util/plugin.js';
56
import type { PlaywrightTestConfig } from './types.js';
@@ -33,15 +34,23 @@ const builtinReporters = ['dot', 'line', 'list', 'junit', 'html', 'blob', 'json'
3334

3435
export const resolveConfig: ResolveConfig<PlaywrightTestConfig> = async (localConfig, options) => {
3536
const { cwd, configFileDir } = options;
37+
38+
const inputs: Input[] = [];
39+
for (const id of arrayify(localConfig.globalSetup)) inputs.push(toEntry(id));
40+
for (const id of arrayify(localConfig.globalTeardown)) inputs.push(toEntry(id));
41+
3642
const projects = localConfig.projects ? [localConfig, ...localConfig.projects] : [localConfig];
43+
3744
const reporters = [localConfig.reporter].flat().flatMap(reporter => {
3845
const name = typeof reporter === 'string' ? reporter : reporter?.[0];
3946
if (!name || builtinReporters.includes(name)) return [];
4047
return [name];
4148
});
49+
4250
return projects
4351
.flatMap(config => toEntryPatterns(config.testMatch ?? entry, cwd, configFileDir, config, localConfig))
44-
.concat(reporters.map(id => toDeferResolve(id)));
52+
.concat(reporters.map(id => toDeferResolve(id)))
53+
.concat(inputs);
4554
};
4655

4756
const args = {

packages/knip/src/plugins/playwright/types.ts

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,38 @@
22

33
type LiteralUnion<T extends U, U = string> = T | (U & { zz_IGNORE_ME?: never });
44

5+
type BlobReporterOptions = { outputDir?: string; fileName?: string };
6+
type ListReporterOptions = { printSteps?: boolean };
7+
type JUnitReporterOptions = {
8+
outputFile?: string;
9+
stripANSIControlSequences?: boolean;
10+
includeProjectInTestName?: boolean;
11+
};
12+
type JsonReporterOptions = { outputFile?: string };
13+
type HtmlReporterOptions = {
14+
outputFolder?: string;
15+
open?: 'always' | 'never' | 'on-failure';
16+
host?: string;
17+
port?: number;
18+
attachmentsBaseURL?: string;
19+
title?: string;
20+
noSnippets?: boolean;
21+
};
22+
523
type ReporterDescription = Readonly<
624
| ['blob']
7-
| ['blob', { outputDir?: string; fileName?: string }]
25+
| ['blob', BlobReporterOptions]
826
| ['dot']
927
| ['line']
1028
| ['list']
11-
| ['list', { printSteps?: boolean }]
29+
| ['list', ListReporterOptions]
1230
| ['github']
1331
| ['junit']
14-
| ['junit', { outputFile?: string; stripANSIControlSequences?: boolean; includeProjectInTestName?: boolean }]
32+
| ['junit', JUnitReporterOptions]
1533
| ['json']
16-
| ['json', { outputFile?: string }]
34+
| ['json', JsonReporterOptions]
1735
| ['html']
18-
| [
19-
'html',
20-
{
21-
outputFolder?: string;
22-
open?: 'always' | 'never' | 'on-failure';
23-
host?: string;
24-
port?: number;
25-
attachmentsBaseURL?: string;
26-
},
27-
]
36+
| ['html', HtmlReporterOptions]
2837
| ['null']
2938
| [string]
3039
| [string, any]
@@ -43,4 +52,6 @@ export type PlaywrightTestConfig = {
4352
reporter?:
4453
| LiteralUnion<'dot' | 'line' | 'list' | 'junit' | 'html' | 'json' | 'github' | 'null', string>
4554
| ReporterDescription[];
55+
globalSetup?: string | Array<string>;
56+
globalTeardown?: string | Array<string>;
4657
};

0 commit comments

Comments
 (0)