Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document, test, and refactor our modules #1

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Document, test, and refactor our modules #1

wants to merge 2 commits into from

Conversation

luzmcosta
Copy link
Owner

As part of testing the ops module's functionality, the following changes are proposed:

  • Introduce and configure Jest, using src as the rootDir property. Alongside the introduction of the usual jest.config.mjs file, I've added a jest.env.js file and set it as the setupFiles property of the jest.config.mjs. The setup file is needed to configure the process.env.NODE_ENV env var for tests that reference or update its value. Similarly, I've added the jest.utils.js file to hold our various setup and teardown functions in one place.
  • Add a test command to the package.json scripts. The command runs Jest with the --experimental-vm-modules flag they currently recommend using to support ES modules.
  • Introduce and configure ESLint. I've started with some basic rules we can iterate upon from here.
  • Introduce an OPS_EMAIL environment variable and update .env.example accordingly. The env var allows a dev user to set the email address the script should use when logging in to Firebase and other services.
  • Refactor modules and functions into smaller blocks, each with a single responsibility. In so doing, new modules were introduced, including env, exec, firebase, and validate.
  • Facilitate testing and future iterations by writing functions that support dependency injection. This is a pattern that should be upheld as this repo matures.
  • Unit test over 80% of statements, functions, lines, and the branch. This goal was attained and surpassed. Details have been included below.

Test Results

Below are the tests results these changes produce.

PASS src/ops.test.js
PASS src/firebase.test.js
PASS src/logger.test.js
PASS src/validate.test.js
PASS src/gcloud.test.js
PASS src/exec.test.js
-------------|---------|----------|---------|---------|------------------------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
-------------|---------|----------|---------|---------|------------------------------------
All files | 95.68 | 96.47 | 86.56 | 95.68 |
env.js | 100 | 50 | 100 | 100 | 11
exec.js | 98.01 | 91.66 | 66.66 | 98.01 | 59-60
firebase.js | 96.43 | 100 | 80.95 | 96.43 | 453-470
gcloud.js | 100 | 100 | 100 | 100 |
logger.js | 100 | 100 | 100 | 100 |
ops.js | 90.64 | 90.9 | 77.77 | 90.64 | ...331-338,343-352,365,378,389,396
validate.js | 100 | 100 | 100 | 100 |
-------------|---------|----------|---------|---------|------------------------------------

Test Suites: 6 passed, 6 total
Tests: 113 passed, 113 total
Snapshots: 0 total
Time: 7.761 s, estimated 10 s
Ran all test suites.

As part of testing the ops module's functionality, the following changes are proposed:

- Introduce and configure Jest, using `src` as the `rootDir` property. Alongside the introduction of the usual `jest.config.mjs` file, I've added a `jest.env.js` file and set it as the `setupFiles` property of the `jest.config.mjs`. The setup file is needed to configure the `process.env.NODE_ENV` env var for tests that reference or update its value. Similarly, I've added the `jest.utils.js` file to hold our various setup and teardown functions in one place.
- Add a `test` command to the package.json scripts. The command runs Jest with the `--experimental-vm-modules` flag they currently recommend using to support ES modules.
- Introduce and configure ESLint. I've started with some basic rules we can iterate upon from here.
- Introduce an `OPS_EMAIL` environment variable and update `.env.example` accordingly. The env var allows a dev user to set the email address the script should use when logging in to Firebase and other services.
- Refactor modules and functions into smaller blocks, each with a single responsibility. In so doing, new modules were introduced, including `env`, `exec`, `firebase`, and `validate`.
- Facilitate testing and future iterations by writing functions that support dependency injection. This is a pattern that should be upheld as this repo matures.
- Unit test over 80% of statements, functions, lines, and the branch. This goal was attained and surpassed. Details have been included below.

## Test Results

Below are the tests results these changes produce.

 PASS  src/ops.test.js
 PASS  src/firebase.test.js
 PASS  src/logger.test.js
 PASS  src/validate.test.js
 PASS  src/gcloud.test.js
 PASS  src/exec.test.js
-------------|---------|----------|---------|---------|------------------------------------
File         | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
-------------|---------|----------|---------|---------|------------------------------------
All files    |   95.68 |    96.47 |   86.56 |   95.68 |
 env.js      |     100 |       50 |     100 |     100 | 11
 exec.js     |   98.01 |    91.66 |   66.66 |   98.01 | 59-60
 firebase.js |   96.43 |      100 |   80.95 |   96.43 | 453-470
 gcloud.js   |     100 |      100 |     100 |     100 |
 logger.js   |     100 |      100 |     100 |     100 |
 ops.js      |   90.64 |     90.9 |   77.77 |   90.64 | ...331-338,343-352,365,378,389,396
 validate.js |     100 |      100 |     100 |     100 |
-------------|---------|----------|---------|---------|------------------------------------

Test Suites: 6 passed, 6 total
Tests:       113 passed, 113 total
Snapshots:   0 total
Time:        7.761 s, estimated 10 s
Ran all test suites.
@luzmcosta luzmcosta self-assigned this Mar 14, 2024
These changes remove the `npm` and `install` packages from our list of `devDependencies` in the package.json file. These packages made their way into the `devDependencies` list via an errant command execution.

This is related to some recent terminal incidents I've experienced, where my terminal froze and crashed while I was typing. It seems I accidentally executed `npm install npm install` during my struggle with the terminal. Because the command is technically well-formed, rather than err, it installed the `npm` and `install` packages.

Thankfully, I caught this issue as part of the pull request review. As such, this incident demonstrates the importance of reviewing dependencies regularly, especially before a pull request is merged into the `main` branch.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant