From 22bb1a17930bdbcf9a2068790efd880fe8ff4158 Mon Sep 17 00:00:00 2001 From: iwata Date: Sat, 14 May 2022 15:16:45 +0900 Subject: [PATCH] =?UTF-8?q?test:=20e2e=E3=83=86=E3=82=B9=E3=83=88=E3=81=8C?= =?UTF-8?q?CI=E3=81=A7=E5=A4=B1=E6=95=97=E3=81=97=E3=81=A6=E3=81=84?= =?UTF-8?q?=E3=81=9F=E5=95=8F=E9=A1=8C=E3=82=92=E3=81=84=E3=81=8F=E3=81=A4?= =?UTF-8?q?=E3=81=8B=E4=BF=AE=E6=AD=A3=20(#8642)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * test: indexeddbをテスト毎に初期化するように * fix: metaが無いときにfetch-metaを同時に呼ぶと死ぬことがある問題を修正 * test: ログイン後のクライアント側処理を待たずにリロードされてログイン出来ないことがあったのを修正 --- cypress/integration/basic.js | 16 +++++++++++++--- packages/backend/src/misc/fetch-meta.ts | 13 ++++++++++--- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/cypress/integration/basic.js b/cypress/integration/basic.js index 7d27b649f..eb15cfe22 100644 --- a/cypress/integration/basic.js +++ b/cypress/integration/basic.js @@ -1,5 +1,8 @@ describe('Before setup instance', () => { beforeEach(() => { + cy.window(win => { + win.indexedDB.deleteDatabase('keyval-store'); + }); cy.request('POST', '/api/reset-db').as('reset'); cy.get('@reset').its('status').should('equal', 204); cy.reload(true); @@ -32,6 +35,9 @@ describe('Before setup instance', () => { describe('After setup instance', () => { beforeEach(() => { + cy.window(win => { + win.indexedDB.deleteDatabase('keyval-store'); + }); cy.request('POST', '/api/reset-db').as('reset'); cy.get('@reset').its('status').should('equal', 204); cy.reload(true); @@ -70,6 +76,9 @@ describe('After setup instance', () => { describe('After user signup', () => { beforeEach(() => { + cy.window(win => { + win.indexedDB.deleteDatabase('keyval-store'); + }); cy.request('POST', '/api/reset-db').as('reset'); cy.get('@reset').its('status').should('equal', 204); cy.reload(true); @@ -129,6 +138,9 @@ describe('After user signup', () => { describe('After user singed in', () => { beforeEach(() => { + cy.window(win => { + win.indexedDB.deleteDatabase('keyval-store'); + }); cy.request('POST', '/api/reset-db').as('reset'); cy.get('@reset').its('status').should('equal', 204); cy.reload(true); @@ -163,12 +175,10 @@ describe('After user singed in', () => { }); it('successfully loads', () => { - cy.visit('/'); + cy.get('[data-cy-open-post-form]').should('be.visible'); }); it('note', () => { - cy.visit('/'); - cy.get('[data-cy-open-post-form]').click(); cy.get('[data-cy-post-form-text]').type('Hello, Misskey!'); cy.get('[data-cy-open-post-form-submit]').click(); diff --git a/packages/backend/src/misc/fetch-meta.ts b/packages/backend/src/misc/fetch-meta.ts index 5417c1096..e855ac28e 100644 --- a/packages/backend/src/misc/fetch-meta.ts +++ b/packages/backend/src/misc/fetch-meta.ts @@ -20,9 +20,16 @@ export async function fetchMeta(noCache = false): Promise { cache = meta; return meta; } else { - const saved = await transactionalEntityManager.save(Meta, { - id: 'x', - }) as Meta; + // metaが空のときfetchMetaが同時に呼ばれるとここが同時に呼ばれてしまうことがあるのでフェイルセーフなupsertを使う + const saved = await transactionalEntityManager + .upsert( + Meta, + { + id: 'x', + }, + ['id'], + ) + .then((x) => transactionalEntityManager.findOneByOrFail(Meta, x.identifiers[0])); cache = saved; return saved;