create-dynamic-app
Version:
CLI tool to generate sample applications using Dynamic's web3 authentication
52 lines (43 loc) • 1.42 kB
text/typescript
import { describe, it, expect, beforeEach, afterEach } from "bun:test"
import { promises as fs } from "node:fs"
import path from "node:path"
describe("Asset Downloads", () => {
const TEST_DIR = path.join(process.cwd(), "test-output")
beforeEach(async () => {
// Clean up any existing test directory
try {
await fs.rm(TEST_DIR, { recursive: true, force: true })
} catch (error) {
console.error("Error during cleanup:", error)
}
await fs.mkdir(TEST_DIR, { recursive: true })
})
afterEach(async () => {
try {
await fs.rm(TEST_DIR, { recursive: true, force: true })
} catch (error) {
console.error("Error during cleanup:", error)
}
})
it("should skip asset downloads in CI environment", async () => {
// Set CI environment variable
const originalCI = process.env.CI
process.env.CI = "true"
// Create a mock copyAssets function
const mockCopyAssets = async (baseDir: string): Promise<void> => {
if (process.env.CI === "true") {
console.log("Skipping asset downloads in CI environment")
return
}
throw new Error("Should not reach this point in CI environment")
}
// Run the test
await mockCopyAssets(TEST_DIR)
// Verify no files were created
const publicDir = path.join(TEST_DIR, "public")
const files = await fs.readdir(publicDir).catch(() => [])
expect(files).toHaveLength(0)
// Restore original CI value
process.env.CI = originalCI
})
})