Skip to content

Built for people who want to own their automations. Join the waitlist for an invite.

Package listing

@kody/postmark

src/source.test.ts

40 lines · 1.3 KB · TypeScript
import assert from 'node:assert/strict'
import { readdir, readFile } from 'node:fs/promises'
import { dirname, join } from 'node:path'
import test from 'node:test'
import { fileURLToPath } from 'node:url'

const root = join(dirname(fileURLToPath(import.meta.url)), '..')

async function walk(dir: string): Promise<string[]> {
	const entries = await readdir(dir, { withFileTypes: true })
	const files: string[] = []
	for (const entry of entries) {
		if (entry.name === 'node_modules' || entry.name === '.git') continue
		const path = join(dir, entry.name)
		if (entry.isDirectory()) files.push(...(await walk(path)))
		else files.push(path)
	}
	return files
}

test('package source stays generic: no Kent tokens or from-addresses', async () => {
	const files = (await walk(root)).filter(
		(path) => !path.includes('/.git/') && !path.endsWith('.test.ts'),
	)
	const banned = [
		/kentcdodds/i,
		/me@kentcdodds\.com/i,
		/hello@kentcdodds\.com/i,
		/epicweb\.dev/i,
		/POSTMARK_API_TEST/,
		/X-Postmark-Server-Token:\s*[A-Za-z0-9_-]{12,}/,
	]
	for (const file of files) {
		if (file.endsWith('.png') || file.endsWith('.ico')) continue
		const text = await readFile(file, 'utf8')
		for (const pattern of banned) {
			assert.equal(pattern.test(text), false, file + ' matched ' + pattern)
		}
	}
})