angular/aio/tools/transforms/angular-extended-diagnostics-package/readers/extended-diagnostic.spec.js
George Kalpakas 7480660a95 fix(docs-infra): track error docs during serve-and-sync (#44704)
Refs #42966.

Look for changes in error docs (i.e. docs under `aio/content/error/`) in
`authors-package`, so that such docs are tracked when running the
`serve-and-sync` script.

PR Close #44704
2022-01-24 10:41:13 -08:00

43 lines
1.4 KiB
JavaScript

const path = require('canonical-path');
const Dgeni = require('dgeni');
const testPackage = require('../../helpers/test-package');
describe('extendedDiagnosticFileReader', () => {
let dgeni, injector, fileReader;
beforeEach(() => {
dgeni = new Dgeni([testPackage('angular-extended-diagnostics-package', false)]);
injector = dgeni.configureInjector();
fileReader = injector.get('extendedDiagnosticFileReader');
});
function createFileInfo(file, content, basePath) {
return {
fileReader: fileReader.name,
filePath: file,
baseName: path.basename(file, path.extname(file)),
extension: path.extname(file).replace(/^\./, ''),
basePath: basePath,
relativePath: path.relative(basePath, file),
content: content,
};
}
describe('defaultPattern', () => {
it('should match `.md` files', () => {
expect(fileReader.defaultPattern.test('abc.md')).toBeTrue();
expect(fileReader.defaultPattern.test('abc.js')).toBeFalse();
});
});
describe('getDocs', () => {
it('should return an object containing info about the file and its contents', () => {
const fileInfo = createFileInfo(
'project/path/modules/someModule/foo/docs/subfolder/bar.md', 'A load of content.',
'project/path');
expect(fileReader.getDocs(fileInfo)).toEqual([
{docType: 'extended-diagnostic', content: 'A load of content.'},
]);
});
});
});