Skip to content

Commit

Permalink
test(integration): properly waited for the image pulls to complete (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
travi committed Jun 26, 2023
1 parent 39d2a05 commit e39ae90
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 12 deletions.
16 changes: 12 additions & 4 deletions test/helpers/gitbox.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Docker from "dockerode";
import getStream from "get-stream";
import pRetry from "p-retry";
import { gitShallowClone, initBareRepo } from "./git-utils.js";

Expand All @@ -15,11 +14,20 @@ let container;
export const gitCredential = `${GIT_USERNAME}:${GIT_PASSWORD}`;

/**
* Download the `gitbox` Docker image, create a new container and start it.
* Download the `gitbox` Docker image
*/
export async function start() {
await getStream(await docker.pull(IMAGE));
export function pull() {
return docker.pull(IMAGE).then((stream) => {
return new Promise((resolve, reject) => {
docker.modem.followProgress(stream, (err, res) => (err ? reject(err) : resolve(res)));
});
});
}

/**
* create a new container and start it.
*/
export async function start() {
container = await docker.createContainer({
Tty: true,
Image: IMAGE,
Expand Down
16 changes: 12 additions & 4 deletions test/helpers/mockserver.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Docker from "dockerode";
import getStream from "get-stream";
import got from "got";
import pRetry from "p-retry";
import { mockServerClient } from "mockserver-client";
Expand All @@ -11,11 +10,20 @@ const docker = new Docker();
let container;

/**
* Download the `mockserver` Docker image, create a new container and start it.
* Download the `mockserver` Docker image,
*/
export async function start() {
await getStream(await docker.pull(IMAGE));
export function pull() {
return docker.pull(IMAGE).then((stream) => {
return new Promise((resolve, reject) => {
docker.modem.followProgress(stream, (err, res) => (err ? reject(err) : resolve(res)));
});
});
}

/**
* create a new container and start it.
*/
export async function start() {
container = await docker.createContainer({
Tty: true,
Image: IMAGE,
Expand Down
16 changes: 12 additions & 4 deletions test/helpers/npm-registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import path, { dirname } from "node:path";
import { fileURLToPath } from "node:url";
import { setTimeout } from "node:timers/promises";
import Docker from "dockerode";
import getStream from "get-stream";
import got from "got";
import pRetry from "p-retry";

Expand All @@ -17,11 +16,20 @@ const __dirname = dirname(fileURLToPath(import.meta.url));
let container, npmToken;

/**
* Download the `npm-registry-docker` Docker image, create a new container and start it.
* Download the `npm-registry-docker` Docker image
*/
export async function start() {
await getStream(await docker.pull(IMAGE));
export function pull() {
return docker.pull(IMAGE).then((stream) => {
return new Promise((resolve, reject) => {
docker.modem.followProgress(stream, (err, res) => (err ? reject(err) : resolve(res)));
});
});
}

/**
* create a new container and start it.
*/
export async function start() {
container = await docker.createContainer({
Tty: true,
Image: IMAGE,
Expand Down
1 change: 1 addition & 0 deletions test/integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const pluginLogEnv = path.resolve("./test/fixtures/plugin-log-env");
const pluginEsmNamedExports = path.resolve("./test/fixtures/plugin-esm-named-exports");

test.before(async () => {
await Promise.all([gitbox.pull(), npmRegistry.pull(), mockServer.pull()]);
await Promise.all([gitbox.start(), npmRegistry.start(), mockServer.start()]);

env = {
Expand Down

0 comments on commit e39ae90

Please sign in to comment.