-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
167 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`CLI End-to-End Tests should display help information 1`] = ` | ||
"Usage: cli [options] [command] | ||
Options: | ||
-h, --help display help for command | ||
Commands: | ||
checkout [options] <migration> Check out any repositories that are | ||
candidates for a given migration | ||
apply [options] <migration> Apply a migration to all checked out | ||
repositories | ||
commit [options] <migration> Commit all changes for the specified | ||
migration | ||
reset [options] <migration> Reset all changes for the specified | ||
migration | ||
push [options] <migration> Push all changes for the specified | ||
migration | ||
pr-preview [options] <migration> View a preview of the PR messages for the | ||
specified migration | ||
pr [options] <migration> Create PRs for the specified migration | ||
pr-status [options] <migration> Check the status of all PRs for the | ||
specified migration | ||
list <migration> List all checked out repositories for the | ||
given migration | ||
version Print Shepherd version | ||
help [command] display help for command | ||
" | ||
`; | ||
exports[`CLI End-to-End Tests should successfully checkout using repos flag 1`] = ` | ||
"Using 2 selected repos | ||
[aorinevo/shepherd-test-repo-1] 1/2 | ||
> Running should_migrate steps | ||
✔ Completed all should_migrate steps successfully | ||
> Running post_checkout steps | ||
✔ Completed all post_checkout steps successfully | ||
[aorinevo/shepherd-test-repo-2] 2/2 | ||
> Running should_migrate steps | ||
✔ Completed all should_migrate steps successfully | ||
> Running post_checkout steps | ||
✔ Completed all post_checkout steps successfully | ||
Checked out 2 out of 2 repos | ||
" | ||
`; | ||
exports[`CLI End-to-End Tests should successfully run apply on a migration 1`] = ` | ||
" | ||
[NerdWalletOSS/shepherd] 1/1 | ||
ℹ Running apply steps | ||
$ touch $SHEPHERD_REPO_DIR/testfile.js && echo "some content" > $SHEPHERD_REPO_DIR/testfile.js | ||
Step "touch $SHEPHERD_REPO_DIR/testfile.js && echo "some content" > $SHEPHERD_REPO_DIR/testfile.js" exited with 0 | ||
✔ Completed all apply steps successfully | ||
" | ||
`; | ||
exports[`CLI End-to-End Tests should successfully run apply on a migration 2`] = ` | ||
"On branch 2024.10.06-test-migration | ||
Untracked files: | ||
(use "git add <file>..." to include in what will be committed) | ||
testfile.js | ||
nothing added to commit but untracked files present (use "git add" to track) | ||
" | ||
`; | ||
exports[`CLI End-to-End Tests should successfully run checkout on a migration 1`] = ` | ||
" | ||
[NerdWalletOSS/shepherd] 1/1 | ||
> Running should_migrate steps | ||
✔ Completed all should_migrate steps successfully | ||
> Running post_checkout steps | ||
✔ Completed all post_checkout steps successfully | ||
Checked out 1 out of 1 repos | ||
" | ||
`; |
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,10 @@ | ||
id: 2024.10.06-test-migration | ||
title: | | ||
feat: test migration | ||
adapter: | ||
type: github | ||
search_query: repo:NerdWalletOSS/shepherd path:/ | ||
hooks: | ||
apply: 'touch $SHEPHERD_REPO_DIR/testfile.js && echo "some content" > $SHEPHERD_REPO_DIR/testfile.js' | ||
pr_message: | | ||
echo "e2e test suite" |
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,54 @@ | ||
import { execSync } from 'child_process'; | ||
import path from 'path'; | ||
import fs from 'fs'; | ||
import os from 'os'; | ||
|
||
describe('CLI End-to-End Tests', () => { | ||
let shepherdRepoDir: string; | ||
|
||
beforeAll(() => { | ||
shepherdRepoDir = path.resolve( | ||
os.homedir(), | ||
'.shepherd', | ||
'2024.10.06-test-migration', | ||
'repos', | ||
'NerdWalletOSS', | ||
'shepherd' | ||
); | ||
}); | ||
|
||
const cliPath = path.resolve(__dirname, '../lib/cli.js'); | ||
|
||
const runCLI = (args: string) => { | ||
return execSync(`node ${cliPath} ${args}`, { encoding: 'utf-8' }); | ||
}; | ||
|
||
it('should display help information', async () => { | ||
const output = runCLI('--help'); | ||
expect(output).toMatchSnapshot(); | ||
}); | ||
|
||
it('should display version information', async () => { | ||
const output = runCLI('version'); | ||
expect(output.split('.').length).toEqual(3); | ||
}); | ||
|
||
it('should successfully run checkout on a migration', async () => { | ||
const output = runCLI(`checkout ${path.join(__dirname, './assets/checkout-apply')}`); | ||
expect(output).toMatchSnapshot(); | ||
}); | ||
|
||
it('should successfully run apply on a migration', async () => { | ||
const output = runCLI(`apply ${path.join(__dirname, './assets/checkout-apply')}`); | ||
expect(output).toMatchSnapshot(); | ||
const gitDiffOutput = execSync(`cd ${shepherdRepoDir} && git status`, { encoding: 'utf-8' }); | ||
expect(gitDiffOutput).toMatchSnapshot(); | ||
}); | ||
|
||
it('should successfully checkout using repos flag', async () => { | ||
const output = runCLI( | ||
`checkout --repos "aorinevo/shepherd-test-repo-1,aorinevo/shepherd-test-repo-2" ${path.join(__dirname, './assets/checkout-apply')}` | ||
); | ||
expect(output).toMatchSnapshot(); | ||
}); | ||
}); |
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,19 @@ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
extensionsToTreatAsEsm: ['.ts', '.mts'], | ||
coveragePathIgnorePatterns: ['\\.mock\\.ts$'], | ||
moduleFileExtensions: ['ts', 'mts', 'tsx', 'js', 'mjs', 'jsx', 'json', 'node'], | ||
testRegex: '(/(__tests__|e2e)/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?|mts)$', | ||
transform: { | ||
'^.+\\.(ts|mts|tsx|js|mjs)?$': 'babel-jest', | ||
'^.+\\.js$': 'babel-jest', | ||
}, | ||
moduleNameMapper: { | ||
'^(\\.{1,2}/.*)\\.js$': '$1', // Map ".js" to ".ts" in imports | ||
}, | ||
transformIgnorePatterns: [ | ||
'/node_modules/(?!(@octokit|before-after-hook|universal-user-agent|bottleneck|@octokit/core|@octokit/plugin-retry|@octokit/plugin-rest-endpoint-methods|@octokit/plugin-throttling|chalk)/)', // Ensure these node_modules are transformed | ||
], | ||
collectCoverageFrom: ['src/**/*.{ts,tsx,js,jsx}'], // Collect coverage from src directory | ||
}; |
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