mirror of
https://github.com/broekema41/obsidian-vcf-contacts.git
synced 2026-07-22 05:42:58 +00:00
test(encodings.spec): add encoding tests and helper function
This commit is contained in:
parent
0733b3ed54
commit
69fd1e6c35
2 changed files with 39 additions and 2 deletions
31
tests/encodings.spec.ts
Normal file
31
tests/encodings.spec.ts
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import {beforeAll, describe, expect, it} from 'vitest';
|
||||
|
||||
import {parseTextFile} from "../src/file/file";
|
||||
import {readVcfFixture, readVcfFixtureAsBlob} from "./fixtures/fixtures";
|
||||
|
||||
|
||||
describe('parseDifferentEncodings', () => {
|
||||
|
||||
let expectedData: string;
|
||||
beforeAll(() => {
|
||||
expectedData = readVcfFixture('encoding-utf8.vcf');
|
||||
})
|
||||
|
||||
|
||||
it('should parse utf-8 vCards as it used to', async () => {
|
||||
const data = await readVcfFixtureAsBlob('encoding-utf8.vcf');
|
||||
const result = await parseTextFile(data)
|
||||
|
||||
expect(result).toBe(expectedData);
|
||||
|
||||
})
|
||||
|
||||
it('should parse windows-1251 vCards correctly', async () => {
|
||||
const data = await readVcfFixtureAsBlob('encoding-win1251.vcf');
|
||||
const result = await parseTextFile(data)
|
||||
|
||||
expect(result).toBe(expectedData);
|
||||
})
|
||||
|
||||
|
||||
})
|
||||
10
tests/fixtures/fixtures.ts
vendored
10
tests/fixtures/fixtures.ts
vendored
|
|
@ -1,11 +1,17 @@
|
|||
import { readFileSync } from 'fs';
|
||||
import { join, resolve } from 'path';
|
||||
import {openAsBlob, readFileSync} from 'fs';
|
||||
import {join, resolve} from 'path';
|
||||
|
||||
export function readVcfFixture(fileName: string): string {
|
||||
const filePath = join(__dirname, fileName);
|
||||
return readFileSync(filePath, 'utf8');
|
||||
}
|
||||
|
||||
export async function readVcfFixtureAsBlob(fileName: string): Promise<Blob> {
|
||||
const filePath = join(__dirname, fileName);
|
||||
return openAsBlob(filePath);
|
||||
}
|
||||
|
||||
|
||||
export function readFrontmatterFixture(fileName: string): Record<string, any>|undefined {
|
||||
const fullPath = resolve(__dirname, fileName + '.js');
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
|
|
|
|||
Loading…
Reference in a new issue