teqo-backup/tests/unit/playwrightE2eArgs.unit.spec.ts
Francisco Solla 8c915e59fc fix(S6-FOLLOWUP): test:e2e:affected rodava a suíte completa — --no-deps desliga o closure de deps dos projects em runs filtrados
Causa raiz (medida com o binário 1.58.2, config real): commander parseia
posicionais e -g/--list funcionam; o que arrastava a suíte era o closure de
dependências do dev mode (setup<-campaign<-frontend<-admin): filtrar um spec
do frontend puxava campaign(160)+setup(2). run-e2e-affected.mjs agora gera
test:e2e <passthrough verbatim> --no-deps -- <paths> via helpers puros em
scripts/lib/playwright-e2e-args.mjs (unit-pinned); passthrough corrigido
(pnpm consome o -- e o path era descartado); run-e2e-affected.mjs entrou em
HIGH_RISK_EXACT. Docs: receitas de filtro no playwright.config.ts, AGENTS.md,
changelog.
2026-08-18 19:09:12 -03:00

101 lines
3.6 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import {
buildPlaywrightE2eArgs,
parsePassthroughArgs,
} from '../../scripts/lib/playwright-e2e-args.mjs'
// S6-FOLLOWUP (2026-08-18): the e2e CLI filters WERE ignored locally because
// the dev-mode project dependency chain drags every dependency project's files
// into a selected run (buildProjectsClosure). The helpers pin the generated
// argv: `--no-deps` on filtered runs only (full runs keep the OPS34 dev
// chain), generated scope paths after the `--` separator, and a verbatim
// passthrough (pnpm consumes the first `--`, so the script never sees it; flag
// values like `-g grade` must not be re-classified).
describe('parsePassthroughArgs', () => {
it('returns nothing for a plain invocation', () => {
expect(parsePassthroughArgs(['node', 'scripts/run-e2e-affected.mjs'])).toEqual([])
})
it('keeps bare args when pnpm consumed the `--` separator', () => {
expect(
parsePassthroughArgs(['node', 'scripts/run-e2e-affected.mjs', 'tests/x.e2e.spec.ts']),
).toEqual(['tests/x.e2e.spec.ts'])
})
it('strips exactly one leading `--` (direct invocation with separator)', () => {
expect(
parsePassthroughArgs(['node', 'scripts/run-e2e-affected.mjs', '--', '-g', 'grade']),
).toEqual(['-g', 'grade'])
})
it('keeps flags and flag values verbatim', () => {
expect(
parsePassthroughArgs([
'node',
'scripts/run-e2e-affected.mjs',
'--grep=home',
'-g',
'grade',
'--',
'tests/x.e2e.spec.ts',
]),
).toEqual(['--grep=home', '-g', 'grade', '--', 'tests/x.e2e.spec.ts'])
})
})
describe('buildPlaywrightE2eArgs', () => {
it('keeps the full-suite form when nothing is filtered (dev chain intact)', () => {
expect(buildPlaywrightE2eArgs({ scopeSpecPaths: [], passthroughArgs: [] })).toEqual([
'test:e2e',
])
})
it('keeps non-filter flags on the full-suite form (shards, reporters, workers)', () => {
expect(buildPlaywrightE2eArgs({ passthroughArgs: ['--shard=1/2', '--reporter=line'] })).toEqual(
['test:e2e', '--shard=1/2', '--reporter=line'],
)
})
it('disables the dependency closure and separates generated paths with -- on filtered runs', () => {
expect(
buildPlaywrightE2eArgs({ scopeSpecPaths: ['tests/e2e/campaignHomeActions.e2e.spec.ts'] }),
).toEqual(['test:e2e', '--no-deps', '--', 'tests/e2e/campaignHomeActions.e2e.spec.ts'])
})
it('treats a bare passthrough path as a filtered run and adds --no-deps', () => {
expect(buildPlaywrightE2eArgs({ passthroughArgs: ['tests/e2e/frontend.e2e.spec.ts'] })).toEqual(
['test:e2e', 'tests/e2e/frontend.e2e.spec.ts', '--no-deps'],
)
})
it('treats filter flags (--project, -g/--grep) as filtered runs', () => {
expect(buildPlaywrightE2eArgs({ passthroughArgs: ['--project=campaign'] })).toEqual([
'test:e2e',
'--project=campaign',
'--no-deps',
])
expect(buildPlaywrightE2eArgs({ passthroughArgs: ['-g', 'grade'] })).toEqual([
'test:e2e',
'-g',
'grade',
'--no-deps',
])
})
it('does not duplicate an explicit --no-deps passthrough', () => {
expect(buildPlaywrightE2eArgs({ passthroughArgs: ['--no-deps'] })).toEqual([
'test:e2e',
'--no-deps',
])
})
it('merges scope paths and passthrough positionals in a single filtered run', () => {
expect(
buildPlaywrightE2eArgs({
scopeSpecPaths: ['tests/e2e/a.e2e.spec.ts'],
passthroughArgs: ['tests/e2e/b.e2e.spec.ts'],
}),
).toEqual(['test:e2e', 'tests/e2e/b.e2e.spec.ts', '--no-deps', '--', 'tests/e2e/a.e2e.spec.ts'])
})
})