MCPcopy Create free account
hub / github.com/ampproject/amphtml / getJsFilesFor

Function getJsFilesFor

build-system/tasks/runtime-test/helpers-unit.js:121–139  ·  view source on GitHub ↗

* Retrieves the set of JS source files that import the given CSS file. * * @param {string} cssFile * @param {!{[key: string]: string}} cssJsFileMap * @return {!Array }

(cssFile, cssJsFileMap)

Source from the content-addressed store, hash-verified

119 * @return {!Array<string>}
120 */
121function getJsFilesFor(cssFile, cssJsFileMap) {
122 const jsFiles = [];
123 if (cssJsFileMap.hasOwnProperty(cssFile)) {
124 const cssFileDir = path.dirname(cssFile);
125 const jsFilesInDir = fs.readdirSync(cssFileDir).filter((file) => {
126 return path.extname(file) == '.js';
127 });
128 jsFilesInDir.forEach((jsFile) => {
129 const jsFilePath = `${cssFileDir}/${jsFile}`;
130 const jsImports = getImports(jsFilePath);
131 if (
132 jsImports.some((jsImport) => jsImport.includes(cssJsFileMap[cssFile]))
133 ) {
134 jsFiles.push(jsFilePath);
135 }
136 });
137 }
138 return jsFiles;
139}
140
141/**
142 * Computes the list of unit tests to run under difference scenarios

Callers 1

unitTestsToRunFunction · 0.85

Calls 4

getImportsFunction · 0.85
filterMethod · 0.45
forEachMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected