From bed44661e1e9670f8ab35083b4a0971f9bdf63b3 Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Wed, 17 Jul 2024 12:10:04 +0200 Subject: [PATCH] refactor --- packages/playwright/src/util.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/playwright/src/util.ts b/packages/playwright/src/util.ts index cbc072445b..9d076e0731 100644 --- a/packages/playwright/src/util.ts +++ b/packages/playwright/src/util.ts @@ -82,10 +82,15 @@ export type TestFileFilter = { }; export async function detectChangedFiles(baseCommit: string): Promise { - const untrackedFiles = childProcess.execSync('git ls-files --others --exclude-standard', { encoding: 'utf-8' }).split('\n').filter(Boolean); - const changedFiles = childProcess.execSync(`git diff ${baseCommit} --name-only`, { encoding: 'utf-8' }).split('\n').filter(Boolean); + const gitFileList = (command: string) => childProcess.execSync(`git ${command}`, { encoding: 'utf-8' }).split('\n').filter(Boolean).map(file => path.resolve(file)); + const untrackedFiles = gitFileList(`ls-files --others --exclude-standard`); + const trackedFilesWithChanges = gitFileList(`diff ${baseCommit} --name-only`); - return [...untrackedFiles, ...changedFiles, ...affectedTestFiles([...untrackedFiles, ...changedFiles].map(file => path.resolve(file)))]; + const filesWithChanges = [...untrackedFiles, ...trackedFilesWithChanges]; + return [ + ...filesWithChanges, + ...affectedTestFiles(filesWithChanges), + ]; } export async function createFileFiltersFromArguments(args: string[], onlyChanged: string | undefined): Promise {