MCPcopy Create free account
hub / github.com/angular/components / testPackage

Function testPackage

integration/linker/link-packages-test.mjs:65–107  ·  view source on GitHub ↗

* Tests the specified package against the Angular linker plugin. * @param pkg Package being tested. * @returns An object containing linker failures and passed files.

(pkg)

Source from the content-addressed store, hash-verified

63 * @returns An object containing linker failures and passed files.
64 */
65function testPackage(pkg) {
66 const entryPointFesmFiles = globSync(`fesm2022/**/*.mjs`, {cwd: pkg.pkgPath});
67 const passedFiles = [];
68 const failures = [];
69
70 // Iterate through each entry point and confirm that all partial declarations can be linked
71 // to their corresponding Angular definitions without errors.
72 for (const fesmFileName of entryPointFesmFiles) {
73 const diskFilePath = path.join(pkg.pkgPath, fesmFileName);
74 const debugFileName = path.join(pkg.name, fesmFileName);
75 const fileContent = fs.readFileSync(diskFilePath, 'utf8');
76 const linkerPlugin = createEs2015LinkerPlugin({fileSystem, logger});
77
78 // Babel throws errors if the transformation fails. We catch these so that we
79 // can print incompatible entry points with their errors at the end.
80 try {
81 const {ast} = transformSync(fileContent, {
82 ast: true,
83 filename: diskFilePath,
84 filenameRelative: debugFileName,
85 plugins: [linkerPlugin],
86 });
87
88 // Naively check if there are any Angular declarations left that haven't been linked.
89 traverse(ast, {
90 Identifier: astPath => {
91 if (astPath.node.name.startsWith('ɵɵngDeclare')) {
92 throw astPath.buildCodeFrameError(
93 'Found Angular declaration that has not been linked.',
94 Error,
95 );
96 }
97 },
98 });
99
100 passedFiles.push(debugFileName);
101 } catch (error) {
102 failures.push({debugFileName, error});
103 }
104 }
105
106 return {passedFiles, failures};
107}

Callers 1

Calls 1

pushMethod · 0.65

Tested by

no test coverage detected