George Kalpakas 2203217c40 build(docs-infra): disambiguate doc paths for global APIs (#42648)
In #41788, the `disambiguateDocsPathsProcessor` was introduced to fix
an issue with case-insensitively equal paths. This processor may alter
the output paths of some docs. Due to its nature, the
`disambiguateDocPathsProcessor` must be the last processor in the
pipeline that updates a doc's output path. However, the
`updateGlobalApiPathProcess` (which also alters the output paths of some
docs) was not configured to run before `disambiguateDocPathsProcessor`.
As a result, the changes made by `disambiguateDocPathsProcessor` were
overridden by `updateGlobalApiPathProcess`, resulting in the app's
failing to load such global API docs pages. An example of such an API
page is: https://angular.io/api/core/global/ngApplyChanges

This commit fixes it by ensuring that the `updateGlobalApiPathProcess`
is explicitly run before the `disambiguateDocPathsProcessor`, so that
the former does not override the changes made by the latter.

PR Close #42648
2021-06-24 12:28:21 -07:00

38 lines
1.3 KiB
JavaScript

const testPackage = require('../../helpers/test-package');
const processorFactory = require('./updateGlobalApiPath');
const Dgeni = require('dgeni');
describe('updateGlobalApiPath processor', () => {
it('should be available on the injector', () => {
const dgeni = new Dgeni([testPackage('angular-api-package')]);
const injector = dgeni.configureInjector();
const processor = injector.get('updateGlobalApiPathProcessor');
expect(processor.$process).toBeDefined();
});
it('should run before the correct processor', () => {
const processor = processorFactory();
expect(processor.$runBefore).toEqual(['disambiguateDocPathsProcessor', 'processNgModuleDocs']);
});
it('should run after the correct processor', () => {
const processor = processorFactory();
expect(processor.$runAfter).toEqual(['paths-computed']);
});
it('should update the paths of namespaced global APIs', () => {
const processor = processorFactory();
const docs = [{
docType: 'function',
moduleDoc: { moduleFolder: 'folder' },
name: 'ng.withNamespace',
globalNamespace: 'ng',
unprefixedName: 'withNamespace',
global: true
}];
processor.$process(docs);
expect(docs[0].path).toBe('folder/ngWithNamespace');
expect(docs[0].outputPath).toBe('folder/ngWithNamespace.json');
});
});