From fd1229e7a4eb70172c142406b15f23d13f370441 Mon Sep 17 00:00:00 2001 From: Marcus Noll Date: Mon, 25 Apr 2022 16:12:56 +0200 Subject: [PATCH] fix(msw): create tmp folder on mkdtempSync failure We found that when executing msw tests within a Docker container, a tmp folder does not exist. With this change, a tmp folder is created in case mkdtempSync fails. Co-authored-by: Robert Kowalski --- packages/msw/mixin.core.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/msw/mixin.core.js b/packages/msw/mixin.core.js index c242f887a..477b633b9 100644 --- a/packages/msw/mixin.core.js +++ b/packages/msw/mixin.core.js @@ -11,12 +11,18 @@ function exists(path) { } const getMockServiceWorkerContent = () => { - const { mkdtempSync, readFileSync } = require('fs'); + const { mkdtempSync, readFileSync, mkdirSync } = require('fs'); const { tmpdir } = require('os'); const { join } = require('path'); const { sync: execa } = require('execa'); + let dir; - const dir = mkdtempSync(join(tmpdir(), 'msw-')); + try { + dir = mkdtempSync(join(tmpdir(), 'msw-')); + } catch (error) { + mkdirSync(tmpdir()); + dir = mkdtempSync(join(tmpdir(), 'msw-')); + } execa(process.execPath, [ require.resolve('msw/cli'),