Skip to content

Commit

Permalink
fix(msw): create tmp folder on mkdtempSync failure
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Marcus Noll and robertkowalski committed Apr 25, 2022
1 parent bd4fed3 commit fd1229e
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/msw/mixin.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down

0 comments on commit fd1229e

Please sign in to comment.