Files
cypress/packages/server/lib/cache.coffee
Brian Mann 4b368830fa send array of specs to API + platform (#1682)
* WIP: refactor runs and recordings, update to new API updates, iteratively send spec results [skip ci]

* update / add schema deps

* add takenAt to screenshots payload

* WIP: refactor recordings to send correctly payloads, iterative through each spec, error handling, e2e tests

* add missing properties, remove hacks, upload stdout, passing tests

* normalize wall clock for newest schema spec

* rename projectPath -> projectRoot for clarity

* normalize specPattern to be relative to projectRoot

* comment out lib/api debug code

* WIP fixes a lot of failing tests

* many more tests around recording

* WIP: update to use x-os-name on all instead of platform

* WIP: update to route version 4 for creating instances

* server: upgrade json-schemas to 4.7.2

* remove debug logs

* fix stdout not being restored correctly between specs

* test all the edge cases with failed api interactions and early exits

* add e2e tests around recording without projectID

* add e2e tests around recording without recordKey

* refactored all tests surrounding record mode, removed duplicates, tested only edge cases

* fixes #1692

* fix failing unit tests, bump schemas

* bump sinon, replace custom sandbox

* fix sinon@5 not restoring fake timers automatically

* missing e2e record snapshots

* fix failing tests, don't pass config through each run, remove old timings in favor of spec isolation

* more e2e test fixes

* add e2e tests around uploading artifacts, fix bug with not uploading videos when it should

- cleanup some dead code
- add debug logs

* cleanup dead code, remove notion of failingTests
2018-05-13 20:24:46 -04:00

118 lines
2.8 KiB
CoffeeScript

_ = require("lodash")
path = require("path")
Promise = require("bluebird")
fs = require("./util/fs")
appData = require("./util/app_data")
FileUtil = require("./util/file")
logger = require("./logger")
fileUtil = new FileUtil({
path: appData.path("cache")
})
convertProjectsToArray = (obj) ->
## if our project structure is not
## an array then its legacy and we
## need to convert it
if not _.isArray(obj.PROJECTS)
obj.PROJECTS = _.chain(obj.PROJECTS).values().map("PATH").compact().value()
obj
renameSessionToken = (obj) ->
if obj.USER and (st = obj.USER.session_token)
delete obj.USER.session_token
obj.USER.sessionToken = st
obj
module.exports = {
path: fileUtil.path
defaults: ->
{
USER: {}
PROJECTS: []
}
_applyRewriteRules: (obj = {}) ->
_.reduce [convertProjectsToArray, renameSessionToken], (memo, fn) ->
if ret = fn(memo)
return ret
else
return memo
, _.cloneDeep(obj)
read: ->
fileUtil.get().then (contents) =>
_.defaults(contents, @defaults())
write: (obj = {}) ->
logger.info("writing to .cy cache", {cache: obj})
fileUtil.set(obj).return(obj)
_getProjects: (tx) ->
tx.get("PROJECTS", [])
_removeProjects: (tx, projects, paths) ->
## normalize paths in array
projects = _.without(projects, [].concat(paths)...)
tx.set({PROJECTS: projects})
getProjectRoots: ->
fileUtil.transaction (tx) =>
@_getProjects(tx).then (projects) =>
pathsToRemove = Promise.reduce projects, (memo, path) ->
fs.statAsync(path)
.catch ->
memo.push(path)
.return(memo)
, []
pathsToRemove.then (removedPaths) =>
@_removeProjects(tx, projects, removedPaths)
.then =>
@_getProjects(tx)
removeProject: (path) ->
fileUtil.transaction (tx) =>
@_getProjects(tx).then (projects) =>
@_removeProjects(tx, projects, path)
insertProject: (path) ->
fileUtil.transaction (tx) =>
@_getProjects(tx).then (projects) =>
## projects are sorted by most recently used, so add a project to
## the start or move it to the start if it already exists
existingIndex = _.findIndex projects, (project) -> project is path
if existingIndex > -1
projects.splice(existingIndex, 1)
projects.unshift(path)
tx.set("PROJECTS", projects)
getUser: ->
logger.info "getting user"
fileUtil.get("USER", {})
setUser: (user) ->
logger.info("setting user", {user: user})
fileUtil.set({USER: user})
removeUser: ->
fileUtil.set({USER: {}})
remove: ->
fileUtil.remove()
## for testing purposes
__get: fileUtil.get.bind(fileUtil)
__removeSync: ->
fileUtil._cache = {}
fs.removeSync(@path)
}