Skip to content

Commit

Permalink
test: create adapter.test.ts (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
yusukebe authored Sep 15, 2024
1 parent fc15f71 commit 4204567
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 79 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,49 @@
import { build } from 'vite'
import { existsSync, readFileSync, rmSync } from 'node:fs'
import bunBuildPlugin from '../src/adapter/bun'
import cloudflarePagesPlugin from '../src/adapter/cloudflare-pages'
import denoBuildPlugin from '../src/adapter/deno'

describe('Build Plugin with Bun Adapter', () => {
const testDir = './test/mocks/app-static-files'
const entry = './src/server.ts'

afterEach(() => {
rmSync(`${testDir}/dist`, { recursive: true, force: true })
})

it('Should build the project correctly with the plugin', async () => {
const outputFile = `${testDir}/dist/index.js`

await build({
root: testDir,
plugins: [
bunBuildPlugin({
entry,
}),
],
})

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

const output = readFileSync(outputFile, 'utf-8')
expect(output).toContain('Hello World')
expect(output).toContain('use("/foo.txt"')
expect(output).toContain('use("/js/*"')

const outputFooTxt = readFileSync(`${testDir}/dist/foo.txt`, 'utf-8')
expect(outputFooTxt).toContain('foo')

const outputJsClientJs = readFileSync(`${testDir}/dist/js/client.js`, 'utf-8')
// eslint-disable-next-line quotes
expect(outputJsClientJs).toContain("console.log('foo')")
})
})

describe('Build Plugin with Cloudflare Pages Adapter', () => {
const testDir = './test/mocks/app-static-files'

afterAll(() => {
afterEach(() => {
rmSync(`${testDir}/dist`, { recursive: true, force: true })
})

Expand Down Expand Up @@ -83,3 +121,39 @@ describe('Build Plugin with Cloudflare Pages Adapter', () => {
expect(routes).toContain('{"version":1,"include":["/"],"exclude":["/customRoute"]}')
})
})

describe('Build Plugin with Deno Adapter', () => {
const testDir = './test/mocks/app-static-files'
const entry = './src/server.ts'

afterEach(() => {
rmSync(`${testDir}/dist`, { recursive: true, force: true })
})

it('Should build the project correctly with the plugin', async () => {
const outputFile = `${testDir}/dist/index.js`

await build({
root: testDir,
plugins: [
denoBuildPlugin({
entry,
}),
],
})

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

const output = readFileSync(outputFile, 'utf-8')
expect(output).toContain('Hello World')
expect(output).toContain('use("/foo.txt"')
expect(output).toContain('use("/js/*"')

const outputFooTxt = readFileSync(`${testDir}/dist/foo.txt`, 'utf-8')
expect(outputFooTxt).toContain('foo')

const outputJsClientJs = readFileSync(`${testDir}/dist/js/client.js`, 'utf-8')
// eslint-disable-next-line quotes
expect(outputJsClientJs).toContain("console.log('foo')")
})
})
39 changes: 0 additions & 39 deletions packages/build/test/bun.test.ts

This file was deleted.

39 changes: 0 additions & 39 deletions packages/build/test/deno.test.ts

This file was deleted.

0 comments on commit 4204567

Please sign in to comment.