Skip to content

Commit 148b32b

Browse files
committed
test updates, env var cleanup
1 parent 25a1483 commit 148b32b

File tree

10 files changed

+77
-40
lines changed

10 files changed

+77
-40
lines changed

.env.sample

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
GITHUB_TOKEN=xxx
22
ADOBE_ID=xxx
3+
UMAMI_SCRIPT_URL=xxx
4+
UMAMI_WEBSITE_ID=xxx
5+
36
PUBLIC_MAPBOX_ACCESS_TOKEN=xxx
4-
PUBLIC_UMAMI_SCRIPT_URL=xxx
5-
PUBLIC_UMAMI_WEBSITE_ID=xxx
6-
PUBLIC_INFURA_ID=xxx
77
PUBLIC_WALLETCONNECT_ID="xxx"
88
PUBLIC_WEB3_API_URL="xxx"

.github/workflows/ci.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ on:
1111
env:
1212
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1313
ADOBE_ID: ${{ secrets.ADOBE_ID }}
14+
UMAMI_SCRIPT_URL: ${{ secrets.UMAMI_SCRIPT_URL }}
15+
UMAMI_WEBSITE_ID: ${{ secrets.UMAMI_WEBSITE_ID }}
1416
PUBLIC_MAPBOX_ACCESS_TOKEN: ${{ secrets.GATSBY_MAPBOX_ACCESS_TOKEN }}
15-
PUBLIC_UMAMI_SCRIPT_URL: ${{ secrets.GATSBY_UMAMI_SCRIPT_URL }}
16-
PUBLIC_UMAMI_WEBSITE_ID: ${{ secrets.GATSBY_UMAMI_WEBSITE_ID }}
17-
PUBLIC_INFURA_ID: ${{ secrets.GATSBY_INFURA_ID }}
1817
PUBLIC_WALLETCONNECT_ID: ${{ secrets.GATSBY_WALLETCONNECT_ID }}
1918
PUBLIC_WEB3_API_URL: ${{ secrets.PUBLIC_WEB3_API_URL }}
2019

AGENTS.md

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,6 @@ you are a senior programmer with expert-level experience in typescript, bun, bio
3030
- If you do not know or are not sure about the answer, say so, instead of guessing.
3131
- If you're unsure, ask me for help or more input.
3232

33-
## Dependencies and libraries
34-
35-
- when adding new dependencies always use the latest version for each dependency
36-
- prefer using least amount of dependencies for features suggested
37-
- prioritize small, minimal, focused, and well-maintained libraries when introducing new dependencies
38-
3933
## Error Handling and Validation
4034

4135
- Prioritize error handling and edge cases:
@@ -85,14 +79,3 @@ you are a senior programmer with expert-level experience in typescript, bun, bio
8579
- Use an object to return results.
8680
- Declare necessary types for input arguments and output.
8781
- Use a single level of abstraction.
88-
89-
### Testing
90-
91-
- Follow the Arrange-Act-Assert convention for tests.
92-
- Name test variables clearly.
93-
- Follow the convention: inputX, mockX, actualX, expectedX, etc.
94-
- Write unit tests for each public function.
95-
- Use test doubles to simulate dependencies.
96-
- Except for third-party dependencies that are not expensive to execute.
97-
- Write acceptance tests for each module.
98-
- Follow the Given-When-Then convention.

