Co-authored-by: Jason Woltje <jason@diversecanvas.com> Co-committed-by: Jason Woltje <jason@diversecanvas.com>
41 lines
1.3 KiB
TypeScript
41 lines
1.3 KiB
TypeScript
import { mkdtemp, rm, writeFile } from 'node:fs/promises';
|
|
import { tmpdir } from 'node:os';
|
|
import { join } from 'node:path';
|
|
|
|
import { describe, expect, it } from 'vitest';
|
|
|
|
import { detectProjectKind } from '../src/detect.js';
|
|
|
|
async function withTempDir(run: (directory: string) => Promise<void>): Promise<void> {
|
|
const directory = await mkdtemp(join(tmpdir(), 'quality-rails-detect-'));
|
|
try {
|
|
await run(directory);
|
|
} finally {
|
|
await rm(directory, { recursive: true, force: true });
|
|
}
|
|
}
|
|
|
|
describe('detectProjectKind', () => {
|
|
it('returns node when package.json exists', async () => {
|
|
await withTempDir(async (directory) => {
|
|
await writeFile(join(directory, 'package.json'), '{"name":"fixture"}\n', 'utf8');
|
|
|
|
await expect(detectProjectKind(directory)).resolves.toBe('node');
|
|
});
|
|
});
|
|
|
|
it('returns python when pyproject.toml exists and package.json does not', async () => {
|
|
await withTempDir(async (directory) => {
|
|
await writeFile(join(directory, 'pyproject.toml'), '[project]\nname = "fixture"\n', 'utf8');
|
|
|
|
await expect(detectProjectKind(directory)).resolves.toBe('python');
|
|
});
|
|
});
|
|
|
|
it('returns unknown when no known project files exist', async () => {
|
|
await withTempDir(async (directory) => {
|
|
await expect(detectProjectKind(directory)).resolves.toBe('unknown');
|
|
});
|
|
});
|
|
});
|