ts_test.conf 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. TS_TEST_EXTENSION=
  2. TS_TEST_EXTRA_SRCS_MASK=
  3. TS_TEST_CONFIG_PATH=
  4. TS_TEST_NM=
  5. _TS_TEST_DEPENDS_ON_BUILD=
  6. # We have to rename node_modules.tar to workspace_node_modules.tar,
  7. # so TS_TEST_JEST module has it's own unique output.
  8. # TS_TEST_JEST_FOR module has to output all files required for test run.
  9. TS_TEST_JEST_CMD=$TOUCH_UNIT \
  10. && $NOTS_TOOL $NOTS_TOOL_BASE_ARGS create-node-modules --moddir $TS_TEST_FOR_PATH \
  11. $_NODE_MODULES_INOUTS ${hide:PEERS} \
  12. && ${cwd:BINDIR} $MOVE_FILE $TS_TEST_NM ${output:"workspace_node_modules.tar"} \
  13. ${kv;hide:"p TS_JST"} ${kv;hide:"pc magenta"}
  14. ### @usage: TS_TEST_JEST_FOR(Path)
  15. ###
  16. ### Defines testing module with jest test runner.
  17. ###
  18. ### Documentation: https://docs.yandex-team.ru/frontend-in-arcadia/references/TS_TEST_JEST_FOR
  19. ###
  20. ### @example
  21. ###
  22. ### TS_TEST_JEST_FOR(path/to/module)
  23. ### TS_TEST_SRCS(../src)
  24. ### TS_TEST_CONFIG(../jest.config.js)
  25. ### END()
  26. ###
  27. module TS_TEST_JEST_FOR: _TS_TEST_BASE {
  28. .CMD=TS_TEST_JEST_CMD
  29. # for multimodule peers we should choose NODE_MODULES
  30. SET(PEERDIR_TAGS TS)
  31. # compatibility with old TS_TEST_SRCS
  32. SET(TS_TEST_EXTENSION test.(ts|tsx|js|jsx))
  33. SET(TS_TEST_EXTRA_SRCS_MASK /**/__mocks__/*)
  34. # nots.py will decide if we need to depend on the testing target module output
  35. _DEPENDS_ON_MOD()
  36. _PEERDIR_TS_RESOURCE(nodejs jest)
  37. _TS_TEST_FOR_CONFIGURE(jest jest.config.js workspace_node_modules.tar)
  38. _TS_ADD_NODE_MODULES_FOR_BUILDER()
  39. }
  40. TS_TEST_HERMIONE_CMD=$TOUCH_UNIT \
  41. && ${cwd:BINDIR} $MOVE_FILE ${input:TS_TEST_NM} ${output:"workspace_node_modules.tar"} \
  42. ${kv;hide:"p TSHRM"} ${kv;hide:"pc magenta"}
  43. ### @usage: TS_TEST_HERMIONE_FOR(Path)
  44. ###
  45. ### Defines testing module with hermione test runner.
  46. ###
  47. ### Documentation: https://docs.yandex-team.ru/frontend-in-arcadia/references/TS_TEST_HERMIONE_FOR
  48. ###
  49. ### @example
  50. ###
  51. ### TS_TEST_HERMIONE_FOR(path/to/module)
  52. ### TS_TEST_SRCS(../src)
  53. ### TS_TEST_CONFIG(../hermione.conf.js)
  54. ### END()
  55. ###
  56. module TS_TEST_HERMIONE_FOR: _TS_TEST_BASE {
  57. .CMD=TS_TEST_HERMIONE_CMD
  58. # for multimodule peers we should choose TS
  59. SET(PEERDIR_TAGS TS)
  60. # compatibility with old TS_TEST_SRCS
  61. SET(TS_TEST_EXTENSION hermione.(ts|js))
  62. TS_TEST_DEPENDS_ON_BUILD()
  63. _DEPENDS_ON_MOD()
  64. _PEERDIR_TS_RESOURCE(nodejs typescript hermione)
  65. _TS_TEST_FOR_CONFIGURE(hermione .hermione.conf.js workspace_node_modules.tar)
  66. }
  67. TS_TEST_PLAYWRIGHT_CMD=$TOUCH_UNIT \
  68. && $NOTS_TOOL $NOTS_TOOL_BASE_ARGS create-node-modules --moddir $TS_TEST_FOR_PATH \
  69. $_NODE_MODULES_INOUTS ${hide:PEERS} \
  70. && ${cwd:BINDIR} $MOVE_FILE $TS_TEST_NM ${output:"workspace_node_modules.tar"} \
  71. ${kv;hide:"p TSPW"} ${kv;hide:"pc magenta"}
  72. ### @usage: TS_TEST_PLAYWRIGHT_FOR(Path)
  73. ###
  74. ### Defines testing module with playwright test runner.
  75. ###
  76. ### Documentation: https://docs.yandex-team.ru/frontend-in-arcadia/references/TS_TEST_PLAYWRIGHT_FOR
  77. ###
  78. ### @example
  79. ###
  80. ### TS_TEST_PLAYWRIGHT_FOR(path/to/module)
  81. ### TS_TEST_SRCS(../src)
  82. ### TS_TEST_CONFIG(../playwright.config.js)
  83. ### END()
  84. ###
  85. module TS_TEST_PLAYWRIGHT_FOR: _TS_TEST_BASE {
  86. .CMD=TS_TEST_PLAYWRIGHT_CMD
  87. # for multimodule peers we should choose TS
  88. SET(PEERDIR_TAGS TS)
  89. # compatibility with old TS_TEST_SRCS
  90. SET(TS_TEST_EXTENSION (playwright|spec).(ts|js))
  91. _DEPENDS_ON_MOD()
  92. _TS_ADD_NODE_MODULES_FOR_BUILDER()
  93. _PEERDIR_TS_RESOURCE(nodejs playwright)
  94. _TS_TEST_FOR_CONFIGURE(playwright playwright.config.ts workspace_node_modules.tar)
  95. }
  96. ### # internal
  97. module _TS_TEST_BASE: _BARE_UNIT {
  98. # ignore SRCS macro
  99. .ALIASES=SRCS=_NOOP_MACRO
  100. # use this parser to get module args in $MODULE_ARGS_RAW
  101. .ARGS_PARSER=Raw
  102. .NODE_TYPE=Bundle
  103. .PEERDIR_POLICY=as_build_from
  104. # .fake tells builder to not materialize it in results
  105. SET(MODULE_SUFFIX .ts_test.fake)
  106. # include processor works only for TS tag
  107. SET(MODULE_TAG TS)
  108. SET(MODULE_LANG TS)
  109. # we read erm-packages.json during configuration, so we have to include it to configuration cache key
  110. SET_APPEND(_MAKEFILE_INCLUDE_LIKE_DEPS ${ARCADIA_ROOT}/$ERM_PACKAGES_PATH)
  111. # parse module args
  112. _TS_TEST_FOR_ARGS($MODULE_ARGS_RAW)
  113. # Set PM values from TS_TEST_FOR_DIR
  114. _SET_PACKAGE_MANAGER()
  115. # we don't want to have TS outputs for tests
  116. DISABLE(TS_CONFIG_DEDUCE_OUT)
  117. }
  118. macro _TS_TEST_FOR_ARGS(FOR_MOD, RELATIVE?"${CURDIR}":"${ARCADIA_ROOT}") {
  119. # we read testing modules' package.json during configuration,
  120. # so we have to include it to configuration cache key
  121. SET_APPEND(_MAKEFILE_INCLUDE_LIKE_DEPS $RELATIVE/$FOR_MOD/package.json)
  122. SET_APPEND(_MAKEFILE_INCLUDE_LIKE_DEPS $RELATIVE/$FOR_MOD/pnpm-lock.yaml)
  123. _VALIDATE_TS_TEST_FOR_ARGS($FOR_MOD $RELATIVE)
  124. _SET_TS_TEST_FOR_VARS($FOR_MOD)
  125. }
  126. macro _SETUP_EXTRACT_NODE_MODULES_RECIPE(FOR_PATH) {
  127. USE_RECIPE(devtools/frontend_build_platform/nots/recipes/extract_node_modules/recipe $FOR_PATH workspace_node_modules.tar)
  128. }
  129. macro _SETUP_EXTRACT_OUTPUT_TARS_RECIPE(FOR_PATH) {
  130. USE_RECIPE(devtools/frontend_build_platform/nots/recipes/extract_output_tars/recipe $FOR_PATH)
  131. }
  132. macro _SETUP_INSTALL_NODE_MODULES_RECIPE() {
  133. USE_RECIPE(devtools/frontend_build_platform/nots/recipes/install_node_modules/recipe $NOTS_TOOL_BASE_ARGS --bundle no)
  134. }
  135. ### @usage: TS_TEST_CONFIG(Path)
  136. ###
  137. ### Macro sets the path to configuration file of the test runner.
  138. ###
  139. ### - Path - path to the config file.
  140. ###
  141. ### Documentation: https://docs.yandex-team.ru/frontend-in-arcadia/references/macros#ts-test-config
  142. macro TS_TEST_CONFIG(Path) {
  143. SET(TS_TEST_CONFIG_PATH $Path)
  144. }
  145. _TS_TEST_SRCS_VALUE=
  146. _TS_TEST_EXTRA_SRCS_VALUE=
  147. ### @usage: TS_TEST_SRCS(DIRS...)
  148. ###
  149. ### Macro to define directories where the test source files should be located.
  150. ###
  151. ### - DIRS... - directories.
  152. ###
  153. ### Documentation: https://docs.yandex-team.ru/frontend-in-arcadia/references/macros#ts-test-srcs
  154. macro TS_TEST_SRCS(DIRS...) {
  155. _GLOB(_TS_TEST_SRCS_VALUE ${suf=/**/*.$TS_TEST_EXTENSION:DIRS})
  156. SRCS($_TS_TEST_SRCS_VALUE)
  157. _GLOB(_TS_TEST_EXTRA_SRCS_VALUE ${suf=$TS_TEST_EXTRA_SRCS_MASK:DIRS})
  158. SRCS($_TS_TEST_EXTRA_SRCS_VALUE)
  159. }
  160. _TS_TEST_DATA_VALUE=
  161. _TS_TEST_DATA_DIRS_RENAME_VALUE=
  162. ### @usage: TS_TEST_DATA([RENAME] GLOBS...)
  163. ###
  164. ### Macro to add tests data (i.e. snapshots) used in testing to a bindir from curdir.
  165. ### Creates symbolic links to directories of files found by the specified globs.
  166. ###
  167. ### Parameters:
  168. ### - RENAME - adds ability to rename paths for tests data from curdir to bindir.
  169. ### For example if your tested module located on "module" path and tests data in "module/tests_data".
  170. ### Then you can be able to rename "tests_data" folder to something else - `RENAME tests_data:example`.
  171. ### As a result in your bindir will be created folder - "module/example" which is a symbolic link on "module/tests_data" in curdir.
  172. ### 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.
  173. ### - GLOBS... - globs to tests data files, symbolic links will be created to their folders. For example - "tests_data/**/*".
  174. macro TS_TEST_DATA(RENAME="", GLOBS...) {
  175. _GLOB(_TS_TEST_DATA_VALUE $GLOBS)
  176. SET(_TS_TEST_DATA_DIRS_RENAME_VALUE $RENAME)
  177. }
  178. ### @usage: TS_TEST_DEPENDS_ON_BUILD()
  179. ###
  180. ### Macro enables build and results unpacking for the module test is targeting.
  181. ### It is not required for most of the tests, but it might be needeed in some special cases.
  182. macro TS_TEST_DEPENDS_ON_BUILD() {
  183. ENABLE(_TS_TEST_DEPENDS_ON_BUILD)
  184. }
  185. # TS_TYPECHECK
  186. _TS_TYPECHECK_VALUE=none
  187. _TS_TYPECHECK_TSCONFIG=
  188. macro NO_TS_TYPECHECK() {
  189. SET(_TS_TYPECHECK_VALUE none)
  190. }
  191. ### @usage: TS_TYPECHECK(tsconfigFile)
  192. ###
  193. ### For check CSS, SASS, LESS for StyleLint. Must be inside of Module (TS_WEBPACK, TS_VITE, TS_NEXT, etc)
  194. ###
  195. ### - tsconfigFile - by default tsconfig.json or value from TS_CONFIG macros.
  196. ###
  197. ### Documentation: https://docs.yandex-team.ru/frontend-in-arcadia/references/macros#ts-typecheck
  198. ###
  199. ### @example:
  200. ###
  201. ### TS_VITE()
  202. ### TS_TYPECHECK()
  203. ### END()
  204. macro TS_TYPECHECK(TS_CONFG="") {
  205. ENABLE(_TS_TYPECHECK_VALUE)
  206. SET(_TS_TYPECHECK_TSCONFIG $TS_CONFG)
  207. }
  208. # TS_STYLELINT
  209. _TS_STYLELINT_VALUE=no
  210. _TS_STYLELINT_CONFIG=
  211. _TS_STYLELINT_FILES=
  212. ### @usage: TS_STYLELINT(configFile)
  213. ###
  214. ### For check CSS, SASS, LESS for StyleLint. Must be inside of Module (TS_WEBPACK, TS_VITE, TS_NEXT, etc)
  215. ###
  216. ### - configFile - by default .stylelintrc.
  217. ###
  218. ### Documentation: https://docs.yandex-team.ru/frontend-in-arcadia/references/macros#ts-stylelint
  219. ###
  220. ### @example:
  221. ###
  222. ### TS_VITE()
  223. ### TS_STYLELINT(.stylelintrc)
  224. ### END()
  225. macro TS_STYLELINT(_CONFIG) {
  226. ENABLE(_TS_STYLELINT_VALUE)
  227. SET(_TS_STYLELINT_CONFIG $_CONFIG)
  228. _GLOB(_TS_STYLELINT_FILES **/*(.css|.scss|.less) EXCLUDE $TS_EXCLUDE_DIR_GLOB $TS_COMMON_OUTDIR_GLOB $TS_GLOB_EXCLUDE_ADDITIONAL)
  229. }