flora is a fast and secure runtime that lets you write discord bots for your servers, with a rich TypeScript SDK, without worrying about running infrastructure. [mirror]
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at trunk 94 lines 3.1 kB view raw
1import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises' 2import { tmpdir } from 'node:os' 3import path from 'node:path' 4import { afterEach, describe, expect, it } from 'vitest' 5 6import { bundleDeploymentSource } from '../src/lib/deploy_bundle' 7 8async function createProjectFixture(): Promise<string> { 9 const root = await mkdtemp(path.join(tmpdir(), 'flora-cli-bundle-')) 10 11 await mkdir(path.join(root, 'src'), { recursive: true }) 12 await mkdir(path.join(root, 'node_modules', 'tiny-dep'), { recursive: true }) 13 14 await writeFile( 15 path.join(root, 'src', 'main.ts'), 16 [ 17 "import { localValue } from './util'", 18 "import dependencyValue from 'tiny-dep'", 19 'export const value = `${localValue}${dependencyValue}`' 20 ].join('\n') 21 ) 22 await writeFile(path.join(root, 'src', 'util.ts'), "export const localValue = 'local-'\n") 23 await writeFile( 24 path.join(root, 'node_modules', 'tiny-dep', 'package.json'), 25 JSON.stringify({ name: 'tiny-dep', version: '1.0.0', type: 'module', main: 'index.js' }) 26 ) 27 await writeFile(path.join(root, 'node_modules', 'tiny-dep', 'index.js'), "export default 'dep'\n") 28 29 return root 30} 31 32describe('bundleDeploymentSource', () => { 33 const roots: string[] = [] 34 35 afterEach(async () => { 36 await Promise.all(roots.map((root) => rm(root, { recursive: true, force: true }))) 37 roots.length = 0 38 }) 39 40 it('bundles multi-file entry and node_modules by default', async () => { 41 const root = await createProjectFixture() 42 roots.push(root) 43 44 const result = await bundleDeploymentSource({ cwd: root }) 45 46 expect(result.entry).toBe('src/main.ts') 47 expect(result.bundle).toContain('local-') 48 expect(result.bundle).toContain('dep') 49 expect(result.bundle).not.toMatch(/from ['"]tiny-dep['"]/) 50 }) 51 52 it('supports sourcemap none mode', async () => { 53 const root = await createProjectFixture() 54 roots.push(root) 55 56 const result = await bundleDeploymentSource({ cwd: root, sourcemap: 'none' }) 57 58 expect(result.sourceMap).toBeUndefined() 59 expect(result.bundle).not.toContain('sourceMappingURL=') 60 }) 61 62 it('supports sourcemap inline mode', async () => { 63 const root = await createProjectFixture() 64 roots.push(root) 65 66 const result = await bundleDeploymentSource({ cwd: root, sourcemap: 'inline' }) 67 68 expect(result.sourceMap).toBeUndefined() 69 expect(result.bundle).toContain('sourceMappingURL=data:') 70 }) 71 72 it('supports sourcemap external mode', async () => { 73 const root = await createProjectFixture() 74 roots.push(root) 75 76 const result = await bundleDeploymentSource({ cwd: root, sourcemap: 'external' }) 77 78 expect(result.sourceMap).toBeDefined() 79 expect(result.sourceMap?.path).toMatch(/\.map$/) 80 expect(result.sourceMap?.contents).toContain('"version"') 81 }) 82 83 it('keeps explicit external imports in output', async () => { 84 const root = await createProjectFixture() 85 roots.push(root) 86 87 const result = await bundleDeploymentSource({ 88 cwd: root, 89 external: ['tiny-dep'] 90 }) 91 92 expect(result.bundle).toMatch(/from ['"]tiny-dep['"]/) 93 }) 94})