ts_test.conf 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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. ${hide;kv:"p TS_JST"} ${hide;kv:"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 TS_PROTO)
  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 ${hide:PEERS} \
  41. && ${cwd:BINDIR} $MOVE_FILE ${input:TS_TEST_NM} ${output:"workspace_node_modules.tar"} \
  42. ${hide;kv:"p TSHRM"} ${hide;kv:"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 TS_PROTO)
  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. ${hide;kv:"p TSPW"} ${hide;kv:"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 TS_PROTO)
  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. TS_TEST_PLAYWRIGHT_LARGE_CMD=$TOUCH_UNIT \
  97. && ${cwd:BINDIR} $MOVE_FILE ${input:TS_TEST_NM} ${output:"workspace_node_modules.tar"} \
  98. ${hide;kv:"p TSPW"} ${hide;kv:"pc magenta"}
  99. ### @usage: TS_TEST_PLAYWRIGHT_LARGE_FOR(Path)
  100. ###
  101. ### Defines testing module with playwright test runner.
  102. ###
  103. ### Documentation: https://docs.yandex-team.ru/frontend-in-arcadia/references/TS_TEST_PLAYWRIGHT_FOR
  104. ###
  105. ### @example
  106. ###
  107. ### TS_TEST_PLAYWRIGHT_LARGE_FOR(path/to/module)
  108. ### TS_TEST_SRCS(../src)
  109. ### TS_TEST_CONFIG(../playwright.config.js)
  110. ### END()
  111. ###
  112. module TS_TEST_PLAYWRIGHT_LARGE_FOR: _TS_TEST_BASE {
  113. .CMD=TS_TEST_PLAYWRIGHT_LARGE_CMD
  114. # for multimodule peers we should choose TS
  115. SET(PEERDIR_TAGS TS TS_PROTO)
  116. # compatibility with old TS_TEST_SRCS
  117. SET(TS_TEST_EXTENSION (playwright|spec).(ts|js))
  118. TS_TEST_DEPENDS_ON_BUILD()
  119. _DEPENDS_ON_MOD()
  120. _PEERDIR_TS_RESOURCE(nodejs playwright)
  121. _TS_TEST_FOR_CONFIGURE(playwright_large playwright.config.ts workspace_node_modules.tar)
  122. }
  123. ### # internal
  124. module _TS_TEST_BASE: _BARE_UNIT {
  125. # ignore SRCS macro
  126. .ALIASES=SRCS=_NOOP_MACRO
  127. # use this parser to get module args in $MODULE_ARGS_RAW
  128. .ARGS_PARSER=Raw
  129. .NODE_TYPE=Bundle
  130. .PEERDIR_POLICY=as_build_from
  131. # .fake tells builder to not materialize it in results
  132. SET(MODULE_SUFFIX .ts_test.fake)
  133. # include processor works only for TS tag
  134. SET(MODULE_TAG TS)
  135. SET(MODULE_LANG TS)
  136. # we read erm-packages.json during configuration, so we have to include it to configuration cache key
  137. SET_APPEND(_MAKEFILE_INCLUDE_LIKE_DEPS ${ARCADIA_ROOT}/$ERM_PACKAGES_PATH)
  138. # parse module args
  139. _TS_TEST_FOR_ARGS($MODULE_ARGS_RAW)
  140. # Set PM values from TS_TEST_FOR_DIR
  141. _SET_PACKAGE_MANAGER()
  142. # we don't want to have TS outputs for tests
  143. DISABLE(TS_CONFIG_DEDUCE_OUT)
  144. }
  145. macro _TS_TEST_FOR_ARGS(FOR_MOD, RELATIVE?"${CURDIR}":"${ARCADIA_ROOT}") {
  146. # we read testing modules' package.json during configuration,
  147. # so we have to include it to configuration cache key
  148. SET_APPEND(_MAKEFILE_INCLUDE_LIKE_DEPS $RELATIVE/$FOR_MOD/package.json)
  149. SET_APPEND(_MAKEFILE_INCLUDE_LIKE_DEPS $RELATIVE/$FOR_MOD/pnpm-lock.yaml)
  150. _VALIDATE_TS_TEST_FOR_ARGS($FOR_MOD $RELATIVE)
  151. _SET_TS_TEST_FOR_VARS($FOR_MOD)
  152. }
  153. macro _SETUP_EXTRACT_NODE_MODULES_RECIPE(FOR_PATH) {
  154. USE_RECIPE(devtools/frontend_build_platform/nots/recipes/extract_node_modules/recipe $FOR_PATH workspace_node_modules.tar)
  155. }
  156. macro _SETUP_EXTRACT_OUTPUT_TARS_RECIPE(FOR_PATH) {
  157. USE_RECIPE(devtools/frontend_build_platform/nots/recipes/extract_output_tars/recipe $FOR_PATH)
  158. }
  159. macro _SETUP_INSTALL_NODE_MODULES_RECIPE() {
  160. USE_RECIPE(devtools/frontend_build_platform/nots/recipes/install_node_modules/recipe $NOTS_TOOL_BASE_ARGS --bundle no)
  161. }
  162. ### @usage: TS_TEST_CONFIG(Path)
  163. ###
  164. ### Macro sets the path to configuration file of the test runner.
  165. ###
  166. ### - Path - path to the config file.
  167. ###
  168. ### Documentation: https://docs.yandex-team.ru/frontend-in-arcadia/references/macros#ts-test-config
  169. macro TS_TEST_CONFIG(Path) {
  170. SET(TS_TEST_CONFIG_PATH $Path)
  171. }
  172. _TS_TEST_SRCS_VALUE=
  173. _TS_TEST_EXTRA_SRCS_VALUE=
  174. ### @usage: TS_TEST_SRCS(DIRS...)
  175. ###
  176. ### Macro to define directories where the test source files should be located.
  177. ###
  178. ### - DIRS... - directories.
  179. ###
  180. ### Documentation: https://docs.yandex-team.ru/frontend-in-arcadia/references/macros#ts-test-srcs
  181. macro TS_TEST_SRCS(DIRS...) {
  182. _GLOB(_TS_TEST_SRCS_VALUE ${suf=/**/*.$TS_TEST_EXTENSION:DIRS})
  183. SRCS($_TS_TEST_SRCS_VALUE)
  184. _GLOB(_TS_TEST_EXTRA_SRCS_VALUE ${suf=$TS_TEST_EXTRA_SRCS_MASK:DIRS})
  185. SRCS($_TS_TEST_EXTRA_SRCS_VALUE)
  186. }
  187. _TS_TEST_DATA_VALUE=
  188. _TS_TEST_DATA_DIRS_RENAME_VALUE=
  189. ### @usage: TS_TEST_DATA([RENAME] GLOBS...)
  190. ###
  191. ### Macro to add tests data (i.e. snapshots) used in testing to a bindir from curdir.
  192. ### Creates symbolic links to directories of files found by the specified globs.
  193. ###
  194. ### Parameters:
  195. ### - RENAME - adds ability to rename paths for tests data from curdir to bindir.
  196. ### For example if your tested module located on "module" path and tests data in "module/tests_data".
  197. ### Then you can be able to rename "tests_data" folder to something else - `RENAME tests_data:example`.
  198. ### As a result in your bindir will be created folder - "module/example" which is a symbolic link on "module/tests_data" in curdir.
  199. ### 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.
  200. ### - GLOBS... - globs to tests data files, symbolic links will be created to their folders. For example - "tests_data/**/*".
  201. macro TS_TEST_DATA(RENAME="", GLOBS...) {
  202. _GLOB(_TS_TEST_DATA_VALUE $GLOBS)
  203. SET(_TS_TEST_DATA_DIRS_RENAME_VALUE $RENAME)
  204. }
  205. ### @usage: TS_TEST_DEPENDS_ON_BUILD()
  206. ###
  207. ### Macro enables build and results unpacking for the module test is targeting.
  208. ### It is not required for most of the tests, but it might be needeed in some special cases.
  209. macro TS_TEST_DEPENDS_ON_BUILD() {
  210. ENABLE(_TS_TEST_DEPENDS_ON_BUILD)
  211. }
  212. # TS_TYPECHECK
  213. _TS_TYPECHECK_VALUE=none
  214. _TS_TYPECHECK_TSCONFIG=
  215. macro NO_TS_TYPECHECK() {
  216. SET(_TS_TYPECHECK_VALUE none)
  217. }
  218. ### @usage: TS_TYPECHECK(tsconfigFile)
  219. ###
  220. ### For check CSS, SASS, LESS for StyleLint. Must be inside of Module (TS_WEBPACK, TS_VITE, TS_NEXT, etc)
  221. ###
  222. ### - tsconfigFile - by default tsconfig.json or value from TS_CONFIG macros.
  223. ###
  224. ### Documentation: https://docs.yandex-team.ru/frontend-in-arcadia/references/macros#ts-typecheck
  225. ###
  226. ### @example:
  227. ###
  228. ### TS_VITE()
  229. ### TS_TYPECHECK()
  230. ### END()
  231. macro TS_TYPECHECK(TS_CONFG="") {
  232. ENABLE(_TS_TYPECHECK_VALUE)
  233. SET(_TS_TYPECHECK_TSCONFIG $TS_CONFG)
  234. }
  235. # TS_STYLELINT
  236. _TS_STYLELINT_VALUE=no
  237. _TS_STYLELINT_CONFIG=
  238. _TS_STYLELINT_FILES=
  239. ### @usage: TS_STYLELINT(configFile)
  240. ###
  241. ### For check CSS, SASS, LESS for StyleLint. Must be inside of Module (TS_WEBPACK, TS_VITE, TS_NEXT, etc)
  242. ###
  243. ### - configFile - by default .stylelintrc.
  244. ###
  245. ### Documentation: https://docs.yandex-team.ru/frontend-in-arcadia/references/macros#ts-stylelint
  246. ###
  247. ### @example:
  248. ###
  249. ### TS_VITE()
  250. ### TS_STYLELINT(.stylelintrc)
  251. ### END()
  252. macro TS_STYLELINT(_CONFIG) {
  253. ENABLE(_TS_STYLELINT_VALUE)
  254. SET(_TS_STYLELINT_CONFIG $_CONFIG)
  255. _GLOB(_TS_STYLELINT_FILES **/*(.css|.scss|.less) EXCLUDE $TS_EXCLUDE_DIR_GLOB $TS_COMMON_OUTDIR_GLOB $TS_GLOB_EXCLUDE_ADDITIONAL)
  256. }