Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
yusukebe committed Jan 23, 2024
1 parent fca6096 commit 2f97a9c
Show file tree
Hide file tree
Showing 4 changed files with 367 additions and 11 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/ci-cloudfare-pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: ci-cloudflare-pages
on:
push:
branches: [main]
paths:
- 'packages/cloudflare-pages/**'
pull_request:
branches: ['*']
paths:
- 'packages/cloudflare-pages/**'

jobs:
ci:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./packages/cloudflare-pages
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20.x
- uses: pnpm/action-setup@v2
with:
version: 8
- run: yarn install
- run: yarn build
- run: yarn test
6 changes: 4 additions & 2 deletions packages/cloudflare-pages/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"module": "dist/index.js",
"type": "module",
"scripts": {
"test": "vitest --run",
"build": "rimraf dist && tsup && publint",
"watch": "tsup --watch",
"prerelease": "yarn build",
Expand Down Expand Up @@ -44,12 +45,13 @@
"publint": "^0.1.12",
"rimraf": "^5.0.1",
"tsup": "^7.2.0",
"vite": "^5.0.12"
"vite": "^5.0.12",
"vitest": "^1.2.1"
},
"peerDependencies": {
"hono": ">=3.11.7"
},
"engines": {
"node": ">=18.14.1"
}
}
}
37 changes: 37 additions & 0 deletions packages/cloudflare-pages/test/cloudflare-pages.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import * as fs from 'node:fs'
import path from 'path'
import { build } from 'vite'
import { describe, it, expect, beforeAll, afterAll } from 'vitest'
import cloudflarePagesPlugin from '../src/index'

describe('cloudflarePagesPlugin', () => {
const testDir = './test-project'
const entryFile = `${testDir}/app/server.ts`
const outputFile = `${testDir}/dist/_worker.js`

beforeAll(() => {
fs.mkdirSync(path.dirname(entryFile), { recursive: true })
fs.writeFileSync(entryFile, 'export default { fetch: () => new Response("Hello World") }')
})

afterAll(() => {
fs.rmSync(testDir, { recursive: true, force: true })
})

it('Should build the project correctly with the plugin', async () => {
expect(fs.existsSync(entryFile)).toBe(true)

await build({
root: testDir,
plugins: [cloudflarePagesPlugin()],
build: {
emptyOutDir: true,
},
})

expect(fs.existsSync(outputFile)).toBe(true)

const output = fs.readFileSync(outputFile, 'utf-8')
expect(output).toContain('Hello World')
})
})
Loading

0 comments on commit 2f97a9c

Please sign in to comment.