Skip to content

Commit

Permalink
Fix dist references from TS tests
Browse files Browse the repository at this point in the history
  • Loading branch information
huntharo committed May 23, 2024
1 parent 77ed703 commit 8013d99
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
22 changes: 21 additions & 1 deletion lib/xmllint.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
import { existsSync } from 'fs';
import { Readable } from 'stream';
import { resolve } from 'path';
import { execFile } from 'child_process';
import { XMLLintUnavailable } from './errors';

/**
* Finds the `schema` directory since we may be located in
* `lib` or `dist/lib` when this is called.
*
* @throws {Error} if the schema directory is not found
* @returns {string} the path to the schema directory
*/
function findSchemaDir(): string {
const paths = ['.', '..', '../..'];
for (const p of paths) {
const schemaPath = resolve(p, 'schema');
if (existsSync(schemaPath)) {
return schemaPath;
}
}
throw new Error('Schema directory not found');
}

/**
* Verify the passed in xml is valid. Requires xmllib be installed
* @param xml what you want validated
Expand All @@ -10,7 +30,7 @@ import { XMLLintUnavailable } from './errors';
export function xmlLint(xml: string | Readable): Promise<void> {
const args = [
'--schema',
resolve(__dirname, '..', '..', 'schema', 'all.xsd'),
resolve(findSchemaDir(), 'all.xsd'),
'--noout',
'-',
];
Expand Down
2 changes: 1 addition & 1 deletion tests/sitemap-parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
XMLToSitemapItemStream,
ObjectStreamToJSON,
} from '../lib/sitemap-parser';
import { SitemapStreamOptions } from '../dist';
import { SitemapStreamOptions } from '../lib/sitemap-stream';
import { ErrorLevel, SitemapItem } from '../lib/types';
const pipeline = promisify(pipe);
// eslint-disable-next-line @typescript-eslint/no-var-requires
Expand Down
2 changes: 1 addition & 1 deletion tests/xmllint.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { xmlLint } from '../dist/index';
import { xmlLint } from '../lib/xmllint';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const execFileSync = require('child_process').execFileSync;
let hasXMLLint = true;
Expand Down

0 comments on commit 8013d99

Please sign in to comment.