feat: sparo completion build test

This commit is contained in:
Cheng Liu 2024-08-08 14:52:20 -07:00
parent e7cce69d52
commit ee5aee74e7
No known key found for this signature in database
GPG key ID: EEC8452F7DB85CD6
64 changed files with 580 additions and 0 deletions

View file

@ -0,0 +1,19 @@
// This is a workaround for https://github.com/eslint/eslint/issues/3458
require('@rushstack/heft-node-rig/profiles/default/includes/eslint/patch/modern-module-resolution');
// This is a workaround for https://github.com/microsoft/rushstack/issues/3021
require('@rushstack/heft-node-rig/profiles/default/includes/eslint/patch/custom-config-package-names');
module.exports = {
extends: [
'@rushstack/heft-node-rig/profiles/default/includes/eslint/profile/node-trusted-tool',
'@rushstack/heft-node-rig/profiles/default/includes/eslint/mixins/friendly-locals'
],
parserOptions: { tsconfigRootDir: __dirname },
overrides: [
{
files: ['*.ts', '*.tsx'],
rules: {}
}
]
};

View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) TikTok Pte. Ltd.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View file

@ -0,0 +1,11 @@
# sparo-completion-test
Building this project tests sparo command completion outputs
# Details
`lib/start-test.js` is run after building the project. This scripts generate the output text files under `temp/etc`. In local builds, those files are copied to `etc` folder. During a CI build, the files under these two folders are compared and the CI build fails if they are different. This ensures that files under `etc` folder must be up to date in the PR, and people who review the PR must approve any changes.
# How to fix the build errors
Run `rush build -t sparo-completion-test` to regenerate files under `etc` folder and commit them into Git.

View file

@ -0,0 +1,24 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/heft/v0/heft.schema.json",
"extends": "@rushstack/heft-node-rig/profiles/default/config/heft.json",
"phasesByName": {
"build": {
"tasksByName": {
"post-compile": {
"taskDependencies": ["typescript"],
"taskPlugin": {
"pluginName": "run-script-plugin",
"pluginPackage": "@rushstack/heft",
"options": {
"scriptPath": "lib/start-test.js"
}
}
}
}
}
}
}

View file

@ -0,0 +1,5 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/rig-package/rig.schema.json",
"rigPackageName": "@rushstack/heft-node-rig"
}

View file

@ -0,0 +1,3 @@
Running "sparo --get-yargs-completions sparo add __fixture__/":
__fixture__/dir-a/
__fixture__/file.txt

View file

@ -0,0 +1,2 @@
Running "sparo --get-yargs-completions sparo add __fixture__/dir-a/file":
__fixture__/dir-a/file-under-a.txt

View file

@ -0,0 +1,2 @@
Running "sparo --get-yargs-completions sparo add __fixture__":
__fixture__/

View file

@ -0,0 +1 @@
Running "sparo --get-yargs-completions sparo auto-config":

View file

@ -0,0 +1,2 @@
Running "sparo --get-yargs-completions sparo auto-config --":
--overwrite

View file

@ -0,0 +1,4 @@
Running "sparo --get-yargs-completions sparo checkout --add-profile":
my-team
sparo-development
sparo-website

View file

@ -0,0 +1,3 @@
Running "sparo --get-yargs-completions sparo checkout --add-profile spa":
sparo-development
sparo-website

View file

@ -0,0 +1 @@
Running "sparo --get-yargs-completions sparo checkout":

View file

@ -0,0 +1,2 @@
Running "sparo --get-yargs-completions sparo checkout --from web":
website

View file

@ -0,0 +1,6 @@
Running "sparo --get-yargs-completions sparo checkout --":
--no-profile
--profile
--add-profile
--to
--from

View file

@ -0,0 +1,3 @@
Running "sparo --get-yargs-completions sparo checkout --no-profile --":
--to
--from

View file

@ -0,0 +1,2 @@
Running "sparo --get-yargs-completions sparo checkout --pro":
--profile

View file

@ -0,0 +1,4 @@
Running "sparo --get-yargs-completions sparo checkout --profile":
my-team
sparo-development
sparo-website

View file

@ -0,0 +1,3 @@
Running "sparo --get-yargs-completions sparo checkout --profile spa":
sparo-development
sparo-website

View file

@ -0,0 +1,3 @@
Running "sparo --get-yargs-completions sparo checkout --add-profile sparo-website --add-profile":
my-team
sparo-development

View file

@ -0,0 +1,3 @@
Running "sparo --get-yargs-completions sparo checkout --profile sparo-website --profile":
my-team
sparo-development

View file

@ -0,0 +1,2 @@
Running "sparo --get-yargs-completions sparo checkout --to web":
website

View file

@ -0,0 +1 @@
Running "sparo --get-yargs-completions sparo clone":

View file

@ -0,0 +1,5 @@
Running "sparo --get-yargs-completions sparo clone --":
--profile
--branch
--full
--skip-git-config

View file

@ -0,0 +1,2 @@
Running "sparo --get-yargs-completions sparo clone --pro":
--profile

View file

@ -0,0 +1,2 @@
Running "sparo --get-yargs-completions sparo clone --profile":
--profile

View file

@ -0,0 +1,2 @@
Running "sparo --get-yargs-completions sparo fetch --al":
--all

View file

@ -0,0 +1,2 @@
Running "sparo --get-yargs-completions sparo fetch":
origin

View file

@ -0,0 +1,3 @@
Running "sparo --get-yargs-completions sparo fetch --":
--all
--tags

View file

@ -0,0 +1,2 @@
Running "sparo --get-yargs-completions sparo fetch --all --":
--tags

View file

@ -0,0 +1,2 @@
Running "sparo --get-yargs-completions sparo fetch --tags --":
--all

View file

@ -0,0 +1,2 @@
Running "sparo --get-yargs-completions sparo fetch origin HEA":
HEAD

View file

@ -0,0 +1 @@
Running "sparo --get-yargs-completions sparo init-profile":

View file

@ -0,0 +1,2 @@
Running "sparo --get-yargs-completions sparo init-profile --":
--profile

View file

@ -0,0 +1,2 @@
Running "sparo --get-yargs-completions sparo init-profile --pro":
--profile

View file

@ -0,0 +1 @@
Running "sparo --get-yargs-completions sparo list-profiles":

View file

@ -0,0 +1,2 @@
Running "sparo --get-yargs-completions sparo list-profiles --":
--project

View file

@ -0,0 +1,2 @@
Running "sparo --get-yargs-completions sparo list-profiles --pro":
--project

View file

@ -0,0 +1,2 @@
Running "sparo --get-yargs-completions sparo list-profiles --project web":
website

View file

@ -0,0 +1,2 @@
Running "sparo --get-yargs-completions sparo pull":
origin

View file

@ -0,0 +1,3 @@
Running "sparo --get-yargs-completions sparo pull --":
--profile
--no-profile

View file

@ -0,0 +1 @@
Running "sparo --get-yargs-completions sparo pull --no-profile --":

View file

@ -0,0 +1,2 @@
Running "sparo --get-yargs-completions sparo pull --pro":
--profile

View file

@ -0,0 +1,4 @@
Running "sparo --get-yargs-completions sparo pull --profile":
my-team
sparo-development
sparo-website

View file

@ -0,0 +1,3 @@
Running "sparo --get-yargs-completions sparo pull --profile spa":
sparo-development
sparo-website

View file

@ -0,0 +1,3 @@
Running "sparo --get-yargs-completions sparo pull --profile sparo-website --profile":
my-team
sparo-development

View file

@ -0,0 +1,5 @@
Running "sparo --get-yargs-completions sparo rebase --":
--continue
--skip
--abort
--interactive

View file

@ -0,0 +1,4 @@
Running "sparo --get-yargs-completions sparo rebase --abort --":
--continue
--skip
--interactive

View file

@ -0,0 +1,4 @@
Running "sparo --get-yargs-completions sparo rebase --continue --":
--skip
--abort
--interactive

View file

@ -0,0 +1,4 @@
Running "sparo --get-yargs-completions sparo rebase -i --":
--continue
--skip
--abort

View file

@ -0,0 +1,4 @@
Running "sparo --get-yargs-completions sparo rebase --interactive --":
--continue
--skip
--abort

View file

@ -0,0 +1,4 @@
Running "sparo --get-yargs-completions sparo rebase --skip --":
--continue
--abort
--interactive

View file

@ -0,0 +1,2 @@
Running "sparo --get-yargs-completions sparo rebase -":
-i

View file

@ -0,0 +1 @@
Running "sparo --get-yargs-completions sparo rebase -i -":

View file

@ -0,0 +1 @@
Running "sparo --get-yargs-completions sparo rebase --interactive -":

View file

@ -0,0 +1,23 @@
Running "sparo --get-yargs-completions sparo":
auto-config:Automatic setup optimized git config
list-profiles:List all available profiles or query profiles that contain the specified project name
init-profile:Initialize a new profile.
clone:Clone a repository into a new directory
checkout:Updates files in the working tree to match the version in the index or the specified tree. If no pathspec was given, git checkout will also update HEAD to set the specified branch as the current branch.
fetch:fetch remote branch to local
pull:Incorporates changes from a remote repository into the current branch.
git-clone:original git clone command
git-checkout:original git checkout command
git-fetch:original git fetch command
git-pull:original git pull command
add:add file contents to the index
branch:list, create, or delete branches
commit:record changes to the repository
diff:show changes between commits, commit and working tree, etc
log:show commit logs
merge:join two or more development histories together
push:update remote refs along with associated objects
rebase:forward-port local commits to the updated upstream head
reset:reset current HEAD to the specified state
restore:restore working tree files
status:show the working tree status

View file

@ -0,0 +1,24 @@
{
"name": "sparo-completion-test",
"description": "Building this project tests Sparo command-line outputs",
"version": "1.0.0",
"private": true,
"scripts": {
"_phase:build": "heft run --only build -- --clean",
"build": "heft build --clean"
},
"dependencies": {
"@rushstack/node-core-library": "~3.64.2",
"build-test-utilities": "workspace:*"
},
"devDependencies": {
"@rushstack/heft": "0.64.3",
"@rushstack/heft-node-rig": "2.4.5",
"@types/heft-jest": "1.0.6",
"@types/node": "20.11.16",
"eslint": "8.56.0",
"typescript": "~5.3.3"
},
"keywords": [],
"license": "MIT"
}

View file

