MCPcopy
hub / github.com/jestjs/jest / onChange

Method onChange

packages/jest-haste-map/src/index.ts:875–1012  ·  view source on GitHub ↗
(
      type: string,
      filePath: string,
      root: string,
      stat?: Stats,
    )

Source from the content-addressed store, hash-verified

873 };
874
875 const onChange = (
876 type: string,
877 filePath: string,
878 root: string,
879 stat?: Stats,
880 ) => {
881 filePath = path.join(root, normalizePathSep(filePath));
882 if (
883 (stat && stat.isDirectory()) ||
884 this._ignore(filePath) ||
885 !extensions.some(extension => filePath.endsWith(extension))
886 ) {
887 return;
888 }
889
890 const relativeFilePath = fastPath.relative(rootDir, filePath);
891 const fileMetadata = hasteMap.files.get(relativeFilePath);
892
893 // The file has been accessed, not modified
894 if (
895 type === 'change' &&
896 fileMetadata &&
897 stat &&
898 fileMetadata[H.MTIME] === stat.mtime.getTime()
899 ) {
900 return;
901 }
902
903 changeQueue = changeQueue
904 .then(() => {
905 // If we get duplicate events for the same file, ignore them.
906 if (
907 eventsQueue.some(
908 event =>
909 event.type === type &&
910 event.filePath === filePath &&
911 ((!event.stat && !stat) ||
912 (!!event.stat &&
913 !!stat &&
914 event.stat.mtime.getTime() === stat.mtime.getTime())),
915 )
916 ) {
917 return null;
918 }
919
920 if (mustCopy) {
921 mustCopy = false;
922 hasteMap = {
923 clocks: new Map(hasteMap.clocks),
924 duplicates: new Map(hasteMap.duplicates),
925 files: new Map(hasteMap.files),
926 map: new Map(hasteMap.map),
927 mocks: new Map(hasteMap.mocks),
928 };
929 }
930
931 const add = () => {
932 eventsQueue.push({filePath, stat, type});

Callers

nothing calls this directly

Calls 15

_ignoreMethod · 0.95
_recoverDuplicatesMethod · 0.95
_processFileMethod · 0.95
_cleanupMethod · 0.95
invariantFunction · 0.90
getPlatformExtensionFunction · 0.85
copyFunction · 0.85
getMockNameFunction · 0.85
catchMethod · 0.80
thenMethod · 0.80
deleteMethod · 0.80
addFunction · 0.50

Tested by

no test coverage detected