@guardian/end-to-end-testing 0.0.0-stage → 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 +119 -2
- package/dist/ApplicationContainer.d.ts +11 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/package.json +36 -4
package/README.md
CHANGED
|
@@ -1,3 +1,120 @@
|
|
|
1
|
-
#
|
|
1
|
+
# end-to-end-testing
|
|
2
|
+
Provide reusable code and docker images to help set up a local stack for end-to-end testing
|
|
3
|
+
|
|
4
|
+
## Application Image
|
|
5
|
+
|
|
6
|
+
[container-images/application.Dockerfile](container-images/application.Dockerfile)
|
|
7
|
+
is a base image for running an application under test in an end-to-end stack:
|
|
8
|
+
Ubuntu with build essentials and [mise](https://mise.jdx.dev/) for installing
|
|
9
|
+
the application's toolchain. It contains no application code.
|
|
10
|
+
|
|
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
|
+
|
|
24
|
+
Publishing uses `GITHUB_TOKEN` with `packages: write`. Enable Actions and package
|
|
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.
|
|
27
|
+
|
|
28
|
+
### Local Image Build
|
|
29
|
+
|
|
30
|
+
From the repository root, with Docker BuildKit available:
|
|
31
|
+
|
|
32
|
+
```sh
|
|
33
|
+
docker build -f container-images/application.Dockerfile -t end-to-end-testing/application:local container-images
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## TypeScript Package
|
|
37
|
+
|
|
38
|
+
Requires Node.js 22.22 or newer. From the repository root:
|
|
39
|
+
|
|
40
|
+
```sh
|
|
41
|
+
npm ci
|
|
42
|
+
npm run build
|
|
43
|
+
npm pack
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
The tarball contains JavaScript and TypeScript declarations. Install that
|
|
47
|
+
tarball in a consuming project alongside `testcontainers@^12.2.1`.
|
|
48
|
+
|
|
49
|
+
### Publishing to npm
|
|
50
|
+
|
|
51
|
+
The package workflow builds the package on pull
|
|
52
|
+
requests and pushes to `main`. After those checks pass on `main`, Changesets
|
|
53
|
+
opens or updates a release pull request with version and changelog updates.
|
|
54
|
+
Merging that pull request publishes the new version to the public npm registry.
|
|
55
|
+
If the current version has never been published, a run on `main` with no pending
|
|
56
|
+
changesets can publish it directly.
|
|
57
|
+
|
|
58
|
+
For each package change, run `npm run changeset`, choose the version bump, and
|
|
59
|
+
commit the generated file alongside the change. `npm run release` builds and
|
|
60
|
+
publishes unpublished versions; it is normally run by CI.
|
|
61
|
+
|
|
62
|
+
### Snapshot Releases
|
|
63
|
+
|
|
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.
|
|
69
|
+
|
|
70
|
+
To install the most recently published canary:
|
|
71
|
+
|
|
72
|
+
```sh
|
|
73
|
+
npm install @guardian/end-to-end-testing@canary
|
|
74
|
+
```
|
|
75
|
+
|
|
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.
|
|
79
|
+
|
|
80
|
+
### Usage
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
import { ApplicationContainer } from "@guardian/end-to-end-testing";
|
|
84
|
+
import { Network } from "testcontainers";
|
|
85
|
+
|
|
86
|
+
const network = await new Network().start();
|
|
87
|
+
try {
|
|
88
|
+
const app = await new ApplicationContainer({
|
|
89
|
+
name: "app",
|
|
90
|
+
exposedPorts: [9000],
|
|
91
|
+
healthCheckPort: 9000,
|
|
92
|
+
healthCheckPath: "/healthcheck",
|
|
93
|
+
})
|
|
94
|
+
.withNetwork(network)
|
|
95
|
+
.withNetworkAliases("app")
|
|
96
|
+
.withBindMounts([{ source: "/path/to/app", target: "/app" }])
|
|
97
|
+
.withWorkingDir("/app")
|
|
98
|
+
.withCommand(["/app/start.sh"])
|
|
99
|
+
.start();
|
|
100
|
+
|
|
101
|
+
try {
|
|
102
|
+
console.log(`http://${app.getHost()}:${app.getMappedPort(9000)}`);
|
|
103
|
+
} finally {
|
|
104
|
+
await app.stop();
|
|
105
|
+
}
|
|
106
|
+
} finally {
|
|
107
|
+
await network.stop();
|
|
108
|
+
}
|
|
109
|
+
```
|
|
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.
|
|
113
|
+
The image has no application or start command, so the caller supplies them,
|
|
114
|
+
along with any backing services the application needs on the network.
|
|
115
|
+
|
|
116
|
+
`ApplicationContainer` extends `GenericContainer`, so network, environment,
|
|
117
|
+
bind mounts, log consumers, and other Testcontainers options remain available.
|
|
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.
|
|
2
120
|
|
|
3
|
-
This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { GenericContainer, PortWithOptionalBinding } from "testcontainers";
|
|
2
|
+
export type ApplicationContainerOptions = {
|
|
3
|
+
image?: string;
|
|
4
|
+
name: string;
|
|
5
|
+
exposedPorts: PortWithOptionalBinding[];
|
|
6
|
+
healthCheckPort: number;
|
|
7
|
+
healthCheckPath: string;
|
|
8
|
+
};
|
|
9
|
+
export declare class ApplicationContainer extends GenericContainer {
|
|
10
|
+
constructor({ image, exposedPorts, healthCheckPort, healthCheckPath, }: ApplicationContainerOptions);
|
|
11
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
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,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@guardian/end-to-end-testing",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Shared Docker images and Testcontainers building blocks for end-to-end stacks.",
|
|
5
|
+
"type": "commonjs",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"repository": {
|
|
9
|
+
"url": "https://github.com/guardian/end-to-end-testing"
|
|
10
|
+
},
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"default": "./dist/index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=22.22"
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "vite build && tsc -p tsconfig.json --emitDeclarationOnly",
|
|
25
|
+
"prepack": "npm run build",
|
|
26
|
+
"changeset": "npx changeset"
|
|
27
|
+
},
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"testcontainers": "^12.2.1"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@changesets/cli": "^3.0.3",
|
|
33
|
+
"@types/node": "^22.0.0",
|
|
34
|
+
"testcontainers": "^12.2.1",
|
|
35
|
+
"typescript": "~5.9.3",
|
|
36
|
+
"vite": "^8.3.8"
|
|
37
|
+
}
|
|
38
|
+
}
|