You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CONTRIBUTING.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,7 @@ Install dependencies using `npm install`
15
15
16
16
Build the project using `npm run build` or `npm run build:watch` to automatically rebuild on file changes.
17
17
18
-
Run integration tests using `npm run test:integration`. Make sure to read the [integration test instructions](./integrationTests/apiTests/README.md) for setup.
18
+
Run integration tests using `npm run test:integration`. Make sure to read the [integration test instructions](./integrationTests/README.md) for setup requirements (particularly the loopback address configuration).
19
19
20
20
Run unit tests using `npm run test:unit <unit-test-file>` or `npm run test:unit:all`, but make sure to build the project first since unit tests depend on the built source files.
Copy file name to clipboardExpand all lines: integrationTests/README.md
+35-54Lines changed: 35 additions & 54 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,6 +3,7 @@
3
3
We prioritize performance at Harper, and that extends to core developer experience and productivity. Harper is a significantly complex application involving multiple processes, threads, file I/O, database operations, network calls, and so much more. Integration tests differ from unit test as they **must run against the built distribution of Harper as if it was a user or another system** (instead of importing source/built code directly). As a result, integration tests will be as resource intensive as the Harper system is.
4
4
5
5
In order to keep things as fast as possible, integration test **files** must be:
6
+
6
7
-**Independent**: Test files do not depend on execution order or state from other test files
7
8
-**Hermetic**: Test files are self-contained with no external side-effects
8
9
-**Deterministic**: The same input always produces the same output, no matter how many times its executed
@@ -13,9 +14,9 @@ If we follow these guidelines strictly, we can execute integration tests concurr
13
14
14
15
This directory contains integration tests migrated from our old repository. These test are incredibly important and are one of the most important ways we've verified the Harper application continues to work throughout the open source transfer. Unfortunately, these tests are very interdependent and cannot be run separately from each other. The setup in early test files is necessary for most other test files to work, and some tests (spread across multiple files) interact with the same resources and data and in some circumstances must be executed in a certain order. This interdependence has made it very difficult, if not impossible, for developers to isolated failing tests during development.
15
16
16
-
These tests should be generally excluded from our new integration testing guidelines while they are actively ported to new implementations. They are automatically ignored by the `test:integration` script, and can be executed using the `test:integration:apiTests` npm script instead.
17
+
These tests should be generally excluded from our new integration testing guidelines while they are actively ported to new implementations. They are automatically ignored by the `test:integration` script, and can be executed using the `test:integration:api-tests` npm script instead.
17
18
18
-
Complete documentation for configuring and executing these tests is available [here](./apiTests/README.md).
19
+
These tests have their own unique configuration and setup requirements that differ from the newer integration test guidelines.
19
20
20
21
## Running Tests
21
22
@@ -24,11 +25,13 @@ Complete documentation for configuring and executing these tests is available [h
24
25
>
25
26
> Linux Ubuntu systems generally have 127.0.0.1 - 127.255.255.255 enabled by default, but MacOS and Windows does not.
26
27
>
27
-
> Use the included script `integrationTests/setup-loopback.sh` to quickly enable the required set of loopback addresses.
28
+
> Use the included script `integrationTests/utils/scripts/setup-loopback.sh` to quickly enable the required set of loopback addresses.
28
29
>
29
30
> This script does require `sudo` permissions. We recommend reviewing the source before executing.
31
+
>
32
+
> The script respects the `HARPER_INTEGRATION_TEST_LOOPBACK_POOL_COUNT` environment variable (defaults to 32) to configure the number of loopback addresses. The integration test runner will automatically validate that the required loopback addresses are available before running tests and will exit with an error if they are not configured.
30
33
31
-
The Node.js test runner uses process isolation to run test files concurrently _by default_. Meaning, `node --test "integrationTests/*.test.ts"` will run every matched file in its own process. Node.js determines the number of concurrent processes using `os.availableParallelism() - 1`. Since Harper is itself a resource intensive application, this default concurrency causes extreme resource contention and system thrashing as each integration test file is also running at least one more process, the Harper application, plus whatever additional work the Harper application does as part of the tests. Through deep analysis, we have determine a safer default concurrency for our circumstances is slightly more than half of the available parallelism. For more information see [Node.js Test Runner Parallelization Analysis](https://github.com/Ethan-Arrowood/node-test-runner-parallelization-analysis). Thus, using `node --test` to run _all_ integration tests is insufficient. We include a npm script `test:integration` for simplified execution. The `node --test` command can still be used to run an individual test file, or at most a small set of test files, but we recommend using `test:integration` whenever possible.
34
+
The Node.js test runner uses process isolation to run test files concurrently _by default_. Meaning, `node --test "integrationTests/*.test.mts"` will run every matched file in its own process. Node.js determines the number of concurrent processes using `os.availableParallelism() - 1`. Since Harper is itself a resource intensive application, this default concurrency causes extreme resource contention and system thrashing as each integration test file is also running at least one more process, the Harper application, plus whatever additional work the Harper application does as part of the tests. Through deep analysis, we have determine a safer default concurrency for our circumstances is slightly more than half of the available parallelism. For more information see [Node.js Test Runner Parallelization Analysis](https://github.com/Ethan-Arrowood/node-test-runner-parallelization-analysis). Thus, using `node --test` to run _all_ integration tests is insufficient. We include a npm script `test:integration` for simplified execution. The `node --test` command can still be used to run an individual test file, or at most a small set of test files, but we recommend using `test:integration` whenever possible.
32
35
33
36
The `test:integration` script will execute **all integration tests by default** using the safe concurrency settings as described above.
34
37
@@ -46,18 +49,19 @@ For example:
46
49
47
50
```sh
48
51
# Supports exact file paths
49
-
npm run test:integration -- "integrationTests/install.test.ts"
52
+
npm run test:integration -- "integrationTests/deploy/deploy-from-source.test.mts"
50
53
# Or glob patterns
51
-
npm run test:integration -- "integrationTests/applicationLifecycle/*.test.ts"
54
+
npm run test:integration -- "integrationTests/deploy/*.test.mts"
52
55
# Or multiple entries
53
-
npm run test:integration -- "integrationTests/install.test.ts""integrationTests/start.test.ts""integrationTests/stop.test.ts"
56
+
npm run test:integration -- "integrationTests/deploy/deploy-from-source.test.mts""integrationTests/deploy/deploy-from-github.test.mts"
54
57
```
55
58
56
59
### Available options:
57
60
58
61
All CLI arguments can be overridden using the associative `HARPER_INTEGRATION_TEST_*` environment variable where the `*` is replaced by the capitalized CLI argument name. For example, `--concurrency` is replaced by `HARPER_INTEGRATION_TEST_CONCURRENCY`.
59
62
60
63
Configuration precedence order is:
64
+
61
65
1. Environment Variables
62
66
2. CLI Argument
63
67
3. Default Value
@@ -126,7 +130,7 @@ This option can be overridden using the `HARPER_INTEGRATION_TEST_ONLY` environme
126
130
127
131
As mentioned in the introduction, integration test **files** should be **independent**, **hermetic**, and **deterministic**.
128
132
129
-
All files meant to be executed by the test runner should end in `.test.ts`. They can be nested within directories for organization purposes, or be top-level in this `integrationTests` directory. Every test file should begin with a comment block explaining exactly what it is meant to test.
133
+
All files meant to be executed by the test runner should end in `.test.mts` (ES module TypeScript). They can be nested within directories for organization purposes, or be top-level in this `integrationTests` directory. Every test file should begin with a comment block explaining exactly what it is meant to test.
130
134
131
135
Tests must use the Node.js Test Runner API [`node:test`]() for establishing suites (`describe` or `suite`), tests (`it` or `test`), and lifecycle methods (`before`, `beforeEach`, `after`, and `afterEach`).
132
136
@@ -144,45 +148,30 @@ Since these tests interact with a running Harper instance directly, they often w
144
148
- Network Responses
145
149
- File System
146
150
147
-
Reusable assertion patterns will develop over time. The [utilities](#utilities) section documents various helpers for things such as setting up and tearing down Harper instances, assertion patterns, and more. Familiarize yourself with this section as well as existing tests to best understand general testing patterns.
151
+
Reusable assertion patterns will develop over time. Familiarize yourself with existing tests and the [Integration Test Utilities documentation](./utils/README.md) to best understand general testing patterns.
148
152
149
153
### Utilities
150
154
151
-
#### `setupHarper(context): Promise<void>`
152
-
153
-
-**context** - [`SuiteContext`]() | [`TestContext`]() - The context for a set of tests.
154
-
155
-
This method should be used in the [`before()`]() function for a set of tests. It will create a Harper instance and assign relevant information to the `context.harper` object for use throughout the set of tests. **Do not forget** to call `teardownHarper(ctx)` in the `after()` function or you will have phantom Harper processes after the tests complete.
156
-
157
-
For example,
158
-
159
-
```ts
160
-
suite('test suite', (ctx) => {
161
-
before(async () => {
162
-
awaitsetupHarper(ctx);
163
-
});
164
-
165
-
after(async () => {
166
-
awaitteardownHarper(ctx);
167
-
});
155
+
Integration test utilities are located in the [`integrationTests/utils/`](./utils/) directory and provide essential functionality for test setup, teardown, and common operations.
168
156
169
-
test('make a request', async () => {
170
-
// The `ctx.harper` object will have important information about the relative instance
171
-
const response =awaitfetch(ctx.harper.url);
172
-
});
173
-
});
174
-
```
157
+
**Complete utilities documentation is available at [`integrationTests/utils/README.md`](./utils/README.md).**
175
158
176
-
#### `teardownHarper(context): Promise<void>`
159
+
#### Quick Reference
177
160
178
-
-**context** - [`ContextWithHarper`](#contextwithharper) - A suite or test context object with the `harper` property from [`setupHarper()`]()
161
+
The most commonly used utilities are:
179
162
180
-
This method should be used in the [`after()`]() function in conjunction with the [`setupHarper()`]() and [`before()`]() methods. It will shutdown the relative Harper instance and remove it from the filesystem.
163
+
-**`setupHarper(context)`** - Sets up a complete Harper instance for testing. Use in `before()` hooks.
164
+
-**`teardownHarper(context)`** - Tears down a Harper instance and cleans up resources. Use in `after()` hooks.
165
+
-**`ContextWithHarper`** - TypeScript interface for test context with Harper instance details.
166
+
-**`targz(dirPath)`** - Compresses a directory into a base64-encoded tar.gz string for application deployment.
181
167
182
-
For example,
168
+
**Example usage:**
183
169
184
170
```ts
185
-
suite('test suite', (ctx) => {
171
+
import { suite, test, before, after } from'node:test';
// The `ctx.harper` object will have important information about the relative instance
196
-
const response =awaitfetch(ctx.harper.url);
183
+
test('make a request', async () => {
184
+
const response =awaitfetch(ctx.harper.httpURL);
185
+
// ... assertions
197
186
});
198
187
});
199
188
```
200
189
201
-
#### `ContextWithHarper`
202
-
203
-
The interface assigned to a [`SuiteContext`]() or [`TestContext`]() object by [`setupHarper()`]() and necessary for [`teardownHarper()`]().
204
-
205
-
Properties:
206
-
-**url** - [`URL`]() - The URL instance for the Harper instance
207
-
-**admin** - `object`
208
-
-**username** - `string` - The Harper Admin Username
209
-
-**password** - `string` - The Harper Admin Password
210
-
-**rootpath** - `string` - The absolute path to the root of the Harper instance
190
+
**For detailed documentation** including all available utilities, parameters, return types, configuration options, and advanced usage examples, see the [**Integration Test Utilities Documentation**](./utils/README.md).
211
191
212
192
### Test File Template
213
193
@@ -223,10 +203,10 @@ Copy and paste the following content to get started:
223
203
*/
224
204
import { suite, test, before, after } from'node:test';
225
205
import { strictEqual } from'node:assert/strict';
226
-
//If this file is nested don't forget to update the path here
0 commit comments