ts_test.conf 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. TS_TEST_EXTENSION=
  2. TS_TEST_EXTRA_SRCS_MASK=
  3. TS_TEST_CONFIG_PATH=
  4. TS_TEST_NM=
  5. # We have to rename node_modules.tar to workspace_node_modules.tar,
  6. # so TS_TEST_JEST module has it's own unique output.
  7. # TS_TEST_JEST_FOR module has to output all files required for test run.
  8. TS_TEST_JEST_CMD=$TOUCH_UNIT \
  9. && $NOTS_TOOL $NOTS_TOOL_BASE_ARGS create-node-modules --moddir $TS_TEST_FOR_PATH \
  10. $_NODE_MODULES_INOUTS ${hide:PEERS} \
  11. && ${cwd:BINDIR} $MOVE_FILE $TS_TEST_NM ${output:"workspace_node_modules.tar"} \
  12. ${kv;hide:"p TS_JST"} ${kv;hide:"pc magenta"}
  13. ### @usage: TS_TEST_JEST_FOR(Path)
  14. ###
  15. ### Defines testing module with jest test runner.
  16. ###
  17. ### @example
  18. ###
  19. ### TS_TEST_JEST_FOR(path/to/module)
  20. ### TS_TEST_SRCS(../src)
  21. ### TS_TEST_CONFIG(../jest.config.js)
  22. ### END()
  23. ###
  24. module TS_TEST_JEST_FOR: _TS_TEST_BASE {
  25. .CMD=TS_TEST_JEST_CMD
  26. # for multimodule peers we should choose NODE_MODULES
  27. SET(PEERDIR_TAGS NODE_MODULES)
  28. # compatibility with old TS_TEST_SRCS
  29. SET(TS_TEST_EXTENSION test.(ts|tsx|js|jsx))
  30. SET(TS_TEST_EXTRA_SRCS_MASK /**/__mocks__/*)
  31. _PEERDIR_TS_RESOURCE(nodejs pnpm jest)
  32. _TS_TEST_FOR_CONFIGURE(jest jest.config.js workspace_node_modules.tar)
  33. _TS_ADD_NODE_MODULES_FOR_BUILDER()
  34. }
  35. TS_TEST_HERMIONE_CMD=$TOUCH_UNIT \
  36. && ${cwd:BINDIR} $MOVE_FILE ${input:TS_TEST_NM} ${output:"workspace_node_modules.tar"} \
  37. ${kv;hide:"p TSHRM"} ${kv;hide:"pc magenta"}
  38. ### @usage: TS_TEST_HERMIONE_FOR(Path)
  39. ###
  40. ### Defines testing module with hermione test runner.
  41. ###
  42. ### @example
  43. ###
  44. ### TS_TEST_HERMIONE_FOR(path/to/module)
  45. ### TS_TEST_SRCS(../src)
  46. ### TS_TEST_CONFIG(../hermione.conf.js)
  47. ### END()
  48. ###
  49. module TS_TEST_HERMIONE_FOR: _TS_TEST_BASE {
  50. .CMD=TS_TEST_HERMIONE_CMD
  51. # for multimodule peers we should choose TS
  52. SET(PEERDIR_TAGS TS)
  53. # compatibility with old TS_TEST_SRCS
  54. SET(TS_TEST_EXTENSION hermione.(ts|js))
  55. _DEPENDS_ON_MOD()
  56. _PEERDIR_TS_RESOURCE(nodejs pnpm typescript hermione)
  57. _TS_TEST_FOR_CONFIGURE(hermione .hermione.conf.js workspace_node_modules.tar)
  58. }
  59. module _TS_TEST_BASE: _BARE_UNIT {
  60. # ignore SRCS macro
  61. .ALIASES=SRCS=_NOOP_MACRO
  62. # use this parser to get module args in $MODULE_ARGS_RAW
  63. .ARGS_PARSER=Raw
  64. .NODE_TYPE=Program
  65. # TODO: remove this. YMAKE-1096 / FBP-1184
  66. _NEVERCACHE()
  67. # .fake tells builder to not materialize it in results
  68. SET(MODULE_SUFFIX .ts_test.fake)
  69. # include processor works only for TS tag
  70. SET(MODULE_TAG TS)
  71. # we read erm-packages.json during configuration, so we have to include it to configuration cache key
  72. SET_APPEND(_MAKEFILE_INCLUDE_LIKE_DEPS ${ARCADIA_ROOT}/$ERM_PACKAGES_PATH)
  73. # parse module args
  74. _TS_TEST_FOR_ARGS($MODULE_ARGS_RAW)
  75. # we don't want to have TS outputs for tests
  76. DISABLE(TS_CONFIG_DEDUCE_OUT)
  77. }
  78. macro _TS_TEST_FOR_ARGS(FOR_MOD, RELATIVE?"${CURDIR}":"${ARCADIA_ROOT}") {
  79. # we read testing modules' package.json during configuration,
  80. # so we have to include it to configuration cache key
  81. SET_APPEND(_MAKEFILE_INCLUDE_LIKE_DEPS $RELATIVE/$FOR_MOD/package.json)
  82. SET_APPEND(_MAKEFILE_INCLUDE_LIKE_DEPS $RELATIVE/$FOR_MOD/pnpm-lock.yaml)
  83. _VALIDATE_TS_TEST_FOR_ARGS($FOR_MOD $RELATIVE)
  84. _SET_TS_TEST_FOR_VARS($FOR_MOD)
  85. }
  86. macro _SETUP_EXTRACT_NODE_MODULES_RECIPE(FOR_PATH) {
  87. DEPENDS(devtools/frontend_build_platform/nots/recipes/extract_node_modules)
  88. USE_RECIPE(devtools/frontend_build_platform/nots/recipes/extract_node_modules/recipe $FOR_PATH workspace_node_modules.tar)
  89. }
  90. macro _SETUP_EXTRACT_PEER_TARS_RECIPE(FOR_PATH) {
  91. DEPENDS(devtools/frontend_build_platform/nots/recipes/extract_peer_tars)
  92. USE_RECIPE(devtools/frontend_build_platform/nots/recipes/extract_peer_tars/recipe $FOR_PATH)
  93. }
  94. ### @usage: TS_TEST_CONFIG(Path)
  95. ###
  96. ### Macro sets the path to configuration file of the test runner.
  97. ###
  98. ### - Path - path to the config file.
  99. macro TS_TEST_CONFIG(Path) {
  100. SET(TS_TEST_CONFIG_PATH $Path)
  101. }
  102. _TS_TEST_SRCS_VALUE=
  103. _TS_TEST_EXTRA_SRCS_VALUE=
  104. ### @usage: TS_TEST_SRCS(DIRS...)
  105. ###
  106. ### Macro to define directories where the test source files should be located.
  107. ###
  108. ### - DIRS... - directories.
  109. macro TS_TEST_SRCS(DIRS...) {
  110. _GLOB(_TS_TEST_SRCS_VALUE ${suf=/**/*.$TS_TEST_EXTENSION:DIRS})
  111. SRCS($_TS_TEST_SRCS_VALUE)
  112. _GLOB(_TS_TEST_EXTRA_SRCS_VALUE ${suf=$TS_TEST_EXTRA_SRCS_MASK:DIRS})
  113. SRCS($_TS_TEST_EXTRA_SRCS_VALUE)
  114. }
  115. _TS_TEST_DATA_VALUE=
  116. _TS_TEST_DATA_DIRS_RENAME_VALUE=
  117. ### @usage: TS_TEST_DATA([RENAME] GLOBS...)
  118. ###
  119. ### Macro to add tests data (i.e. snapshots) used in testing to a bindir from curdir.
  120. ### Creates symbolic links to directories of files found by the specified globs.
  121. ###
  122. ### Parameters:
  123. ### - RENAME - adds ability to rename paths for tests data from curdir to bindir.
  124. ### For example if your tested module located on "module" path and tests data in "module/tests_data".
  125. ### Then you can be able to rename "tests_data" folder to something else - `RENAME tests_data:example`.
  126. ### As a result in your bindir will be created folder - "module/example" which is a symbolic link on "module/tests_data" in curdir.
  127. ### It is possible to specify multiple renaming rules in the following format "dir1:dir2;dir3/foo:dir4/bar", where "dir1" and "dir3" folders in curdir.
  128. ### - GLOBS... - globs to tests data files, symbolic links will be created to their folders. For example - "tests_data/**/*".
  129. macro TS_TEST_DATA(RENAME="", GLOBS...) {
  130. _GLOB(_TS_TEST_DATA_VALUE $GLOBS)
  131. SET(_TS_TEST_DATA_DIRS_RENAME_VALUE $RENAME)
  132. }