Skip to content

Commit

Permalink
feat: add basic integration tests (#13)
Browse files Browse the repository at this point in the history
* feat: add basic integration tests

* test robotjs dependencies

* add robotjs dependencies to workflows

* change remote urls of tests projects to http

* add logs to project setup in tests for debug

* try again with ssh, now generating ssh key pair in workflow

* setup github user and email

* use http

* mkdir tests project directory if does not exist

* keep test projects in tmp

* clone test projects before running jest

* downgrade typescript to be compatible with ts-jest

* go back to new version of typescript

* add verbose flag to jest command

* remove interactive tests and add non-interactive flag

* remove the verbose option from detox test

* change help message test to not use snapshots

* run jest tests on macos

* move test projects to this repository

* ignore test projects in eslint config
  • Loading branch information
km1chno authored Sep 13, 2024
1 parent 74b42dd commit d35c96c
Show file tree
Hide file tree
Showing 250 changed files with 109,478 additions and 61 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ module.exports = {
],
'@typescript-eslint/no-var-requires': 'off',
},
ignorePatterns: ['__tests__/test-projects'],
}
17 changes: 17 additions & 0 deletions .github/workflows/jest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Run Jest

on: pull_request

jobs:
jest:
name: Jest
runs-on: macos-latest
steps:
- name: 🏗 Setup repo
uses: actions/checkout@v4

- name: 📦 Install dependencies
run: yarn

- name: 🎭 Run Jest
run: yarn test
11 changes: 7 additions & 4 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
name: Check ESLint
on:
- pull_request

on: pull_request

jobs:
test:
lint:
name: ESLint
runs-on: ubuntu-latest
steps:
- name: 🏗 Setup repo
uses: actions/checkout@v4

- name: 📦 Install dependencies
run: yarn

- name: 🤓 Run ESLint
run: yarn --cwd . lint
run: yarn lint
9 changes: 6 additions & 3 deletions .github/workflows/prettier.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
name: Prettier check
on:
- pull_request

on: pull_request

jobs:
prettier-check:
name: Prettier check
runs-on: ubuntu-latest
steps:
- name: 🏗 Setup repo
uses: actions/checkout@v4

- name: 📦 Install dependencies
run: yarn

- name: ✨ Run Prettier check
run: yarn --cwd . prettier:check
run: yarn prettier:check
20 changes: 13 additions & 7 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,31 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
- name: 🏗 Setup repo
uses: actions/checkout@v4
- name: Setup Node

- name: 🍀 Setup Node
uses: actions/setup-node@v4
with:
node-version: 18
cache: 'yarn'
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies 🔧

- name: 📦 Install dependencies
run: yarn
- name: Build 🏗️

- name: 🛠️ Build
run: yarn build
- name: Publish package on NPM 📦

- name: 🚀 Publish package to NPM repository
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Build for alias 🏗️

- name: 🛠️ Build for alias
run: yarn build:alias
- name: Publish package on NPM for alias 📦

- name: 🚀 Publish package to NPM repository for alias
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
7 changes: 5 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@ jobs:
changelog:
runs-on: ubuntu-latest
steps:
- name: 🏗 Setup repo
- uses: actions/checkout@v4
with:
token: ${{ secrets.PA_TOKEN }}
- name: Conventional Changelog Action

- name: 📘 Conventional Changelog Action
id: changelog
uses: TriPSs/conventional-changelog-action@v3
with:
github-token: ${{ secrets.PA_TOKEN }}
- name: Create release

- name: 🚀 Create release
uses: actions/create-release@v1
if: ${{ steps.changelog.outputs.skipped == 'false' }}
env:
Expand Down
15 changes: 9 additions & 6 deletions .github/workflows/typescript.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
name: Run Typescript
on:
- pull_request
name: Typescript check

on: pull_request

jobs:
test:
name: Typescript
typescript-check:
name: Typescript check
runs-on: ubuntu-latest
steps:
- name: 🏗 Setup repo
uses: actions/checkout@v4

- name: 📦 Install dependencies
run: yarn

- name: 🔨 Run Typescript
run: yarn --cwd . ts:check
run: yarn ts:check
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
dist
build
__tests__/test-projects
31 changes: 0 additions & 31 deletions __tests__/cli-integration.test.ts

This file was deleted.

31 changes: 31 additions & 0 deletions __tests__/cli.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { cli } from './utils'
import { version } from '../package.json'

test('prints version', async () => {
const output = await cli(['--version'])
expect(output).toContain(version)
})

test('prints help', async () => {
const output = await cli(['--help'])

expect(output).toContain(version)

for (const message of [
'Welcome to react-native-ci-cli',
'Quickly setup CI workflows for your React Native app',
'--help',
'--version',
'--skip-git-check',
'--preset',
'Use any combination of the following with --preset flag to specify your own set of workflows to generate',
'--lint',
'--jest',
'--ts',
'--prettier',
'--eas-update',
'--detox',
]) {
expect(output).toContain(message)
}
})
36 changes: 36 additions & 0 deletions __tests__/fail-fast.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { rm } from 'fs/promises'
import { join } from 'path'
import {
cli,
removeTestProject,
setupTestProject,
TEST_PROJECTS,
} from './utils'

describe('fail fast scenarios', () => {
afterEach(removeTestProject)

test('fails when cwd has no package.json', async () => {
const { appRoot } = TEST_PROJECTS['rn-setup-ci-yarn-flat']
setupTestProject('rn-setup-ci-yarn-flat')

await rm(join(appRoot, 'package.json'))

const output = await cli(['--skip-git-check'], { cwd: appRoot })

expect(output).toContain(
'No package.json found in current directory. Are you sure you are in a project directory?'
)
})

test('fails when cwd is monorepo root', async () => {
const { repoRoot } = TEST_PROJECTS['rn-setup-ci-yarn-monorepo']
setupTestProject('rn-setup-ci-yarn-monorepo')

const output = await cli([], { cwd: repoRoot })

expect(output).toContain(
'The current directory is workspace root directory. Please run the script again from selected package root directory.'
)
})
})
Loading

0 comments on commit d35c96c

Please sign in to comment.