Skip to content

Commit be7b317

Browse files
fix: create temporary environment for publish tests instead of skipping
The § 3.4 publish tests were pending because the fresh dynamic stack has no environments (they're only created by Phase 5 environment tests). Fix: before() now creates a throw-away environment when none is found, and after() deletes it. Same self-contained pattern used by AM org stack. Priority order: 1. Use testData.environments.development.name if Phase 5 already ran 2. Query for any existing environment 3. Create a temporary environment (scan-publish-env-XXXXX) Verified locally: 32 passing, 0 pending, 0 failing
1 parent a9eafb8 commit be7b317

1 file changed

Lines changed: 27 additions & 2 deletions

File tree

test/sanity-check/api/assetScanStatus-test.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,7 @@ describe('Asset Scan Status – Publish Is Always Async (§ 3.4)', () => {
498498
let stack
499499
let publishAssetUid
500500
let publishEnvironment
501+
let createdEnvironmentName = null // track if we created it so we can delete it
501502

502503
before(function () {
503504
const apiKey = process.env.API_KEY
@@ -507,17 +508,38 @@ describe('Asset Scan Status – Publish Is Always Async (§ 3.4)', () => {
507508

508509
before(async function () {
509510
this.timeout(60000)
510-
// Get environment from testData
511+
512+
// Prefer an environment already created by prior test phases
511513
publishEnvironment = (testData.environments && testData.environments.development)
512514
? testData.environments.development.name
513515
: null
516+
517+
// Try querying for an existing one
514518
if (!publishEnvironment) {
515519
try {
516520
const envResp = await stack.environment().query().find()
517521
if (envResp.items && envResp.items.length > 0) {
518522
publishEnvironment = envResp.items[0].name
519523
}
520-
} catch (e) { /* skip if no environment */ }
524+
} catch (e) { /* ignore */ }
525+
}
526+
527+
// Nothing found — create a temporary environment for this test
528+
if (!publishEnvironment) {
529+
try {
530+
const envName = `scan-publish-env-${Math.random().toString(36).substring(2, 7)}`
531+
await stack.environment().create({
532+
environment: {
533+
name: envName,
534+
urls: [{ locale: 'en-us', url: 'http://localhost' }]
535+
}
536+
})
537+
publishEnvironment = envName
538+
createdEnvironmentName = envName
539+
console.log(` [scan-test] Created temporary publish environment: ${envName}`)
540+
} catch (e) {
541+
console.log(' [scan-test] Could not create environment:', e.errorMessage || e.message)
542+
}
521543
}
522544

523545
// Upload a fresh asset for publish tests
@@ -537,6 +559,9 @@ describe('Asset Scan Status – Publish Is Always Async (§ 3.4)', () => {
537559
if (publishAssetUid) {
538560
try { await stack.asset(publishAssetUid).delete() } catch (e) { /* ignore */ }
539561
}
562+
if (createdEnvironmentName) {
563+
try { await stack.environment(createdEnvironmentName).delete() } catch (e) { /* ignore */ }
564+
}
540565
})
541566

542567
it('should return success notice on publish regardless of scan status (async validation)', async function () {

0 commit comments

Comments
 (0)