Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion GEMINI.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ To test framework changes against a real Cedar project:
- **Code Style:**
- **Linting:** ESLint (`eslint.config.mjs`).
- **Formatting:** Prettier.
- **TypeScript:** Never use `@ts-ignore`. Always prefer `@ts-expect-error` with a clear explanation for why it's needed.
- **TypeScript:** Never use `@ts-ignore`. Always prefer `@ts-expect-error` with a clear explanation for why it's needed. Avoid `any`. Use `unknown` or specific types whenever possible. If `any` is truly necessary, add a comment explaining why. `any` is more acceptable in test files than in implementation files. Avoid `as unknown as X`.
- **Comments:** Place comments on a separate line immediately above the affected code using `//`. Unless you're documenting the usage of a function or variable, in which case you should use JSDoc comments. Avoid in-line or end-of-line comments.
- **Constraints:** Yarn constraints ensure consistent dependency versions across the monorepo.
- **Testing:**
- Unit tests: Jest/Vitest. When running `vitest` directly, use `--run` to disable watch mode.
Expand Down
1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"scripts": {
"build": "tsx ./build.mts",
"build:pack": "yarn pack -o cedarjs-cli.tgz",
"build:types": "tsc --build --verbose ./tsconfig.build.json",
"build:watch": "nodemon --watch src --ext \"js,jsx,ts,tsx,template\" --ignore dist --exec \"yarn build && yarn fix:permissions\"",
"dev": "RWJS_CWD=../../__fixtures__/example-todo-main node dist/index.js",
"fix:permissions": "chmod +x dist/index.js dist/cfw.js",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import type FS from 'node:fs'

import { Listr } from 'listr2'
import { vi, afterEach, test, expect } from 'vitest'

import type * as ProjectConfig from '@cedarjs/project-config'

vi.mock('listr2')

// Make sure prerender doesn't get triggered
vi.mock('@cedarjs/project-config', async (importOriginal) => {
const originalProjectConfig = await importOriginal()
const originalProjectConfig = await importOriginal<typeof ProjectConfig>()
return {
...originalProjectConfig,
getPaths: () => {
Expand All @@ -23,14 +33,14 @@ vi.mock('@cedarjs/project-config', async (importOriginal) => {
}
})

vi.mock('node:fs', async () => {
const actualFs = await vi.importActual('node:fs')
vi.mock('node:fs', async (importOriginal) => {
const actualFs = await importOriginal<typeof FS>()

return {
default: {
...actualFs,
// Mock the existence of the Prisma config file
existsSync: (path) => {
existsSync: (path: string) => {
if (path === '/mocked/project/api/prisma.config.js') {
return true
}
Expand All @@ -41,12 +51,6 @@ vi.mock('node:fs', async () => {
}
})

import { Listr } from 'listr2'
import { vi, afterEach, test, expect } from 'vitest'

vi.mock('listr2')

// Make sure prerender doesn't get triggered
vi.mock('execa', () => ({
default: vi.fn((cmd, params) => ({
cmd,
Expand All @@ -62,7 +66,8 @@ afterEach(() => {

test('the build tasks are in the correct sequence', async () => {
await handler({})
expect(Listr.mock.calls[0][0].map((x) => x.title)).toMatchInlineSnapshot(`
const callArgs = vi.mocked(Listr).mock.calls[0][0] as { title: string }[]
expect(callArgs.map((x) => x.title)).toMatchInlineSnapshot(`
[
"Generating Prisma Client...",
"Verifying graphql schema...",
Expand All @@ -80,7 +85,8 @@ test('Should run prerender for web', async () => {
const consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => {})

await handler({ side: ['web'], prerender: true })
expect(Listr.mock.calls[0][0].map((x) => x.title)).toMatchInlineSnapshot(`
const callArgs = vi.mocked(Listr).mock.calls[0][0] as { title: string }[]
expect(callArgs.map((x) => x.title)).toMatchInlineSnapshot(`
[
"Building Web...",
]
Expand Down
1 change: 0 additions & 1 deletion packages/cli/src/commands/__tests__/exec.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { vi, afterEach, beforeEach, describe, it, expect } from 'vitest'
// @ts-expect-error - No types for .js files
import { runScriptFunction } from '../../lib/exec.js'
import '../../lib/mockTelemetry'
// @ts-expect-error - No types for .js files
import { handler } from '../execHandler.js'

vi.mock('@cedarjs/babel-config', () => ({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import fs from 'node:fs'

import execa from 'execa'
import { vi, beforeEach, afterEach, test, expect } from 'vitest'

import type * as ProjectConfig from '@cedarjs/project-config'

vi.mock('@cedarjs/project-config', async (importOriginal) => {
const originalProjectConfig = await importOriginal()
const originalProjectConfig = await importOriginal<typeof ProjectConfig>()
return {
...originalProjectConfig,
getPaths: () => {
Expand All @@ -26,11 +33,6 @@ vi.mock('execa', () => ({
},
}))

import fs from 'node:fs'

import execa from 'execa'
import { vi, beforeEach, afterEach, test, expect } from 'vitest'

import { handler } from '../prisma.js'

beforeEach(() => {
Expand All @@ -40,8 +42,8 @@ beforeEach(() => {
})

afterEach(() => {
console.info.mockRestore()
console.log.mockRestore()
vi.mocked(console).info.mockRestore()
vi.mocked(console).log.mockRestore()
})

test('the prisma command handles spaces', async () => {
Expand All @@ -53,7 +55,7 @@ test('the prisma command handles spaces', async () => {
n: 'add bazingas',
})

expect(execa.sync.mock.calls[0][1]).toEqual([
expect(vi.mocked(execa.sync).mock.calls[0][1]).toEqual([
'migrate',
'dev',
'-n',
Expand Down
145 changes: 0 additions & 145 deletions packages/cli/src/commands/__tests__/test.test.js

This file was deleted.

Loading
Loading