@guardian/end-to-end-testing 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -85
- package/dist/ApplicationContainer.d.ts +6 -3
- package/dist/index.js +1 -5
- package/package.json +4 -4
- package/dist/ApplicationContainer.js +0 -17
package/README.md
CHANGED
|
@@ -8,60 +8,22 @@ is a base image for running an application under test in an end-to-end stack:
|
|
|
8
8
|
Ubuntu with build essentials and [mise](https://mise.jdx.dev/) for installing
|
|
9
9
|
the application's toolchain. It contains no application code.
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
11
|
+
On every push to `main`, CI tags the image `sha-<full-commit-id>` using the
|
|
12
|
+
pushed commit. Other runs use `hash-<dockerfile-hash>`, derived
|
|
13
|
+
from `hashFiles('container-images/application.Dockerfile')`. For either tag,
|
|
14
|
+
CI skips publication if GHCR confirms it exists; otherwise it builds and pushes
|
|
15
|
+
for `linux/amd64` and `linux/arm64`. Fork and Dependabot PRs do not publish.
|
|
16
|
+
|
|
17
|
+
The image workflow returns the tag to CI, which passes it to package builds
|
|
18
|
+
through `APPLICATION_IMAGE_TAG`. Vite embeds this value in the library bundle;
|
|
19
|
+
consumers do not need to set it. Local builds without that variable use the
|
|
20
|
+
same single-file calculation: SHA-256 of the Dockerfile's binary SHA-256 digest.
|
|
21
|
+
The Dockerfile hash is not an image
|
|
22
|
+
digest: rebuilding the same Dockerfile can pick up updated base images or tools.
|
|
23
23
|
|
|
24
24
|
Publishing uses `GITHUB_TOKEN` with `packages: write`. Enable Actions and package
|
|
25
|
-
creation for the repository.
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
### Sharing Within the Organisation
|
|
29
|
-
|
|
30
|
-
After the first publish, open the package under the `guardian` organisation
|
|
31
|
-
on GitHub, then open **Package settings**. Under **Manage Actions access**, add
|
|
32
|
-
each consuming repository with the **Read** role. Being in the same organisation
|
|
33
|
-
does not automatically give another repository's `GITHUB_TOKEN` access.
|
|
34
|
-
|
|
35
|
-
In each consuming repository's workflow, grant `packages: read` and log in before
|
|
36
|
-
Docker or Testcontainers pulls the image:
|
|
37
|
-
|
|
38
|
-
```yaml
|
|
39
|
-
permissions:
|
|
40
|
-
contents: read
|
|
41
|
-
packages: read
|
|
42
|
-
|
|
43
|
-
jobs:
|
|
44
|
-
e2e:
|
|
45
|
-
runs-on: ubuntu-latest
|
|
46
|
-
steps:
|
|
47
|
-
- uses: actions/checkout@v4
|
|
48
|
-
- uses: docker/login-action@v3
|
|
49
|
-
with:
|
|
50
|
-
registry: ghcr.io
|
|
51
|
-
username: ${{ github.actor }}
|
|
52
|
-
password: ${{ secrets.GITHUB_TOKEN }}
|
|
53
|
-
- run: docker pull ghcr.io/guardian/end-to-end-testing/application:latest
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
Replace `latest` with a published SHA tag or digest for reproducible tests, then
|
|
57
|
-
run the repository's e2e suite after login. No shared personal access token is
|
|
58
|
-
needed for these Actions workflows.
|
|
59
|
-
|
|
60
|
-
For local development, users need read access to the package and can authenticate
|
|
61
|
-
with `docker login ghcr.io` using a personal access token (classic) with
|
|
62
|
-
`read:packages`, authorised for organisation SSO when required. Alternatively,
|
|
63
|
-
make the package public to allow unauthenticated pulls; this also makes it
|
|
64
|
-
available outside the organisation.
|
|
25
|
+
creation for the repository. The published image is public, so Docker and
|
|
26
|
+
Testcontainers can pull it without authentication both locally and in CI.
|
|
65
27
|
|
|
66
28
|
### Local Image Build
|
|
67
29
|
|
|
@@ -77,7 +39,7 @@ Requires Node.js 22.22 or newer. From the repository root:
|
|
|
77
39
|
|
|
78
40
|
```sh
|
|
79
41
|
npm ci
|
|
80
|
-
npm
|
|
42
|
+
npm run build
|
|
81
43
|
npm pack
|
|
82
44
|
```
|
|
83
45
|
|
|
@@ -86,7 +48,7 @@ tarball in a consuming project alongside `testcontainers@^12.2.1`.
|
|
|
86
48
|
|
|
87
49
|
### Publishing to npm
|
|
88
50
|
|
|
89
|
-
The package workflow builds
|
|
51
|
+
The package workflow builds the package on pull
|
|
90
52
|
requests and pushes to `main`. After those checks pass on `main`, Changesets
|
|
91
53
|
opens or updates a release pull request with version and changelog updates.
|
|
92
54
|
Merging that pull request publishes the new version to the public npm registry.
|
|
@@ -99,46 +61,36 @@ publishes unpublished versions; it is normally run by CI.
|
|
|
99
61
|
|
|
100
62
|
### Snapshot Releases
|
|
101
63
|
|
|
102
|
-
Run `npm run changeset
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
for manual triggers on non-`main` branches, after the test job passes. Pull
|
|
108
|
-
requests run the normal CI tests without publishing. Manual runs on `main` do
|
|
109
|
-
not publish. The workflow must exist on the default branch before GitHub shows
|
|
110
|
-
the **Run workflow** button.
|
|
111
|
-
|
|
112
|
-
Configure an npm trusted publisher for `guardian/end-to-end-testing` with the
|
|
113
|
-
workflow filename `ci.yml` and permission to publish directly with `npm publish`.
|
|
114
|
-
This is shared with normal releases; no npm token secret is required.
|
|
64
|
+
Run `npm run changeset` and commit the generated changeset to a pull request
|
|
65
|
+
whose branch is in this repository. Add the `🐥 Canaries` label to the PR.
|
|
66
|
+
After the image and build jobs succeed, CI publishes a snapshot under npm's
|
|
67
|
+
`canary` tag without changing `latest`. Fork PRs and manual workflow runs do
|
|
68
|
+
not publish snapshots.
|
|
115
69
|
|
|
116
|
-
|
|
117
|
-
snapshot label containing the run ID and attempt, then builds and tests it.
|
|
118
|
-
Manual runs publish under the `snapshot-<run-id>-<run-attempt>` npm tag. It does
|
|
119
|
-
not commit version changes, create Git tags, or update npm's `latest` tag. The
|
|
120
|
-
committed changeset remains available for the normal release. For example, run
|
|
121
|
-
`123456789`, attempt `1`:
|
|
70
|
+
To install the most recently published canary:
|
|
122
71
|
|
|
123
72
|
```sh
|
|
124
|
-
npm install @guardian/end-to-end-testing@
|
|
73
|
+
npm install @guardian/end-to-end-testing@canary
|
|
125
74
|
```
|
|
126
75
|
|
|
127
|
-
|
|
128
|
-
|
|
76
|
+
To test a specific PR snapshot, install the exact `package@version` from the
|
|
77
|
+
workflow's PR comment. The `canary` tag can move when another PR publishes.
|
|
78
|
+
After publishing, CI removes the label; reapply it to request another snapshot.
|
|
129
79
|
|
|
130
80
|
### Usage
|
|
131
81
|
|
|
132
82
|
```typescript
|
|
133
|
-
import { ApplicationContainer } from "end-to-end-testing";
|
|
83
|
+
import { ApplicationContainer } from "@guardian/end-to-end-testing";
|
|
134
84
|
import { Network } from "testcontainers";
|
|
135
85
|
|
|
136
86
|
const network = await new Network().start();
|
|
137
87
|
try {
|
|
138
|
-
const app = await new ApplicationContainer(
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
88
|
+
const app = await new ApplicationContainer({
|
|
89
|
+
name: "app",
|
|
90
|
+
exposedPorts: [9000],
|
|
91
|
+
healthCheckPort: 9000,
|
|
92
|
+
healthCheckPath: "/healthcheck",
|
|
93
|
+
})
|
|
142
94
|
.withNetwork(network)
|
|
143
95
|
.withNetworkAliases("app")
|
|
144
96
|
.withBindMounts([{ source: "/path/to/app", target: "/app" }])
|
|
@@ -156,13 +108,13 @@ try {
|
|
|
156
108
|
}
|
|
157
109
|
```
|
|
158
110
|
|
|
111
|
+
Omit `image` to use the Dockerfile hash tag embedded in the installed package,
|
|
112
|
+
or supply an explicit image reference to override it.
|
|
159
113
|
The image has no application or start command, so the caller supplies them,
|
|
160
114
|
along with any backing services the application needs on the network.
|
|
161
115
|
|
|
162
116
|
`ApplicationContainer` extends `GenericContainer`, so network, environment,
|
|
163
117
|
bind mounts, log consumers, and other Testcontainers options remain available.
|
|
164
|
-
It pulls the specified image rather than building it, exposes the given
|
|
165
|
-
and waits up to ten minutes for HTTP 200 from the given health-check path.
|
|
118
|
+
It pulls the specified image rather than building it, exposes the given ports,
|
|
119
|
+
and waits up to ten minutes for HTTP 200 from the given health-check path and port.
|
|
166
120
|
|
|
167
|
-
Unit tests exercise configuration without Docker. They do not verify a running
|
|
168
|
-
stack.
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import { GenericContainer } from "testcontainers";
|
|
1
|
+
import { GenericContainer, PortWithOptionalBinding } from "testcontainers";
|
|
2
2
|
export type ApplicationContainerOptions = {
|
|
3
|
-
|
|
3
|
+
image?: string;
|
|
4
|
+
name: string;
|
|
5
|
+
exposedPorts: PortWithOptionalBinding[];
|
|
6
|
+
healthCheckPort: number;
|
|
4
7
|
healthCheckPath: string;
|
|
5
8
|
};
|
|
6
9
|
export declare class ApplicationContainer extends GenericContainer {
|
|
7
|
-
constructor(image
|
|
10
|
+
constructor({ image, exposedPorts, healthCheckPort, healthCheckPath, }: ApplicationContainerOptions);
|
|
8
11
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ApplicationContainer = void 0;
|
|
4
|
-
var ApplicationContainer_1 = require("./ApplicationContainer");
|
|
5
|
-
Object.defineProperty(exports, "ApplicationContainer", { enumerable: true, get: function () { return ApplicationContainer_1.ApplicationContainer; } });
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("testcontainers");var t=class extends e.GenericContainer{constructor({image:t=`ghcr.io/guardian/end-to-end-testing/application:sha-c943bdee255ed0c6b43e86396f044732a833107d`,exposedPorts:n,healthCheckPort:r,healthCheckPath:i}){if(!t||!t.trim())throw Error(`A published application image reference is required`);super(t),this.withExposedPorts(...n).withStartupTimeout(6e5).withWaitStrategy(e.Wait.forHttp(i,r).forStatusCode(200))}};exports.ApplicationContainer=t;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@guardian/end-to-end-testing",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Shared Docker images and Testcontainers building blocks for end-to-end stacks.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -21,8 +21,7 @@
|
|
|
21
21
|
"node": ">=22.22"
|
|
22
22
|
},
|
|
23
23
|
"scripts": {
|
|
24
|
-
"build": "tsc -p tsconfig.json",
|
|
25
|
-
"test": "npm run build && node --test test/*.test.cjs",
|
|
24
|
+
"build": "vite build && tsc -p tsconfig.json --emitDeclarationOnly",
|
|
26
25
|
"prepack": "npm run build",
|
|
27
26
|
"changeset": "npx changeset"
|
|
28
27
|
},
|
|
@@ -33,6 +32,7 @@
|
|
|
33
32
|
"@changesets/cli": "^3.0.3",
|
|
34
33
|
"@types/node": "^22.0.0",
|
|
35
34
|
"testcontainers": "^12.2.1",
|
|
36
|
-
"typescript": "~5.9.3"
|
|
35
|
+
"typescript": "~5.9.3",
|
|
36
|
+
"vite": "^8.3.8"
|
|
37
37
|
}
|
|
38
38
|
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ApplicationContainer = void 0;
|
|
4
|
-
const testcontainers_1 = require("testcontainers");
|
|
5
|
-
class ApplicationContainer extends testcontainers_1.GenericContainer {
|
|
6
|
-
constructor(image, { port, healthCheckPath }) {
|
|
7
|
-
if (!image.trim()) {
|
|
8
|
-
throw new Error("A published application image reference is required");
|
|
9
|
-
}
|
|
10
|
-
super(image);
|
|
11
|
-
this.withExposedPorts(port);
|
|
12
|
-
// Allows for compiling the application on first start.
|
|
13
|
-
this.withStartupTimeout(10 * 60 * 1000);
|
|
14
|
-
this.withWaitStrategy(testcontainers_1.Wait.forHttp(healthCheckPath, port).forStatusCode(200));
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
exports.ApplicationContainer = ApplicationContainer;
|