mirror of
https://github.com/cypress-io/cypress.git
synced 2026-02-05 06:40:56 -06:00
server: update cache project insertion
This commit is contained in:
@@ -84,10 +84,13 @@ module.exports = {
|
||||
insertProject: (path) ->
|
||||
fileUtil.transaction (tx) =>
|
||||
@_getProjects(tx).then (projects) =>
|
||||
## bail if we already have this path
|
||||
return projects if path in 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.push(path)
|
||||
projects.unshift(path)
|
||||
tx.set("PROJECTS", projects)
|
||||
|
||||
getUser: ->
|
||||
|
||||
@@ -56,27 +56,44 @@ describe "lib/cache", ->
|
||||
context "projects", ->
|
||||
describe "#insertProject", ->
|
||||
it "inserts project by path", ->
|
||||
cache.insertProject("foo/bar").then =>
|
||||
cache.__get("PROJECTS").then (projects) ->
|
||||
expect(projects).to.deep.eq ["foo/bar"]
|
||||
|
||||
it "is a noop if project already exists by id", ->
|
||||
cache.insertProject("foo/bar")
|
||||
.then =>
|
||||
cache.insertProject("foo/bar")
|
||||
.then =>
|
||||
cache.__get("PROJECTS").then (projects) ->
|
||||
expect(projects).to.deep.eq(["foo/bar"])
|
||||
.then ->
|
||||
cache.__get("PROJECTS")
|
||||
.then (projects) ->
|
||||
expect(projects).to.deep.eq ["foo/bar"]
|
||||
|
||||
it "can insert multiple projects", ->
|
||||
it "inserts project at the start", ->
|
||||
cache.insertProject("foo")
|
||||
.then ->
|
||||
cache.insertProject("bar")
|
||||
.then ->
|
||||
cache.__get("PROJECTS")
|
||||
.then (projects) ->
|
||||
expect(projects).to.deep.eq ["bar", "foo"]
|
||||
|
||||
it "can insert multiple projects in a row", ->
|
||||
Promise.all([
|
||||
cache.insertProject("baz")
|
||||
cache.insertProject("bar")
|
||||
cache.insertProject("foo")
|
||||
])
|
||||
.then ->
|
||||
cache.__get("PROJECTS")
|
||||
.then (projects) ->
|
||||
expect(projects).to.deep.eq(["foo", "bar", "baz"])
|
||||
|
||||
it "moves project to start if it already exists", ->
|
||||
Promise.all([
|
||||
cache.insertProject("foo")
|
||||
cache.insertProject("bar")
|
||||
cache.insertProject("baz")
|
||||
])
|
||||
.then =>
|
||||
cache.__get("PROJECTS").then (projects) ->
|
||||
expect(projects).to.deep.eq(["foo", "bar", "baz"])
|
||||
.then ->
|
||||
cache.insertProject("bar")
|
||||
.then ->
|
||||
cache.__get("PROJECTS")
|
||||
.then (projects) ->
|
||||
expect(projects).to.deep.eq ["bar", "baz", "foo"]
|
||||
|
||||
describe "#removeProject", ->
|
||||
it "removes project by path", ->
|
||||
@@ -100,7 +117,7 @@ describe "lib/cache", ->
|
||||
cache.insertProject("/Users/sam/app2")
|
||||
.then =>
|
||||
cache.getProjectPaths().then (paths) ->
|
||||
expect(paths).to.deep.eq ["/Users/brian/app", "/Users/sam/app2"]
|
||||
expect(paths).to.deep.eq ["/Users/sam/app2", "/Users/brian/app"]
|
||||
|
||||
it "removes any paths which no longer exist on the filesystem", ->
|
||||
@statAsync.withArgs("/Users/brian/app").resolves()
|
||||
|
||||
Reference in New Issue
Block a user