-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add checks based on git diff in it tests
- Loading branch information
Showing
14 changed files
with
133 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ import { minVersion } from 'semver'; | |
import { createTestEnvironmentAngular } from './test-environments/create-test-environment-angular'; | ||
import { createTestEnvironmentAngularWithO3rCore } from './test-environments/create-test-environment-angular-with-o3r-core'; | ||
import { createTestEnvironmentBlank } from './test-environments/create-test-environment-blank'; | ||
import {createWithLock, packageManagerInstall, setPackagerManagerConfig} from './utilities'; | ||
import { createWithLock, packageManagerInstall, setPackagerManagerConfig, setupGit } from './utilities'; | ||
|
||
/** | ||
* 'blank' only create yarn/npm config | ||
|
@@ -134,24 +134,7 @@ export async function prepareTestEnv(folderName: string, type: PrepareTestEnvTyp | |
} | ||
|
||
// Setup git and initial commit to easily make checks on the diff inside the tests | ||
try { | ||
const authorName = 'otter it tests'; | ||
const authorEmail = '[email protected]'; | ||
execSync('git init -b master && git add -A && git commit -m "initial commit"', { | ||
cwd: appFolderPath, | ||
env: { | ||
/* eslint-disable @typescript-eslint/naming-convention, camelcase */ | ||
GIT_AUTHOR_NAME: authorName, | ||
GIT_COMMITTER_NAME: authorName, | ||
GIT_AUTHOR_EMAIL: authorEmail, | ||
GIT_COMMITTER_EMAIL: authorEmail | ||
/* eslint-enable @typescript-eslint/naming-convention, camelcase */ | ||
} | ||
}); | ||
} catch (err) { | ||
// eslint-disable-next-line no-console | ||
console.error('Unable to setup git for the test-app', err); | ||
} | ||
setupGit(appFolderPath); | ||
|
||
return appFolderPath; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { execFileSync, ExecFileSyncOptionsWithStringEncoding, execSync } from 'node:child_process'; | ||
|
||
/** | ||
* Setup git and initial commit | ||
* @param workingDirectory | ||
*/ | ||
export function setupGit(workingDirectory?: string) { | ||
const authorName = 'otter it tests'; | ||
const authorEmail = '[email protected]'; | ||
execSync('git init -b master && git add -A && git commit -m "initial commit" && git tag -a after-init -m "after-init"', { | ||
cwd: workingDirectory, | ||
env: { | ||
/* eslint-disable @typescript-eslint/naming-convention, camelcase */ | ||
GIT_AUTHOR_NAME: authorName, | ||
GIT_COMMITTER_NAME: authorName, | ||
GIT_AUTHOR_EMAIL: authorEmail, | ||
GIT_COMMITTER_EMAIL: authorEmail | ||
/* eslint-enable @typescript-eslint/naming-convention, camelcase */ | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* Get all files added, modified or deleted based on baseBranch param | ||
* @param workingDirectory | ||
* @param baseBranch | ||
*/ | ||
export function getGitDiff(workingDirectory?: string, baseBranch = 'after-init') { | ||
const execOptions: ExecFileSyncOptionsWithStringEncoding = {stdio: ['pipe', 'pipe', 'ignore'], encoding: 'utf8', cwd: workingDirectory}; | ||
const untrackedFiles = execFileSync('git', ['ls-files', '--others', '--exclude-standard'], execOptions).split('\n'); | ||
const trackedFiles = execFileSync('git', ['diff', '--name-status', baseBranch], execOptions).split('\n'); | ||
const indexedFiles = execFileSync('git', ['diff', '--cached', '--name-status', baseBranch], execOptions).split('\n'); | ||
const extractFile = (line: string) => line.replace(/^[ADM]\s*/, ''); | ||
const cleanList = (list: string[]) => [...new Set(list.filter((file) => !!file))]; | ||
const added = cleanList([...untrackedFiles, ...[...trackedFiles, ...indexedFiles].filter((line) => /^A/.test(line)).map(extractFile)]); | ||
const modified = cleanList([...trackedFiles, ...indexedFiles].filter((line) => /^M/.test(line)).map(extractFile)); | ||
const deleted = cleanList([...trackedFiles, ...indexedFiles].filter((line) => /^D/.test(line)).map(extractFile)); | ||
return { | ||
added, | ||
modified, | ||
deleted, | ||
all: cleanList([...added, ...modified, ...deleted]) | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters