Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Test

on:
pull_request:
types: [opened, synchronize]
paths:
- '**/*.[tj]s'
- '**/*.?[tj]s'
- 'tsconfig.json'
- 'package.json'
- 'package-lock.json'
- '.nvmrc'
- '.github/workflows/test.yml'

jobs:
test:
runs-on: blacksmith-2vcpu-ubuntu-2404
steps:
- name: Checkout
# 6.0.3
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10

# v6.1.0
- name: Setup Node
uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f
with:
node-version-file: .nvmrc
cache: npm
cache-dependency-path: package-lock.json

- name: Install npm packages
run: npm ci

- name: Run unit tests
run: npm test

- name: Tell people how to run the failing check
if: failure()
run: echo "::error::The test check failed! To run it locally, run \`npm ci && npm test\` from the GitHub-Actions repo root."
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"scripts": {
"fmt": "oxfmt --write .",
"typecheck": "tsgo --noEmit -p tsconfig.json",
"verify-peer-review": "tsx scripts/verifyPeerReview.ts"
"verify-peer-review": "tsx scripts/verifyPeerReview.ts",
"test": "tsx --test tests/*.test.ts"
},
"dependencies": {
"expensify-common": "2.0.189"
Expand Down
33 changes: 33 additions & 0 deletions tests/verifyPeerReviewCli.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import assert from 'node:assert/strict';
import {afterEach, beforeEach, describe, it} from 'node:test';

import VerifyPeerReview from '../scripts/verifyPeerReview';

const ORIGINAL_ARGV = process.argv;

describe('main CLI parsing', () => {
let originalExit: typeof process.exit;

beforeEach(() => {
process.argv = ['tsx', 'scripts/verifyPeerReview.ts'];
originalExit = process.exit.bind(process);
process.exit = (code?: string | number | null) => {
throw new Error(`exit ${code ?? 0}`);
};
});

afterEach(() => {
process.argv = ORIGINAL_ARGV;
process.exit = originalExit;
});

it('parses required pull request CLI arguments', async () => {
process.argv.push('--owner', 'Expensify', '--repo', 'Auth', '--pull-request-number', '21136', '--base-ref', 'main');

await assert.doesNotReject(() => VerifyPeerReview.main());
});

it('fails when required arguments are missing', async () => {
await assert.rejects(() => VerifyPeerReview.main(), /exit 1/);
});
});
Loading