Skip to content

Openverse is a search engine for openly-licensed media. This monorepo includes all application code.

Parallelize snapshot tests (#1559)

Krystle Salazarc4a117a11ddd
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index d726310a7..93ff9c453 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -129,7 +129,7 @@ jobs:
downloadLocales: true
- name: Run Nuxt Playwright tests
- run: pnpm test:playwright
+ run: pnpm test:playwright --workers=2
- uses: actions/upload-artifact@v3
if: failure()
diff --git a/bin/playwright.sh b/bin/playwright.sh
index dc619b74a..8b8d79fd6 100755
--- a/bin/playwright.sh
+++ b/bin/playwright.sh
@@ -12,3 +12,5 @@ export TEST_COMMAND=${TEST_COMMAND:-test:playwright:local}
echo Running Playwright v$PLAYWRIGHT_VERSION as $USER_ID with Playwright arguments $PLAYWRIGHT_ARGS
docker-compose -f docker-compose.playwright.yml up --build --force-recreate --abort-on-container-exit --exit-code-from playwright --remove-orphans
+
+docker-compose -f docker-compose.playwright.yml down
diff --git a/docker-compose.playwright.yml b/docker-compose.playwright.yml
index 765233b2d..9b0eac6c5 100644
--- a/docker-compose.playwright.yml
+++ b/docker-compose.playwright.yml
@@ -14,4 +14,6 @@ services:
environment:
# This makes the webserver that Playwright runs show the build
- DEBUG=pw:webserver
+ - DISABLE_SENTRY=true
- UPDATE_TAPES=${UPDATE_TAPES:-false}
+ cpus: 0.000
diff --git a/package.json b/package.json
index 10382cee2..062c2e272 100644
--- a/package.json
+++ b/package.json
@@ -36,7 +36,7 @@
"test:unit": "jest",
"test:unit:watch": "pnpm test:unit --collectCoverage=false --watch",
"test:playwright": "./bin/playwright.sh",
- "test:playwright:local": "playwright test -c test/playwright",
+ "test:playwright:local": "DISABLE_SENTRY=true playwright test -c test/playwright",
"test:playwright:debug": "PWDEBUG=1 pnpm test:playwright:local",
"test:playwright:recreate-tapes": "rimraf test/tapes && pnpm test:playwright:update-tapes",
"test:playwright:update-tapes": "UPDATE_TAPES=true pnpm test:playwright",
diff --git a/src/utils/env.ts b/src/utils/env.ts
index 54e65c356..3198c4cf0 100644
--- a/src/utils/env.ts
+++ b/src/utils/env.ts
@@ -8,6 +8,5 @@ const apiUrl = process.env.API_URL ?? 'https://api.openverse.engineering/'
export const env = {
apiUrl: apiUrl.endsWith('/') ? apiUrl : `${apiUrl}/`,
filterStorageKey: 'openverse-filter-visibility',
- enableInternalAnalytics: process.env.ENABLE_INTERNAL_ANALYTICS ?? 'false',
providerUpdateFrequency: `${60 * 60 * 1000}`, // 1 hour
} as const
diff --git a/src/utils/sentry-config.ts b/src/utils/sentry-config.ts
index 912ca9093..649c47aa1 100644
--- a/src/utils/sentry-config.ts
+++ b/src/utils/sentry-config.ts
@@ -11,7 +11,7 @@ export const sentryConfig: ModuleConfiguration = {
dsn:
process.env.SENTRY_DSN ||
'https://[email protected]/5799642',
- disabled: !isProd,
+ disabled: process.env.DISABLE_SENTRY ? true : !isProd,
lazy: true,
clientConfig: {
// Only allow errors that come from an actual openverse.engineering subdomain
diff --git a/test/playwright/e2e/filters.spec.ts b/test/playwright/e2e/filters.spec.ts
index 7605f4e28..08ba98e96 100644
--- a/test/playwright/e2e/filters.spec.ts
+++ b/test/playwright/e2e/filters.spec.ts
@@ -16,6 +16,8 @@ import {
AUDIO,
} from '~/constants/media'
+test.describe.configure({ mode: 'parallel' })
+
test.beforeEach(async ({ context }) => {
await mockProviderApis(context)
})
diff --git a/test/playwright/e2e/report-media.spec.ts b/test/playwright/e2e/report-media.spec.ts
index 55587a567..aa788ec24 100644
--- a/test/playwright/e2e/report-media.spec.ts
+++ b/test/playwright/e2e/report-media.spec.ts
@@ -8,6 +8,8 @@ import {
import { supportedMediaTypes } from '~/constants/media'
+test.describe.configure({ mode: 'parallel' })
+
/**
* Some helpers for repeated actions.
*/
diff --git a/test/playwright/playwright.config.ts b/test/playwright/playwright.config.ts
index 7f4ac8b51..c9c32c4b0 100644
--- a/test/playwright/playwright.config.ts
+++ b/test/playwright/playwright.config.ts
@@ -9,6 +9,8 @@ addAliases({
'~~': process.cwd(),
})
+const UPDATE_TAPES = process.env.UPDATE_TAPES || 'false'
+
const config: PlaywrightTestConfig = {
webServer: {
/**
@@ -32,7 +34,7 @@ const config: PlaywrightTestConfig = {
reuseExistingServer: !process.env.CI || process.env.PWDEBUG === '1',
env: {
API_URL: 'http://localhost:49153/',
- UPDATE_TAPES: process.env.UPDATE_TAPES || '',
+ UPDATE_TAPES: UPDATE_TAPES,
},
},
use: {
@@ -49,7 +51,7 @@ const config: PlaywrightTestConfig = {
* tapes then we can avoid this problem. Defaulting to `undefined` means the
* Playwright default of using 1/2 of the number of CPU cores continues to work otherwise.
*/
- workers: process.env.UPDATE_TAPES ? 1 : undefined,
+ workers: UPDATE_TAPES === 'true' ? 1 : undefined,
}
export default config
diff --git a/test/playwright/visual-regression/components/audio-results.spec.ts b/test/playwright/visual-regression/components/audio-results.spec.ts
index b5fad26d4..7c2999d24 100644
--- a/test/playwright/visual-regression/components/audio-results.spec.ts
+++ b/test/playwright/visual-regression/components/audio-results.spec.ts
@@ -2,6 +2,8 @@ import { test } from '@playwright/test'
import breakpoints from '~~/test/playwright/utils/breakpoints'
+test.describe.configure({ mode: 'parallel' })
+
test.describe('audio results', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/search/audio?q=birds')
diff --git a/test/playwright/visual-regression/components/header.spec.ts b/test/playwright/visual-regression/components/header.spec.ts
index efb221e57..9dcdef854 100644
--- a/test/playwright/visual-regression/components/header.spec.ts
+++ b/test/playwright/visual-regression/components/header.spec.ts
@@ -9,6 +9,8 @@ import {
sleep,
} from '~~/test/playwright/utils/navigation'
+test.describe.configure({ mode: 'parallel' })
+
const headerSelector = '.main-header'
const loadMoreSelector = 'button:has-text("Load more")'
diff --git a/test/playwright/visual-regression/components/media-reuse.spec.ts b/test/playwright/visual-regression/components/media-reuse.spec.ts
index 82eab6beb..912003f8a 100644
--- a/test/playwright/visual-regression/components/media-reuse.spec.ts
+++ b/test/playwright/visual-regression/components/media-reuse.spec.ts
@@ -7,6 +7,8 @@ import {
languageDirections,
} from '~~/test/playwright/utils/navigation'
+test.describe.configure({ mode: 'parallel' })
+
const tabs = [
{ id: 'rich', name: 'Rich Text' },
{ id: 'html', name: 'HTML' },
diff --git a/test/playwright/visual-regression/pages/homepage.spec.ts b/test/playwright/visual-regression/pages/homepage.spec.ts
index c927c7e97..eca2671d5 100644
--- a/test/playwright/visual-regression/pages/homepage.spec.ts
+++ b/test/playwright/visual-regression/pages/homepage.spec.ts
@@ -8,8 +8,10 @@ import {
languageDirections,
} from '~~/test/playwright/utils/navigation'
+test.describe.configure({ mode: 'parallel' })
+
/**
- * Remove the randomly-selected images from the homepage .
+ * Remove the randomly-selected images from the homepage.
*/
const deleteImageCarousel = async (page: Page) => {
const element = await page.$('[data-testid="image-carousel"]')
diff --git a/test/playwright/visual-regression/pages/pages.spec.ts b/test/playwright/visual-regression/pages/pages.spec.ts
index a1098a64b..783b90e3f 100644
--- a/test/playwright/visual-regression/pages/pages.spec.ts
+++ b/test/playwright/visual-regression/pages/pages.spec.ts
@@ -8,6 +8,8 @@ import {
languageDirections,
} from '~~/test/playwright/utils/navigation'
+test.describe.configure({ mode: 'parallel' })
+
const contentPages = [
'extension',
'about',
diff --git a/test/playwright/visual-regression/pages/sources.spec.ts b/test/playwright/visual-regression/pages/sources.spec.ts
index f6c0d58ef..7e6c97f6b 100644
--- a/test/playwright/visual-regression/pages/sources.spec.ts
+++ b/test/playwright/visual-regression/pages/sources.spec.ts
@@ -7,6 +7,8 @@ import {
languageDirections,
} from '~~/test/playwright/utils/navigation'
+test.describe.configure({ mode: 'parallel' })
+
test.describe('sources page snapshots', () => {
for (const dir of languageDirections) {
test.describe(dir, () => {
diff --git a/test/unit/specs/stores/provider.spec.js b/test/unit/specs/stores/provider.spec.js
index 6a05bf75a..496360964 100644
--- a/test/unit/specs/stores/provider.spec.js
+++ b/test/unit/specs/stores/provider.spec.js
@@ -1,5 +1,6 @@
import { createPinia, setActivePinia } from 'pinia'
+import { warn } from '~/utils/console'
import { AUDIO, IMAGE, supportedMediaTypes } from '~/constants/media'
import { useSearchStore } from '~/stores/search'
import { useProviderStore } from '~/stores/provider'
@@ -14,6 +15,8 @@ jest.mock('@nuxtjs/composition-api', () => ({
...jest.requireActual('@nuxtjs/composition-api'),
ssrRef: (v) => jest.fn(v),
}))
+jest.mock('~/utils/console', () => ({ warn: jest.fn(), log: jest.fn() }))
+
process.env.providerUpdateFrequency = '0'
const mockData = [
@@ -68,6 +71,10 @@ describe('Provider Store', () => {
providerServices.audio.getProviderStats.mockClear()
providerServices.image.getProviderStats.mockClear()
})
+ afterAll(() => {
+ warn.mockReset()
+ })
+
it('sets the default state', () => {
expect(providerStore.providers).toEqual({
[AUDIO]: [],