This repository was archived by the owner on May 4, 2023. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ import {
1919 printViolation ,
2020} from "../utils/print" ;
2121import { BLANK_SHA } from "../utils/constants" ;
22+ import { isTestMode } from "../tests/test-utils" ;
2223
2324/**
2425 * Gets the changed file paths between two SHAs
@@ -43,7 +44,7 @@ function getChangedFilePaths(remoteSHA, localSHA) {
4344 * @param {string } localShaArg
4445 * @returns {{ remoteSha: string, localSha: string } } updated SHAs strings
4546 */
46- function checkSHAs ( remoteShaArg , localShaArg ) {
47+ export function checkSHAs ( remoteShaArg , localShaArg ) {
4748 let remoteSha = remoteShaArg ;
4849 let localSha = localShaArg ;
4950
@@ -69,6 +70,13 @@ function checkSHAs(remoteShaArg, localShaArg) {
6970 process . exit ( 0 ) ;
7071 }
7172
73+ if ( isTestMode ) {
74+ return {
75+ remoteSha : remoteShaArg ,
76+ localSha : localShaArg ,
77+ } ;
78+ }
79+
7280 return {
7381 remoteSha,
7482 localSha,
Original file line number Diff line number Diff line change 1- import { ACTION_GIT_PUSH_HOOK } from "../utils/constants" ;
2- import { executeCommand } from "./test-utils" ;
1+ import { ACTION_GIT_PUSH_HOOK , BLANK_SHA } from "../utils/constants" ;
2+ import { setToken } from "../utils/store" ;
3+ import { executeCommand , SAMPLE_TOKEN } from "./test-utils" ;
34
45describe ( "codiga git-push-hook" , ( ) => {
5- test ( "no git repository " , async ( ) => {
6+ test ( "check for same SHAs " , async ( ) => {
67 // run the command
7- await executeCommand ( [ ACTION_GIT_PUSH_HOOK ] ) . catch ( ( { stdout } ) => {
8- console . log ( "stdout: " , stdout ) ;
9- expect ( stdout ) . toMatch (
10- / U n a b l e t o e x e c u t e a g i t c o m m a n d b e c a u s e y o u ' r e n o t i n a g i t r e p o s i t o r y /
8+ await executeCommand ( [ ACTION_GIT_PUSH_HOOK , "1234" , "1234" ] ) . then (
9+ ( output ) => {
10+ expect ( output ) . toMatch ( / R e m o t e a n d l o c a l S H A a r e t h e s a m e / ) ;
11+ }
12+ ) ;
13+ } ) ;
14+
15+ test ( "check for closest SHA" , async ( ) => {
16+ // run the command
17+ await executeCommand ( [
18+ ACTION_GIT_PUSH_HOOK ,
19+ "--remote-sha" ,
20+ BLANK_SHA ,
21+ "--local-sha" ,
22+ "5678" ,
23+ ] ) . then ( ( output ) => {
24+ expect ( output ) . toMatch (
25+ / T r i e d t o f i n d c l o s e s t S H A b u t d i d n o t f i n d a n y ; e x i t i n g w i t h c o d e 0 /
1126 ) ;
1227 } ) ;
1328 } ) ;
29+
30+ test ( "unable to fetch rulesets when no API token is set" , async ( ) => {
31+ // run the command
32+ await executeCommand ( [
33+ ACTION_GIT_PUSH_HOOK ,
34+ "--remote-sha" ,
35+ "1234" ,
36+ "--local-sha" ,
37+ "5678" ,
38+ ] ) . catch ( ( { stdout } ) => {
39+ expect ( stdout ) . toMatch ( / W e w e r e u n a b l e t o f e t c h y o u r r u l e s e t s / ) ;
40+ } ) ;
41+ } ) ;
1442} ) ;
Original file line number Diff line number Diff line change 1+ rulesets :
2+ - react-best-practices
3+ - jsx-a11y
Original file line number Diff line number Diff line change 11import child_process from "child_process" ;
22import { printFailure } from "./print" ;
3+ import { isTestMode } from "../tests/test-utils" ;
34
45/**
56 * Executes a git command with the given args in that order
@@ -22,6 +23,10 @@ export function executeGitCommand(args) {
2223 * @returns the directory string or exits if there isn't one
2324 */
2425export function getRootDirectory ( ) {
26+ // if we're in test mode we'll skip this check
27+ if ( isTestMode ) return "./tests/fixtures" ;
28+
29+ // now look for a git repository
2530 const rootDirectory = executeGitCommand ( [ "rev-parse" , "--show-toplevel" ] ) ;
2631 if ( rootDirectory ) {
2732 return rootDirectory . split ( "\n" ) . join ( "" ) ;
@@ -74,6 +79,7 @@ export function getMainBranch() {
7479}
7580
7681export function findClosestSha ( ) {
82+ if ( isTestMode ) return null ;
7783 const currentBranch = getCurrentBranch ( ) ;
7884 const mainBranch = getMainBranch ( ) ;
7985 let closestSha = null ;
You can’t perform that action at this time.
0 commit comments