import { readFileSync } from 'fs'; import Path from 'path'; import { describe, expect, test } from 'vitest'; import { createQRCode } from './create-qrcode'; describe('#createQRCode', () => { test('with { url }', () => { const testOutput = getTestSvgOutput('./fixtures/with-url.svg'); const svg = createQRCode({ url: 'https://shared.coastapp.com/r/d634c3d2-4708-42f3-8dbe-a987696a8bb3', }); expect(svg).toBe(testOutput); }); test('with { url, width: 400 }', () => { const testOutput = getTestSvgOutput('./fixtures/with-url-width-400.svg'); const svg = createQRCode({ url: 'https://shared.coastapp.com/r/d634c3d2-4708-42f3-8dbe-a987696a8bb3', width: 400, }); expect(svg).toBe(testOutput); }); test('with { url, width: 600, showBorder: true }', () => { const testOutput = getTestSvgOutput('./fixtures/with-url-width-600-border-true.svg'); const svg = createQRCode({ url: 'https://shared.coastapp.com/r/d634c3d2-4708-42f3-8dbe-a987696a8bb3', width: 600, showBorder: true, }); expect(svg).toBe(testOutput); }); test('with { url, width: 600, showBorder: false, showLogo: false }', () => { const testOutput = getTestSvgOutput('./fixtures/with-url-width-600-border-false-logo-false.svg'); const svg = createQRCode({ url: 'https://shared.coastapp.com/r/d634c3d2-4708-42f3-8dbe-a987696a8bb3', width: 600, showBorder: false, showLogo: false, }); expect(svg).toBe(testOutput); }); test('with { url, width: 600, showBorder: true, showLogo: false }', () => { const testOutput = getTestSvgOutput('./fixtures/with-url-width-600-border-true-logo-false.svg'); const svg = createQRCode({ url: 'https://shared.coastapp.com/r/d634c3d2-4708-42f3-8dbe-a987696a8bb3', width: 600, showBorder: true, showLogo: false, }); expect(svg).toBe(testOutput); }); }); function getTestSvgOutput(path: string): string { return readFileSync(Path.resolve(__dirname, path), 'utf-8').trim(); }