Files
cypress/packages/server/lib/util/saved_state.coffee
T
Gleb Bahmutov 4409698c7f Remove fs sync 373 (#376)
* remove fs.existsSync in unit test, close #373

* updating an integration test

* remove unlinkSync from an integration spec

* remove only

* make saved_stage async

* switched some tests to async state

* server: fix more state tests

* working on config to async

* change config mergeDefaults to async

* more .mergeDefaults tests updated

* fix config unit tests

* remove only in config unit tests

* fix server unit test

* fix two more tests

* server: maybe all unit tests fixed

* server: handle NPM 3 vs 4 in exit codes

* fix server start

* fix another server startup in test

* server: messaging and promise.try
2017-08-25 11:31:36 -04:00

49 lines
1.4 KiB
CoffeeScript

log = require('../log')
cwd = require('../cwd')
fs = require('fs-extra')
md5 = require('md5')
sanitize = require("sanitize-filename")
Promise = require("bluebird")
{ basename, join, isAbsolute } = require('path')
toHashName = (projectPath) ->
throw new Error("Missing project path") unless projectPath
throw new Error("Expected project absolute path, not just a name #{projectPath}") unless isAbsolute(projectPath)
name = sanitize(basename(projectPath))
hash = md5(projectPath)
"#{name}-#{hash}"
# async promise-returning method
formStatePath = (projectPath) ->
Promise.resolve()
.then ->
log('making saved state from %s', cwd())
if projectPath
log('for project path %s', projectPath)
else
log('missing project path, looking for project here')
cypressJsonPath = cwd('cypress.json')
fs.pathExists(cypressJsonPath)
.then (found) ->
if found
log('found cypress file %s', cypressJsonPath)
projectPath = cwd()
return projectPath
.then (projectPath) ->
fileName = "state.json"
if projectPath
log("state path for project #{projectPath}")
statePath = join(toHashName(projectPath), fileName)
else
log("state path for global mode")
statePath = join("__global__", fileName)
return statePath
module.exports = {
toHashName: toHashName,
formStatePath: formStatePath
}