package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
"license": "MIT",
88
"type": "module",
99
"scripts": {
10-
"dev": "bun run prebuild && astro dev --config 'src/config/astro.config.ts'",
11-
"build": "astro build --config 'src/config/astro.config.ts'",
12-
"preview": "astro preview",
13-
"typecheck:astro": "astro check",
10+
"dev": "bun run prebuild && bun run --bun astro dev --config 'src/config/astro.config.ts'",
11+
"build": "bun run --bun astro build --config 'src/config/astro.config.ts'",
12+
"preview": "bun run --bun astro preview",
13+
"typecheck:astro": "bun run --bun astro check",
1414
"typecheck:tsc": "tsc --noEmit --pretty",
1515
"typecheck": "bun run typecheck:astro && bun run typecheck:tsc",
1616
"prebuild": "run-p --silent --continue-on-error create:symlinks move:downloads",
@@ -25,7 +25,6 @@
2525
"format": "run-p --silent format:biome format:md",
2626
"deploy:s3": "./scripts/deploy-s3.sh",
2727
"new": "bun run scripts/new/index.ts",
28-
"create:redirects": "bun run scripts/redirect-from.ts",
2928
"create:symlinks": "./scripts/create-symlinks.sh",
3029
"move:downloads": "bun run scripts/move-downloads.ts",
3130
"iptc:add": "bun run scripts/iptc-add.ts"

scripts/move-downloads.test.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import fs from 'node:fs/promises'
22
import path from 'node:path'
33
import chalk from 'chalk'
4+
import { globby } from 'globby'
45
import type { Ora } from 'ora'
56
import { expect, test, vi } from 'vitest'
67
import { copyZipFiles } from './move-downloads'
@@ -9,6 +10,17 @@ vi.mock('globby', () => ({
910
globby: vi.fn().mockResolvedValue(['file1.zip', 'file2.zip'])
1011
}))
1112

13+
vi.mock('ora', () => ({
14+
default: vi.fn(() => ({
15+
start: () => ({
16+
text: '',
17+
start: vi.fn(),
18+
succeed: vi.fn(),
19+
fail: vi.fn()
20+
})
21+
}))
22+
}))
23+
1224
test('copyZipFiles should copy zip files', async () => {
1325
// Create temporary directories and files
1426
const sourceDir = path.join(__dirname, 'tmp_source')
@@ -17,6 +29,11 @@ test('copyZipFiles should copy zip files', async () => {
1729
await fs.mkdir(destDir, { recursive: true })
1830
await fs.writeFile(path.join(sourceDir, 'file1.zip'), 'content1')
1931
await fs.writeFile(path.join(sourceDir, 'file2.zip'), 'content2')
32+
// Add an existing file to destDir to test removal
33+
await fs.writeFile(path.join(destDir, 'old.zip'), 'old content')
34+
// Add a subdirectory with a file to test recursive removal
35+
await fs.mkdir(path.join(destDir, 'subdir'), { recursive: true })
36+
await fs.writeFile(path.join(destDir, 'subdir', 'old2.zip'), 'old content2')
2037

2138
const mockOra = {
2239
text: '',
@@ -31,6 +48,10 @@ test('copyZipFiles should copy zip files', async () => {
3148
const file2 = await fs.readFile(path.join(destDir, 'file2.zip'), 'utf-8')
3249
expect(file1).toBe('content1')
3350
expect(file2).toBe('content2')
51+
// Check that old file was removed
52+
await expect(fs.access(path.join(destDir, 'old.zip'))).rejects.toThrow()
53+
// Check that subdirectory was removed
54+
await expect(fs.access(path.join(destDir, 'subdir'))).rejects.toThrow()
3455

3556
expect(mockOra.succeed).toHaveBeenCalledWith(
3657
`${chalk.bold('[move-downloads]')} Copied 2 .zip files to ${destDir}`
@@ -40,3 +61,34 @@ test('copyZipFiles should copy zip files', async () => {
4061
await fs.rm(sourceDir, { recursive: true, force: true })
4162
await fs.rm(destDir, { recursive: true, force: true })
4263
})
64+
65+
test('copyZipFiles should create destination folder if it does not exist', async () => {
66+
// Create temporary directories and files
67+
const sourceDir = path.join(__dirname, 'tmp_source2')
68+
const destDir = path.join(__dirname, 'tmp_dest2')
69+
await fs.mkdir(sourceDir, { recursive: true })
70+
await fs.writeFile(path.join(sourceDir, 'file1.zip'), 'content1')
71+
72+
const globbyMock = vi.mocked(globby)
73+
globbyMock.mockResolvedValue(['file1.zip'])
74+
75+
const mockOra = {
76+
text: '',
77+
start: vi.fn(),
78+
succeed: vi.fn(),
79+
fail: vi.fn()
80+
}
81+
82+
await copyZipFiles(sourceDir, destDir, mockOra as unknown as Ora)
83+
84+
const file1 = await fs.readFile(path.join(destDir, 'file1.zip'), 'utf-8')
85+
expect(file1).toBe('content1')
86+
87+
expect(mockOra.succeed).toHaveBeenCalledWith(
88+
`${chalk.bold('[move-downloads]')} Copied 1 .zip files to ${destDir}`
89+
)
90+
91+
// Cleanup
92+
await fs.rm(sourceDir, { recursive: true, force: true })
93+
await fs.rm(destDir, { recursive: true, force: true })
94+
})

scripts/move-downloads.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function removeFolderContents(folderPath: string) {
2222
const filePath = path.join(folderPath, file)
2323
if (fs.lstatSync(filePath).isDirectory()) {
2424
removeFolderContents(filePath)
25-
fs.rmSync(filePath)
25+
fs.rmdirSync(filePath)
2626
} else {
2727
fs.unlinkSync(filePath)
2828
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { render } from '@testing-library/react'
2+
import { test } from 'vitest'
3+
import { Loader } from './Loader'
4+
5+
test('Loader', async () => {
6+
render(<Loader />)
7+
})

src/env.d.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ declare module '*.astro' {
77
declare global {
88
interface ImportMetaEnv {
99
readonly PUBLIC_MAPBOX_ACCESS_TOKEN?: string
10-
readonly PUBLIC_UMAMI_SCRIPT_URL?: string
11-
readonly PUBLIC_UMAMI_WEBSITE_ID?: string
12-
readonly PUBLIC_INFURA_ID?: string
1310
readonly PUBLIC_WALLETCONNECT_ID?: string
1411
readonly PUBLIC_WEB3_API_URL?: string
1512
}

src/lib/umami/umami.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { getUmamiConfig } from '.'
44
test('should throw an error if Umami environment variables are missing in production', () => {
55
const mockEnv = {
66
PROD: true,
7-
PUBLIC_UMAMI_SCRIPT_URL: '',
8-
PUBLIC_UMAMI_WEBSITE_ID: ''
7+
UMAMI_SCRIPT_URL: '',
8+
UMAMI_WEBSITE_ID: ''
99
} as any
1010

1111
expect(() => getUmamiConfig(mockEnv)).toThrow(
@@ -17,8 +17,8 @@ test('should not throw an error if Umami environment variables are present in pr
1717
// Mock production environment with Umami variables
1818
const mockEnv = {
1919
PROD: true,
20-
PUBLIC_UMAMI_SCRIPT_URL: 'https://example.com/umami.js',
21-
PUBLIC_UMAMI_WEBSITE_ID: 'your-website-id'
20+
UMAMI_SCRIPT_URL: 'https://example.com/umami.js',
21+
UMAMI_WEBSITE_ID: 'your-website-id'
2222
} as any
2323

2424
expect(() => getUmamiConfig(mockEnv)).not.toThrow()
@@ -28,8 +28,8 @@ test('should not throw an error in non-production environments', () => {
2828
// Mock non-production environment
2929
const mockEnv = {
3030
PROD: false,
31-
PUBLIC_UMAMI_SCRIPT_URL: '',
32-
PUBLIC_UMAMI_WEBSITE_ID: ''
31+
UMAMI_SCRIPT_URL: '',
32+
UMAMI_WEBSITE_ID: ''
3333
} as any
3434

3535
expect(() => getUmamiConfig(mockEnv)).not.toThrow()

src/lib/umami/umami.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ export function getUmamiConfig(env = import.meta.env): {
22
scriptUrl: string
33
websiteId: string
44
} {
5-
const scriptUrl = env.PUBLIC_UMAMI_SCRIPT_URL
6-
const websiteId = env.PUBLIC_UMAMI_WEBSITE_ID
5+
const scriptUrl = env.UMAMI_SCRIPT_URL
6+
const websiteId = env.UMAMI_WEBSITE_ID
77
const isProduction = env.PROD
88

99
if (isProduction && (!scriptUrl || !websiteId)) {

0 commit comments

Comments
 (0)