From 888a509c372d9a173148d2776191edd5d1fe761c Mon Sep 17 00:00:00 2001 From: RMidhunSuresh Date: Tue, 6 Sep 2022 01:29:37 +0530 Subject: [PATCH] Support creating docker networks from the plugin --- cypress/plugins/docker/index.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/cypress/plugins/docker/index.ts b/cypress/plugins/docker/index.ts index fe9c24ae..a55f341e 100644 --- a/cypress/plugins/docker/index.ts +++ b/cypress/plugins/docker/index.ts @@ -78,6 +78,31 @@ export function dockerExec(args: { }); } +/** + * Create a docker network; does not fail if network already exists + */ +export function dockerCreateNetwork(args: { + networkName: string; +}): Promise { + return new Promise((resolve, reject) => { + childProcess.execFile("docker", [ + "network", + "create", + args.networkName + ], { encoding: 'utf8' }, (err, stdout, stderr) => { + if(err) { + if (stderr.includes(`network with name ${args.networkName} already exists`)) { + // Don't consider this as error + resolve(); + } + reject(err); + return; + } + resolve(); + }) + }); +} + export async function dockerLogs(args: { containerId: string; stdoutFile?: string; @@ -142,5 +167,6 @@ export function docker(on: PluginEvents, config: PluginConfigOptions) { dockerLogs, dockerStop, dockerRm, + dockerCreateNetwork }); }