-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import * as path from 'path' | ||
import { describe, expect, it, vi } from 'vitest' | ||
import { | ||
AFTER_CREATE, | ||
addAfterCreateHook, | ||
rewriteWranglerHook, | ||
} from './after-create' | ||
|
||
describe('addAfterCreateHook', () => { | ||
it('adds a hook to the AFTER_CREATE map', () => { | ||
const hook = () => {} | ||
addAfterCreateHook('test-template', hook) | ||
expect(AFTER_CREATE.get('test-template')).toEqual([hook]) | ||
}) | ||
}) | ||
|
||
describe('rewriteWranglerHook', () => { | ||
it('rewrites the wrangler.toml file with the project name', async () => { | ||
vi.mock('fs', () => { | ||
const wrangler = ` | ||
name = "%%PROJECT_NAME%%" | ||
type = "javascript" | ||
account_id = "test-account-id" | ||
workers_dev = true | ||
route = "" | ||
zone_id = "" | ||
`.trim() | ||
|
||
return { | ||
readFileSync: vi.fn().mockReturnValue(wrangler), | ||
writeFileSync: vi.fn(), | ||
} | ||
}) | ||
const { readFileSync, writeFileSync } = await import('fs') | ||
|
||
const projectName = 'test-project' | ||
const directoryPath = './tmp' | ||
const wranglerPath = path.join(directoryPath, 'wrangler.toml') | ||
const replaced = ` | ||
name = "${projectName}" | ||
type = "javascript" | ||
account_id = "test-account-id" | ||
workers_dev = true | ||
route = "" | ||
zone_id = "" | ||
`.trim() | ||
rewriteWranglerHook({ projectName, directoryPath }) | ||
expect(readFileSync).toHaveBeenCalledWith(wranglerPath, 'utf-8') | ||
expect(writeFileSync).toHaveBeenCalledWith(wranglerPath, replaced) | ||
}) | ||
}) |