Skip to content

Commit

Permalink
remove interactive tests and add non-interactive flag
Browse files Browse the repository at this point in the history
  • Loading branch information
km1chno committed Aug 29, 2024
1 parent 2b85412 commit d8fbb54
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 390 deletions.
13 changes: 0 additions & 13 deletions .github/workflows/jest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,6 @@ jobs:
- name: 🏗 Setup repo
uses: actions/checkout@v4

- name: 📡 Fetch test projects
run: |
git clone https://github.com/km1chno-swm/rn-setup-ci-yarn-flat.git test-projects/rn-setup-ci-yarn-flat
git clone https://github.com/km1chno-swm/rn-setup-ci-npm-flat.git test-projects/rn-setup-ci-npm-flat
git clone https://github.com/km1chno-swm/rn-setup-ci-yarn-monorepo.git test-projects/rn-setup-ci-yarn-monorepo
git clone https://github.com/km1chno-swm/rn-setup-ci-npm-monorepo.git test-projects/rn-setup-ci-npm-monorepo
git clone https://github.com/km1chno-swm/rn-setup-ci-create-expo-stack.git test-projects/rn-setup-ci-create-expo-stack
- name: 🤖 Install robotjs dependencies
run: |
sudo apt update
sudo apt-get install libxtst-dev libpng++-dev
- name: 📦 Install dependencies
run: yarn

Expand Down
5 changes: 0 additions & 5 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ jobs:
- name: 🏗 Setup repo
uses: actions/checkout@v4

- name: 🤖 Install robotjs dependencies
run: |
sudo apt update
sudo apt-get install libxtst-dev libpng++-dev
- name: 📦 Install dependencies
run: yarn

Expand Down
5 changes: 0 additions & 5 deletions .github/workflows/prettier.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ jobs:
- name: 🏗 Setup repo
uses: actions/checkout@v4

- name: 🤖 Install robotjs dependencies
run: |
sudo apt update
sudo apt-get install libxtst-dev libpng++-dev
- name: 📦 Install dependencies
run: yarn

Expand Down
5 changes: 0 additions & 5 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ jobs:
cache: 'yarn'
registry-url: 'https://registry.npmjs.org'

- name: 🤖 Install robotjs dependencies
run: |
sudo apt update
sudo apt-get install libxtst-dev libpng++-dev
- name: 📦 Install dependencies
run: yarn

Expand Down
5 changes: 0 additions & 5 deletions .github/workflows/typescript.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ jobs:
- name: 🏗 Setup repo
uses: actions/checkout@v4

- name: 🤖 Install robotjs dependencies
run: |
sudo apt update
sudo apt-get install libxtst-dev libpng++-dev
- name: 📦 Install dependencies
run: yarn

Expand Down
14 changes: 8 additions & 6 deletions __tests__/recipes/detox.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
cli,
getPackageJsonWithoutVersions,
installDependencies,
NON_INTERACTIVE_FLAG,
PRESET_FLAG,
removeTestProject,
setupTestProject,
Expand Down Expand Up @@ -71,12 +72,13 @@ describe('detox recipe', () => {
const { packageManager, repoRoot, appRoot, workflowNamePrefix } =
TEST_PROJECTS[projectName]

const output = await cli([PRESET_FLAG, `--${FLAG}`], {
cwd: appRoot,
input: {
'Press enter to continue...': ['enter'],
},
})
const output = await cli(
[PRESET_FLAG, NON_INTERACTIVE_FLAG, `--${FLAG}`],
{
cwd: appRoot,
verbose: true,
}
)

for (const message of [
'You have chosen to setup Detox for a non-expo project.',
Expand Down
21 changes: 2 additions & 19 deletions __tests__/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { execSync, spawn } from 'child_process'
import { join } from 'path'
import { existsSync } from 'fs'
const robot = require('robotjs')

const PATH_TO_BINARY = join(__dirname, '..', 'bin', 'react-native-ci-cli')

Expand All @@ -11,6 +10,7 @@ const TEST_PROJECT_NAME = 'test-project'
export const PATH_TO_TEST_PROJECTS = join(__dirname, '..', TEST_PROJECTS_FOLDER)
const PATH_TO_TEST_PROJECT = join(__dirname, '..', TEST_PROJECT_NAME)

export const NON_INTERACTIVE_FLAG = '--non-interactive'
export const PRESET_FLAG = '--preset'

const INSTALL_DEPENDENCIES_COMMAND = {
Expand Down Expand Up @@ -65,11 +65,7 @@ export const TEST_PROJECTS = {
// If verbose is set to true, the child stdout will be printed to parent stdout.
export const cli = async (
flags: string[] = [],
{
verbose = false,
cwd = '.',
input,
}: { verbose?: boolean; cwd?: string; input?: Record<string, string[]> } = {
{ verbose = false, cwd = '.' }: { verbose?: boolean; cwd?: string } = {
verbose: false,
cwd: '.',
}
Expand All @@ -87,19 +83,6 @@ export const cli = async (
if (verbose) {
process.stdout.write(data)
}

if (input) {
const dataStr: string = data.toString()

const actionKey = Object.keys(input)
.map((key): [string, number] => [key, dataStr.lastIndexOf(key)])
.sort((a, b) => b[1] - a[1])[0]

if (actionKey[1] !== -1) {
input[actionKey[0]].forEach((key) => robot.keyTap(key))
}
}

output += data.toString()
})

Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"build": "yarn clean-build && yarn compile && yarn copy-templates",
"prepublishOnly": "yarn build",
"format": "eslint \"**/*.{js,jsx,ts,tsx}\" --fix && prettier \"**/*.{js,jsx,ts,tsx,json}\" --write",
"test": "jest --verbose",
"test": "jest",
"watch": "jest --watch",
"build:alias": "sed -i 's/\"name\": \"react-native-ci-cli\"/\"name\": \"setup-ci\"/g' package.json && yarn build",
"snapupdate": "jest --updateSnapshot",
Expand Down Expand Up @@ -58,7 +58,6 @@
"jest": "^26.6.3",
"prettier": "^2.2.1",
"pretty-quick": "^3.1.0",
"robotjs": "^0.6.0",
"ts-jest": "^26.5.3",
"ts-node": "^10.9.1",
"typescript": "^5.5.3"
Expand Down
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const S_BAR_END = '└'
export const S_RADIO_ACTIVE = '●'
export const S_RADIO_INACTIVE = '○'

export const NON_INTERACTIVE_FLAG = 'non-interactive'
export const HELP_FLAG = 'help'
export const PRESET_FLAG = 'preset'

Expand Down
5 changes: 5 additions & 0 deletions src/extensions/interactive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ module.exports = (toolbox: CycliToolbox) => {
dim(S_BAR)
)}\n`

if (toolbox.options.isNonInteractive()) {
toolbox.interactive.info(titleSubmitted)
return
}

const confirmed = await new SelectPrompt({
options: [
{
Expand Down
7 changes: 6 additions & 1 deletion src/extensions/options.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PRESET_FLAG } from '../constants'
import { NON_INTERACTIVE_FLAG, PRESET_FLAG } from '../constants'
import { CycliToolbox } from '../types'

module.exports = (toolbox: CycliToolbox) => {
Expand All @@ -8,15 +8,20 @@ module.exports = (toolbox: CycliToolbox) => {
Boolean(toolbox.parameters.options[PRESET_FLAG]) &&
Boolean(toolbox.parameters.options[recipeFlag])

const isNonInteractive = () =>
Boolean(toolbox.parameters.options[NON_INTERACTIVE_FLAG])

toolbox.options = {
isPreset,
isRecipeSelected,
isNonInteractive,
}
}

export interface OptionsExtension {
options: {
isPreset: () => boolean
isRecipeSelected: (recipeFlag: string) => boolean
isNonInteractive: () => boolean
}
}
Loading

0 comments on commit d8fbb54

Please sign in to comment.