Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Run ActiveJob in-process for the dashboard e2e server; add imports e2e

Damian Legawiecc899c13da07a
diff --git a/packages/dashboard/e2e/global-setup.ts b/packages/dashboard/e2e/global-setup.ts
index 0542af53c9..9128441106 100644
--- a/packages/dashboard/e2e/global-setup.ts
+++ b/packages/dashboard/e2e/global-setup.ts
@@ -26,14 +26,14 @@ import {
FIXTURE_PROMO_PRODUCT,
FIXTURE_PROMO_TAXON,
} from './helpers'
-import { CREDENTIALS_FILE, E2E_DIR, RAILS_PID_FILE } from './paths'
+import { ASYNC_JOBS_INITIALIZER, CREDENTIALS_FILE, E2E_DIR, RAILS_PID_FILE } from './paths'
const API_GEM_DIR = resolve(E2E_DIR, '../../../spree/api')
const PORT = process.env.E2E_RAILS_PORT || '3010'
// Mirrors `spec/dummy/config/database.yml`.
const TEST_SQLITE = resolve(API_GEM_DIR, 'spec/dummy/db/spree_test.sqlite3')
-const RAILS_ENV = { ...process.env, RAILS_ENV: 'test', PORT }
+const RAILS_ENV = { ...process.env, RAILS_ENV: 'test', PORT, DASHBOARD_E2E: '1' }
// Customer's last name is derived from the full name so the seeder and the
// matching `full_name` assertion in promotions.spec stay in sync.
@@ -136,6 +136,20 @@ let serverProcess: ChildProcess | null = null
export default async function globalSetup() {
rmIfExists(TEST_SQLITE)
+ // The dummy test env pins ActiveJob to the :test adapter (RSpec asserts on
+ // enqueues), but e2e flows like CSV import only progress when jobs actually
+ // run — execute them in-process for the e2e server only. Removed in
+ // global-teardown; the DASHBOARD_E2E guard keeps a leftover file inert for
+ // regular spec runs.
+ writeFileSync(
+ ASYNC_JOBS_INITIALIZER,
+ [
+ '# Written by packages/dashboard/e2e/global-setup.ts — safe to delete.',
+ "ActiveJob::Base.queue_adapter = :async if ENV['DASHBOARD_E2E'] == '1'",
+ '',
+ ].join('\n'),
+ )
+
// Pass the script via argv to sidestep shell quoting (the Ruby contains
// both single and double quotes).
const result = spawnSync('bundle', ['exec', 'spec/dummy/bin/rails', 'runner', BOOTSTRAP_RUBY], {
diff --git a/packages/dashboard/e2e/global-teardown.ts b/packages/dashboard/e2e/global-teardown.ts
index 6e59ee78bc..821829c414 100644
--- a/packages/dashboard/e2e/global-teardown.ts
+++ b/packages/dashboard/e2e/global-teardown.ts
@@ -1,7 +1,13 @@
import { readFileSync, unlinkSync } from 'node:fs'
-import { RAILS_PID_FILE } from './paths'
+import { ASYNC_JOBS_INITIALIZER, RAILS_PID_FILE } from './paths'
export default async function globalTeardown() {
+ try {
+ unlinkSync(ASYNC_JOBS_INITIALIZER)
+ } catch (e) {
+ if ((e as NodeJS.ErrnoException).code !== 'ENOENT') throw e
+ }
+
let pid: number
try {
pid = Number.parseInt(readFileSync(RAILS_PID_FILE, 'utf-8'), 10)
diff --git a/packages/dashboard/e2e/imports.spec.ts b/packages/dashboard/e2e/imports.spec.ts
new file mode 100644
index 0000000000..23b8c4a27d
--- /dev/null
+++ b/packages/dashboard/e2e/imports.spec.ts
@@ -0,0 +1,109 @@
+import { expect, type Page, test } from '@playwright/test'
+import { login } from './helpers'
+
+const PRODUCTS_PATH = (storeId: string) => `/${storeId}/products`
+
+function csvFile(rows: string[]) {
+ return {
+ name: `e2e-import-${Date.now()}.csv`,
+ mimeType: 'text/csv',
+ buffer: Buffer.from(`${rows.join('\n')}\n`),
+ }
+}
+
+async function openImportDialog(page: Page, storeId: string) {
+ await page.goto(PRODUCTS_PATH(storeId))
+ await page.getByRole('button', { name: /^import$/i }).click()
+ await expect(page.getByRole('heading', { name: /import from csv/i })).toBeVisible()
+}
+
+test.describe('csv import', () => {
+ test('imports products through the upload → mapping → progress → results wizard', async ({
+ page,
+ }) => {
+ // Upload + background row processing legitimately take a while.
+ test.setTimeout(180_000)
+
+ const creds = await login(page)
+ const suffix = Date.now()
+ const goodName = `E2E Imported Product ${suffix}`
+
+ await openImportDialog(page, creds.store_id)
+
+ // Row 2 has no name and no price — guaranteed row-level failure that
+ // feeds the failed-rows report without failing the whole import.
+ await page
+ .getByRole('dialog')
+ .locator('input[type="file"]')
+ .setInputFiles(
+ csvFile([
+ 'slug,sku,name,price',
+ `e2e-import-ok-${suffix},E2E-IMP-OK-${suffix},${goodName},10.00`,
+ `e2e-import-bad-${suffix},E2E-IMP-BAD-${suffix},,`,
+ ]),
+ )
+ await page.getByRole('button', { name: /upload & continue/i }).click()
+
+ // Mapping step — canonical headers auto-assign, so required fields are
+ // already satisfied and the sample value from the file is shown.
+ // (CardTitle renders a div, so match by text rather than heading role.)
+ await expect(page.getByText('Map columns')).toBeVisible({ timeout: 15_000 })
+ await expect(page.getByText(`e2e-import-ok-${suffix}`)).toBeVisible()
+
+ await page.getByRole('button', { name: /start import/i }).click()
+
+ // Progress → results, driven entirely by the 2s poll.
+ await expect(page.getByText(/import completed/i)).toBeVisible({ timeout: 120_000 })
+ await expect(page.getByText(/1 failed/i).first()).toBeVisible()
+
+ // Failure report: the broken row is listed and its raw data is inspectable.
+ // exact: true — "Retry failed rows (1)" would otherwise also match.
+ await expect(page.getByText('Failed rows', { exact: true })).toBeVisible()
+ await page
+ .getByRole('button', { name: /view row data/i })
+ .first()
+ .click()
+ await expect(page.getByText(`E2E-IMP-BAD-${suffix}`)).toBeVisible()
+
+ // Retry re-runs the still-broken row: the wizard flips back into the
+ // processing state (retry-pass copy) and completes again with the
+ // failure intact.
+ await page.getByRole('button', { name: /retry failed rows/i }).click()
+ await expect(page.getByText(/retrying failed rows/i)).toBeVisible({ timeout: 15_000 })
+ await expect(page.getByText(/import completed/i)).toBeVisible({ timeout: 120_000 })
+ await expect(page.getByRole('button', { name: /retry failed rows/i })).toBeVisible({
+ timeout: 15_000,
+ })
+
+ // The good row became a real product.
+ await page.goto(PRODUCTS_PATH(creds.store_id))
+ await expect(page.getByText(goodName)).toBeVisible({ timeout: 15_000 })
+ })
+
+ test('blocks starting until required fields are mapped', async ({ page }) => {
+ const creds = await login(page)
+ const suffix = Date.now()
+
+ await openImportDialog(page, creds.store_id)
+
+ // No `price` column at all — a required schema field stays unmapped.
+ await page
+ .getByRole('dialog')
+ .locator('input[type="file"]')
+ .setInputFiles(
+ csvFile([
+ 'slug,sku,name',
+ `e2e-import-nomap-${suffix},E2E-IMP-NM-${suffix},No Price ${suffix}`,
+ ]),
+ )
+ await page.getByRole('button', { name: /upload & continue/i }).click()
+
+ await expect(page.getByText('Map columns')).toBeVisible({ timeout: 15_000 })
+ await expect(page.getByRole('button', { name: /start import/i })).toBeDisabled()
+ await expect(page.getByText(/map the required fields to continue/i)).toBeVisible()
+
+ // The import history lists the abandoned mapping-state import too.
+ await page.goto(`/${creds.store_id}/settings/imports`)
+ await expect(page.getByText(/^IM\d+/).first()).toBeVisible({ timeout: 15_000 })
+ })
+})
diff --git a/packages/dashboard/e2e/paths.ts b/packages/dashboard/e2e/paths.ts
index 4893832429..544bb4a8d9 100644
--- a/packages/dashboard/e2e/paths.ts
+++ b/packages/dashboard/e2e/paths.ts
@@ -4,3 +4,9 @@ import { fileURLToPath } from 'node:url'
export const E2E_DIR = dirname(fileURLToPath(import.meta.url))
export const CREDENTIALS_FILE = resolve(E2E_DIR, '.credentials.json')
export const RAILS_PID_FILE = resolve(E2E_DIR, '.rails.pid')
+// Written by global-setup into the (generated, gitignored) dummy app and
+// removed in global-teardown — see the comment inside the file it writes.
+export const ASYNC_JOBS_INITIALIZER = resolve(
+ E2E_DIR,
+ '../../../spree/api/spec/dummy/config/initializers/zz_dashboard_e2e_async_jobs.rb',
+)