Skip to content

Commit

Permalink
chore: fix server unit tests running on mac by using actual tmp dir
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbreiding committed Dec 13, 2021
1 parent f33abf6 commit 4d5822d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
24 changes: 12 additions & 12 deletions system-tests/lib/fixtures.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -27,17 +27,17 @@ 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)
}

/**
* Given a project name, copy the project's test files to the temp dir.
*/
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)
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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))
Expand All @@ -312,27 +312,27 @@ 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)
})
.on('error', console.error)
}

// 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') {
Expand Down
1 change: 1 addition & 0 deletions system-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down

0 comments on commit 4d5822d

Please sign in to comment.