@ -0,0 +1,311 @@
import {
ICommandDefinition,
executeCommandsAndCollectOutputs,
updateOrCompareOutputs
} from 'build-test-utilities';
import type { IRunScriptOptions } from '@rushstack/heft';
/**
* This build test is highly inspired by the build test for api-extractor in rushstack.
*/
export async function runAsync(runScriptOptions: IRunScriptOptions): Promise<void> {
const {
heftTaskSession: {
logger,
parameters: { production }
},
heftConfiguration: { buildFolderPath }
} = runScriptOptions;
const prefixArgs: string[] = ['--get-yargs-completions', 'sparo'];
const commandDefinitions: ICommandDefinition[] = [
{
kind: 'sparo-command',
name: 'sparo-top-level-completion',
args: prefixArgs.concat([])
},
// auto-config
{
kind: 'sparo-command',
name: 'auto-config-completion',
args: prefixArgs.concat(['auto-config'])
},
{
kind: 'sparo-command',
name: 'auto-config-long-parameters-completion',
args: prefixArgs.concat(['auto-config', '--'])
},
// list-profiles
{
kind: 'sparo-command',
name: 'list-profiles-completion',
args: prefixArgs.concat(['list-profiles'])
},
{
kind: 'sparo-command',
name: 'list-profiles-long-parameters-completion',
args: prefixArgs.concat(['list-profiles', '--'])
},
{
kind: 'sparo-command',
name: 'list-profiles-pro-completion',
args: prefixArgs.concat(['list-profiles', '--pro'])
},
{
kind: 'sparo-command',
name: 'list-profiles-project-web-completion',
args: prefixArgs.concat(['list-profiles', '--project', 'web'])
},
// init-profile
{
kind: 'sparo-command',
name: 'init-profile-completion',
args: prefixArgs.concat(['init-profile'])
},
{
kind: 'sparo-command',
name: 'init-profile-long-parameters-completion',
args: prefixArgs.concat(['init-profile', '--'])
},
{
kind: 'sparo-command',
name: 'init-profile-pro-completion',
args: prefixArgs.concat(['init-profile', '--pro'])
},
// clone
{
kind: 'sparo-command',
name: 'clone-completion',
args: prefixArgs.concat(['clone'])
},
{
kind: 'sparo-command',
name: 'clone-long-parameters-completion',
args: prefixArgs.concat(['clone', '--'])
},
{
kind: 'sparo-command',
name: 'clone-long-parameters-completion',
args: prefixArgs.concat(['clone', '--'])
},
{
kind: 'sparo-command',
name: 'clone-pro-completion',
args: prefixArgs.concat(['clone', '--pro'])
},
{
kind: 'sparo-command',
name: 'clone-profile-completion',
args: prefixArgs.concat(['clone', '--profile'])
},
// checkout
{
kind: 'sparo-command',
name: 'checkout-completion',
args: prefixArgs.concat(['checkout'])
},
{
kind: 'sparo-command',
name: 'checkout-long-parameters-completion',
args: prefixArgs.concat(['checkout', '--'])
},
{
kind: 'sparo-command',
name: 'checkout-pro-completion',
args: prefixArgs.concat(['checkout', '--pro'])
},
{
kind: 'sparo-command',
name: 'checkout-profile-completion',
args: prefixArgs.concat(['checkout', '--profile'])
},
{
kind: 'sparo-command',
name: 'checkout-profile-spa-completion',
args: prefixArgs.concat(['checkout', '--profile', 'spa'])
},
{
kind: 'sparo-command',
name: 'checkout-second-profile-completion',
args: prefixArgs.concat(['checkout', '--profile', 'sparo-website', '--profile'])
},
{
kind: 'sparo-command',
name: 'checkout-add-profile-completion',
args: prefixArgs.concat(['checkout', '--add-profile'])
},
{
kind: 'sparo-command',
name: 'checkout-add-profile-spa-completion',
args: prefixArgs.concat(['checkout', '--add-profile', 'spa'])
},
{
kind: 'sparo-command',
name: 'checkout-second-add-profile-completion',
args: prefixArgs.concat(['checkout', '--add-profile', 'sparo-website', '--add-profile'])
},
{
kind: 'sparo-command',
name: 'checkout-no-profile-completion',
args: prefixArgs.concat(['checkout', '--no-profile', '--'])
},
{
kind: 'sparo-command',
name: 'checkout-to-web-completion',
args: prefixArgs.concat(['checkout', '--to', 'web'])
},
{
kind: 'sparo-command',
name: 'checkout-from-web-completion',
args: prefixArgs.concat(['checkout', '--from', 'web'])
},
// fetch
{
kind: 'sparo-command',
name: 'fetch-completion',
args: prefixArgs.concat(['fetch'])
},
{
kind: 'sparo-command',
name: 'fetch-long-parameters-completion',
args: prefixArgs.concat(['fetch', '--'])
},
{
kind: 'sparo-command',
name: 'fetch-long-parameters-with-all-completion',
args: prefixArgs.concat(['fetch', '--all', '--'])
},
{
kind: 'sparo-command',
name: 'fetch-long-parameters-with-tags-completion',
args: prefixArgs.concat(['fetch', '--tags', '--'])
},
{
kind: 'sparo-command',
name: 'fetch-al-completion',
args: prefixArgs.concat(['fetch', '--al'])
},
{
kind: 'sparo-command',
name: 'fetch-origin-HEA-completion',
args: prefixArgs.concat(['fetch', 'origin', 'HEA'])
},
// pull
{
kind: 'sparo-command',
name: 'pull-completion',
args: prefixArgs.concat(['pull'])
},
{
kind: 'sparo-command',
name: 'pull-long-parameters-completion',
args: prefixArgs.concat(['pull', '--'])
},
{
kind: 'sparo-command',
name: 'pull-pro-completion',
args: prefixArgs.concat(['pull', '--pro'])
},
{
kind: 'sparo-command',
name: 'pull-profile-completion',
args: prefixArgs.concat(['pull', '--profile'])
},
{
kind: 'sparo-command',
name: 'pull-profile-spa-completion',
args: prefixArgs.concat(['pull', '--profile', 'spa'])
},
{
kind: 'sparo-command',
name: 'pull-second-profile-completion',
args: prefixArgs.concat(['pull', '--profile', 'sparo-website', '--profile'])
},
{
kind: 'sparo-command',
name: 'pull-no-profile-completion',
args: prefixArgs.concat(['pull', '--no-profile', '--'])
},
// add
{
kind: 'sparo-command',
name: 'add-partial-completion',
args: prefixArgs.concat(['add', '__fixture__'])
},
{
kind: 'sparo-command',
name: 'add-folder-completion',
args: prefixArgs.concat(['add', '__fixture__/'])
},
{
kind: 'sparo-command',
name: 'add-folder-partial-completion',
args: prefixArgs.concat(['add', '__fixture__/dir-a/file'])
},
// branch
// commit
// diff
// log
// merge
// rebase
{
kind: 'sparo-command',
name: 'rebase-short-parameters-completion',
args: prefixArgs.concat(['rebase', '-'])
},
{
kind: 'sparo-command',
name: 'rebase-short-with-i-completion',
args: prefixArgs.concat(['rebase', '-i', '-'])
},
{
kind: 'sparo-command',
name: 'rebase-short-with-interactive-completion',
args: prefixArgs.concat(['rebase', '--interactive', '-'])
},
{
kind: 'sparo-command',
name: 'rebase-long-parameters-completion',
args: prefixArgs.concat(['rebase', '--'])
},
{
kind: 'sparo-command',
name: 'rebase-long-with-continue-completion',
args: prefixArgs.concat(['rebase', '--continue', '--'])
},
{
kind: 'sparo-command',
name: 'rebase-long-with-skip-completion',
args: prefixArgs.concat(['rebase', '--skip', '--'])
},
{
kind: 'sparo-command',
name: 'rebase-long-with-abort-completion',
args: prefixArgs.concat(['rebase', '--abort', '--'])
},
{
kind: 'sparo-command',
name: 'rebase-long-with-interactive-completion',
args: prefixArgs.concat(['rebase', '--interactive', '--'])
},
{
kind: 'sparo-command',
name: 'rebase-long-with-i-completion',
args: prefixArgs.concat(['rebase', '-i', '--'])
}
// restore
// status
];
await executeCommandsAndCollectOutputs({
buildFolderPath,
commandDefinitions
});
await updateOrCompareOutputs({
buildFolderPath,
logger,
production
});
}

View file

@ -0,0 +1,8 @@
{
"$schema": "http://json.schemastore.org/tsconfig",
"extends": "./node_modules/@rushstack/heft-node-rig/profiles/default/tsconfig-base.json",
"compilerOptions": {
"types": ["node", "heft-jest"]
}
}

View file

@ -111,6 +111,7 @@ export async function executeCommandsAndCollectOutputs({
outputPath, outputPath,
`Running "sparo ${args.join(' ')}":\n${processSparoOutput( `Running "sparo ${args.join(' ')}":\n${processSparoOutput(
stdout, stdout,
// process.cwd() -> project folder
currentWorkingDirectory || process.cwd() currentWorkingDirectory || process.cwd()
)}` )}`
); );

View file

@ -13,5 +13,6 @@ words:
- rushstack - rushstack
- Sparo - Sparo
- tiktok - tiktok
- yargs
ignoreWords: [] ignoreWords: []
import: [] import: []

View file

@ -405,6 +405,10 @@
// } // }
// Build tests // Build tests
{
"packageName": "sparo-completion-test",
"projectFolder": "build-tests/sparo-completion-test"
},
{ {
"packageName": "sparo-output-test", "packageName": "sparo-output-test",
"projectFolder": "build-tests/sparo-output-test" "projectFolder": "build-tests/sparo-output-test"