Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There is no way to avoid clearing indexedDB between specs with cacheAcrossSpecs=true #27155

Closed
asier-perez opened this issue Jun 28, 2023 · 3 comments
Assignees

Comments

@asier-perez
Copy link

What would you like?

I would like to be allowed to keep the indexedDB data between specs when cacheAcrossSpecs is set to true in cy.session().

Why is this needed?

I suppose that the indexedDB should be cleared by default, but I'd like to ask for a parameter similar to cacheAcrossSpecs, like indexeddbAcrossSpecs or so. Or another way to keep it between specs, at least when cacheAcrossSpecs is set to true. I know that there is a workaround, but it does not work for me.

Other

No response

@mike-plummer
Copy link
Contributor

@asier-perez Officially cy.session doesn't support IndexedDB - that's been requested/discussed in #18350 but since a viable workaround was posted it hasn't been prioritized. Can you expand on how/why the workaround described there doesn't work for your use case?

@mike-plummer mike-plummer self-assigned this Jun 28, 2023
@asier-perez
Copy link
Author

Hi @mike-plummer, the workaround gives me an error, but I'm not sure why. When I call importIDB in the validate block => on the step where the db constant is created with value event.target.result, event is always empty. I'm referring to this is the peace of code inside importIDB:

indexedDB.open(dbName).onsuccess = async (event) => {
    const db = (event.target as IDBOpenDBRequest).result
    await clearDatabase(db)
    await importFromJson(db, json.toString())
    resolve()
}

I have to mention that, in my code, I have event.target.result instead of (event.target as IDBOpenDBRequest).result, both in importIDB and exportIDB functions. This is because it was giving me these two compilation errors (the first one in target and the second one in IDBOpenDBRequest):

  • Parsing error: Unexpected token, expected ","
  • Type assertion expressions can only be used in TypeScript files

@mike-plummer
Copy link
Contributor

@asier-perez Interesting - the example code is Typescript, maybe the file you were trying to paste it into is just Javascript? Might be some browser-specific behavior there as well re: the differently-shaped event object, not super-familiar with IndexedDB myself. You might try reaching out on Discord, I'm sure there are folks there who have hit the same issue and can help.

I think the best approach might be to close this issue in favor of #18350 since that issue discusses a more comprehensive solution for IndexedDB with cy.session. This issue would be linked and available as context for that issue. I can then pass it along to the team to evaluate for future feature development. They'll determine priority consider their capacity to pick it up. LMK if you disagree and we can reopen this - just trying to avoid duplication/fragmenting of issues so everyone can discuss more easily

@mike-plummer mike-plummer closed this as not planned Won't fix, can't repro, duplicate, stale Jun 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants