From 4d5822d31e8f20d58d917f34b8a6b78c19ba7aa7 Mon Sep 17 00:00:00 2001 From: Chris Breiding Date: Mon, 13 Dec 2021 14:15:12 -0500 Subject: [PATCH] chore: fix server unit tests running on mac by using actual tmp dir --- system-tests/lib/fixtures.ts | 24 ++++++++++++------------ system-tests/package.json | 1 + 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/system-tests/lib/fixtures.ts b/system-tests/lib/fixtures.ts index 46472e6d3e9d..a2d489c7a83a 100644 --- a/system-tests/lib/fixtures.ts +++ b/system-tests/lib/fixtures.ts @@ -1,15 +1,15 @@ import fs from 'fs-extra' import _path from 'path' import chokidar from 'chokidar' -import os from 'os' import cachedir from 'cachedir' import execa from 'execa' +import tempDir from 'temp-dir' const root = _path.join(__dirname, '..') const serverRoot = _path.join(__dirname, '../../packages/server/') const projects = _path.join(root, 'projects') -const tmpDir = _path.join(os.tmpdir(), 'cy-projects') +const cyTmpDir = _path.join(tempDir, 'cy-projects') // copy contents instead of deleting+creating new file, which can cause // filewatchers to lose track of toFile. @@ -27,9 +27,9 @@ const copyContents = (fromFile, toFile) => { } // copies all of the project fixtures -// to the tmpDir .projects in the root +// to the cyTmpDir .projects in the root export function scaffold () { - fs.copySync(projects, tmpDir) + fs.copySync(projects, cyTmpDir) } /** @@ -37,7 +37,7 @@ export function scaffold () { */ export function scaffoldProject (project: string): void { const from = _path.join(projects, project) - const to = _path.join(tmpDir, project) + const to = _path.join(cyTmpDir, project) fs.copySync(from, to) } @@ -131,7 +131,7 @@ function getYarnCommand (opts: { // in CircleCI, this offline cache can be used if (opts.isCI) cmd += ` --cache-folder=~/.yarn-${process.platform} ` - else cmd += ` --cache-folder=${_path.join(os.tmpdir(), 'cy-system-tests-yarn-cache', String(Date.now()))}` + else cmd += ` --cache-folder=${_path.join(tempDir, 'cy-system-tests-yarn-cache', String(Date.now()))}` return cmd } @@ -291,7 +291,7 @@ export async function scaffoldCommonNodeModules () { } export async function symlinkNodeModule (pkg) { - const from = _path.join(tmpDir, 'node_modules', pkg) + const from = _path.join(cyTmpDir, 'node_modules', pkg) const to = pathToPackage(pkg) await fs.ensureDir(_path.dirname(from)) @@ -312,7 +312,7 @@ export function scaffoldWatch () { chokidar.watch(watchdir, { }) .on('change', (srcFilepath, stats) => { - const tmpFilepath = _path.join(tmpDir, _path.relative(watchdir, srcFilepath)) + const tmpFilepath = _path.join(cyTmpDir, _path.relative(watchdir, srcFilepath)) return copyContents(srcFilepath, tmpFilepath) }) @@ -320,19 +320,19 @@ export function scaffoldWatch () { } // removes all of the project fixtures -// from the tmpDir .projects in the root +// from the cyTmpDir .projects in the root export function remove () { - return fs.removeSync(tmpDir) + return fs.removeSync(cyTmpDir) } // returns the path to project fixture -// in the tmpDir +// in the cyTmpDir export function project (...args) { return this.projectPath.apply(this, args) } export function projectPath (name) { - return _path.join(tmpDir, name) + return _path.join(cyTmpDir, name) } export function get (fixture, encoding: BufferEncoding = 'utf8') { diff --git a/system-tests/package.json b/system-tests/package.json index 16e0bf481bed..57c202776b78 100644 --- a/system-tests/package.json +++ b/system-tests/package.json @@ -73,6 +73,7 @@ "ssestream": "1.0.1", "supertest": "4.0.2", "systeminformation": "5.6.4", + "temp-dir": "^2.0.0", "webpack": "4.43.0", "ws": "5.2.3" },